
// Make newform 121.4.c.c in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_121_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_121_c_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_121_4_c_c();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_121_4_c_c();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function ConvertToHeckeField(input: pass_field := false, Kf := [])
    if not pass_field then
        poly := [81, 0, 27, 0, 9, 0, 3, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 1]];
    Rf_basisdens := [1, 1, 3, 3, 9, 9, 27, 27];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_121_c();"
function MakeCharacter_121_c()
    N := 121;
    order := 5;
    char_gens := [2];
    v := [4];
    // chi(gens[i]) = zeta^v[i]
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    F := CyclotomicField(order);
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),[F|F.1^e:e in v]);
    return MinimalBaseRingCharacter(chi);
end function;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_121_c_Hecke();"
function MakeCharacter_121_c_Hecke(Kf)
    N := 121;
    order := 5;
    char_gens := [2];
    char_values := [[0, 0, 0, 0, 1, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
end function;


function ExtendMultiplicatively(weight, aps, character)
    prec := NextPrime(NthPrime(#aps)) - 1; // we will able to figure out a_0 ... a_prec
    primes := PrimesUpTo(prec);
    prime_powers := primes;
    assert #primes eq #aps;
    log_prec := Floor(Log(prec)/Log(2)); // prec < 2^(log_prec+1)
    F := Universe(aps);
    FXY<X, Y> := PolynomialRing(F, 2);
    // 1/(1 - a_p T + p^(weight - 1) * char(p) T^2) = 1 + a_p T + a_{p^2} T^2 + ...
    R<T> := PowerSeriesRing(FXY : Precision := log_prec + 1);
    recursion := Coefficients(1/(1 - X*T + Y*T^2));
    coeffs := [F!0: i in [1..(prec+1)]];
    coeffs[1] := 1; //a_1
    for i := 1 to #primes do
        p := primes[i];
        coeffs[p] := aps[i];
        b := p^(weight - 1) * F!character(p);
        r := 2;
        p_power := p * p;
        //deals with powers of p
        while p_power le prec do
            Append(~prime_powers, p_power);
            coeffs[p_power] := Evaluate(recursion[r + 1], [aps[i], b]);
            p_power *:= p;
            r +:= 1;
        end while;    
    end for;
    Sort(~prime_powers);
    for pp in prime_powers do
        for k := 1 to Floor(prec/pp) do
            if GCD(k, pp) eq 1 then
                coeffs[pp*k] := coeffs[pp]*coeffs[k];
            end if;
        end for;
    end for;
    return coeffs;
end function;


function qexpCoeffs()
    // To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
    weight := 4;
    raw_aps := [[0, 0, 1, 0, 0, 0, 0, 1], [0, -4, 0, 0, 0, 0, -1, 0], [-1, 0, -1, 8, -1, 0, -1, 0], [0, 4, 0, 4, 10, 4, 0, 4], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 40, 0, 0, 0, 0, -20], [62, 0, 62, 12, 62, 0, 62, 0], [0, 60, 0, 0, 0, 0, 36, 0], [-49, 0, 0, 0, 0, -36, 0, 0], [0, 56, 0, 56, 72, 56, 0, 56], [0, 0, -17, 0, 0, 0, 0, 28], [0, 8, 0, 8, 27, 8, 0, 8], [0, -4, 0, 0, 0, 0, 268, 0], [-30, 0, 0, 0, 0, -16, 0, 0], [0, -120, 0, 0, 0, 0, -136, 0], [0, 0, -246, 0, 0, 0, 0, -56], [0, 132, 0, 132, 317, 132, 0, 132], [-420, 0, -420, 184, -420, 0, -420, 0], [377, 0, 0, 0, 0, -20, 0, 0], [339, 0, 339, 76, 339, 0, 339, 0], [0, 468, 0, 468, -200, 468, 0, 468], [0, 0, 158, 0, 0, 0, 0, 656], [-234, 0, -234, 120, -234, 0, -234, 0], [-921, 0, 0, 0, 0, -328, 0, 0], [0, 0, 1097, 0, 0, 0, 0, 144], [0, 0, 566, 0, 0, 0, 0, -420], [0, -488, 0, -488, -880, -488, 0, -488], [0, 380, 0, 0, 0, 0, 174, 0], [490, 0, 0, 0, 0, 320, 0, 0], [0, 664, 0, 0, 0, 0, -855, 0], [604, 0, 604, -412, 604, 0, 604, 0], [-222, 0, 0, 0, 0, -796, 0, 0], [-905, 0, -905, 408, -905, 0, -905, 0], [0, -828, 0, -828, -1466, -828, 0, -828], [-530, 0, -530, -1708, -530, 0, -530, 0], [0, -408, 0, 0, 0, 0, -1870, 0], [0, 616, 0, 0, 0, 0, 1409, 0], [0, 0, -2060, 0, 0, 0, 0, -384], [0, 0, 1608, 0, 0, 0, 0, 652], [0, 144, 0, 0, 0, 0, 2058, 0], [0, 900, 0, 0, 0, 0, -2871, 0], [-1303, 0, -1303, -1216, -1303, 0, -1303, 0], [0, 348, 0, 348, 2321, 348, 0, 348], [572, 0, 572, 1104, 572, 0, 572, 0], [-4322, 0, 0, 0, 0, 464, 0, 0], [408, 0, 0, 0, 0, 240, 0, 0], [0, 0, 1500, 0, 0, 0, 0, -928], [0, -1132, 0, 0, 0, 0, -1973, 0], [0, 1844, 0, 1844, 1422, 1844, 0, 1844], [0, 0, 3495, 0, 0, 0, 0, -912], [0, 0, 2304, 0, 0, 0, 0, 1208], [0, -2424, 0, 0, 0, 0, 114, 0], [1456, 0, 0, 0, 0, 1416, 0, 0], [0, 0, 409, 0, 0, 0, 0, 396], [0, -1160, 0, -1160, -1226, -1160, 0, -1160], [3194, 0, 0, 0, 0, 1724, 0, 0], [-3010, 0, -3010, -1168, -3010, 0, -3010, 0], [0, -892, 0, -892, 3032, -892, 0, -892], [0, 0, 166, 0, 0, 0, 0, 232], [-198, 0, -198, 2952, -198, 0, -198, 0], [0, 136, 0, 0, 0, 0, -4964, 0], [0, -3236, 0, -3236, -3276, -3236, 0, -3236], [-1588, 0, 0, 0, 0, -52, 0, 0], [0, 3192, 0, 0, 0, 0, -1956, 0], [-3263, 0, -3263, 2264, -3263, 0, -3263, 0], [0, 0, 109, 0, 0, 0, 0, -72], [3607, 0, 0, 0, 0, -2844, 0, 0], [0, 3444, 0, 3444, 5726, 3444, 0, 3444], [632, 0, 632, -3020, 632, 0, 632, 0], [0, -932, 0, 0, 0, 0, 5106, 0], [-2589, 0, 0, 0, 0, -4808, 0, 0], [0, 2132, 0, 2132, -7808, 2132, 0, 2132], [0, 836, 0, 836, 8215, 836, 0, 836], [-2726, 0, 0, 0, 0, -1492, 0, 0], [1829, 0, 1829, 572, 1829, 0, 1829, 0], [0, 0, -4585, 0, 0, 0, 0, 1012], [0, -3440, 0, -3440, -2847, -3440, 0, -3440], [9262, 0, 0, 0, 0, 2856, 0, 0], [2950, 0, 2950, -1912, 2950, 0, 2950, 0], [0, 0, 2514, 0, 0, 0, 0, -3872], [-12100, 0, 0, 0, 0, 1624, 0, 0], [0, 7688, 0, 0, 0, 0, -170, 0], [0, 0, 2658, 0, 0, 0, 0, 1300], [0, 2880, 0, 2880, -6755, 2880, 0, 2880], [-2000, 0, 0, 0, 0, -5672, 0, 0], [0, -452, 0, 0, 0, 0, 10885, 0], [0, 0, 8315, 0, 0, 0, 0, -5000], [13380, 0, 13380, 1624, 13380, 0, 13380, 0], [6660, 0, 0, 0, 0, -1112, 0, 0], [-2243, 0, 0, 0, 0, 3276, 0, 0], [5019, 0, 5019, 5852, 5019, 0, 5019, 0], [-10784, 0, -10784, 452, -10784, 0, -10784, 0], [0, -7324, 0, 0, 0, 0, -5641, 0], [0, -1648, 0, -1648, -10472, -1648, 0, -1648], [0, -9520, 0, -9520, -3580, -9520, 0, -9520], [0, 688, 0, 0, 0, 0, 8974, 0], [0, 2288, 0, 0, 0, 0, 2487, 0], [0, 7776, 0, 7776, -5859, 7776, 0, 7776], [-9356, 0, -9356, -1788, -9356, 0, -9356, 0], [0, 0, -2348, 0, 0, 0, 0, -6732], [0, 1752, 0, 0, 0, 0, -7984, 0], [0, -2372, 0, -2372, -7910, -2372, 0, -2372], [0, 0, -9332, 0, 0, 0, 0, -328], [0, 4504, 0, 0, 0, 0, -2472, 0], [-7180, 0, 0, 0, 0, -5648, 0, 0], [17607, 0, 17607, 1224, 17607, 0, 17607, 0], [0, -6120, 0, -6120, 484, -6120, 0, -6120], [3740, 0, 0, 0, 0, 352, 0, 0], [-11632, 0, -11632, 896, -11632, 0, -11632, 0], [0, 6796, 0, 6796, -6994, 6796, 0, 6796], [0, 0, 9650, 0, 0, 0, 0, 7056], [0, -4688, 0, 0, 0, 0, 4592, 0], [-3246, 0, 0, 0, 0, -11248, 0, 0], [0, -9844, 0, 0, 0, 0, -4393, 0], [0, -7356, 0, -7356, 8791, -7356, 0, -7356], [0, 7952, 0, 0, 0, 0, 6375, 0], [-8189, 0, -8189, 11940, -8189, 0, -8189, 0], [0, 0, -6031, 0, 0, 0, 0, 2564], [0, -3952, 0, -3952, 13183, -3952, 0, -3952], [2338, 0, 0, 0, 0, -7424, 0, 0], [2797, 0, 0, 0, 0, 288, 0, 0], [0, 0, 11006, 0, 0, 0, 0, -7040], [-5538, 0, -5538, 4436, -5538, 0, -5538, 0], [-21688, 0, 0, 0, 0, 4536, 0, 0], [0, 0, 8993, 0, 0, 0, 0, -10860], [0, 14332, 0, 0, 0, 0, 5126, 0], [-15215, 0, -15215, -2256, -15215, 0, -15215, 0], [0, 9948, 0, 9948, -15393, 9948, 0, 9948], [-4029, 0, 0, 0, 0, 2036, 0, 0], [0, 968, 0, 968, 10308, 968, 0, 968], [0, 0, -22750, 0, 0, 0, 0, 2536], [9020, 0, 9020, 11664, 9020, 0, 9020, 0], [0, 7388, 0, 0, 0, 0, 3937, 0], [0, 0, 5666, 0, 0, 0, 0, -17360], [0, 0, 21432, 0, 0, 0, 0, -7484], [10616, 0, 0, 0, 0, 12828, 0, 0], [0, -6608, 0, 0, 0, 0, -24126, 0], [-5656, 0, -5656, 5816, -5656, 0, -5656, 0], [9571, 0, 9571, 10080, 9571, 0, 9571, 0], [-14772, 0, -14772, -5124, -14772, 0, -14772, 0], [0, -5568, 0, 0, 0, 0, 23842, 0], [0, 6480, 0, 6480, -8618, 6480, 0, 6480], [0, 0, 1887, 0, 0, 0, 0, -17372], [0, 0, -1864, 0, 0, 0, 0, 20724], [0, -1752, 0, -1752, 1897, -1752, 0, -1752], [0, -236, 0, 0, 0, 0, -37781, 0], [-10238, 0, -10238, 18896, -10238, 0, -10238, 0], [13064, 0, 0, 0, 0, -17520, 0, 0], [19425, 0, 0, 0, 0, -5836, 0, 0], [-2352, 0, -2352, -6928, -2352, 0, -2352, 0], [0, 18180, 0, 0, 0, 0, -11760, 0], [11645, 0, 0, 0, 0, 4520, 0, 0], [0, 88, 0, 0, 0, 0, 48940, 0], [0, 9296, 0, 9296, 25394, 9296, 0, 9296], [-29652, 0, -29652, 4640, -29652, 0, -29652, 0], [0, 0, 18348, 0, 0, 0, 0, 8488], [-4066, 0, -4066, -15712, -4066, 0, -4066, 0], [8310, 0, 8310, -8584, 8310, 0, 8310, 0], [0, 0, -29524, 0, 0, 0, 0, -2916], [-28626, 0, -28626, 7624, -28626, 0, -28626, 0], [-2955, 0, 0, 0, 0, 17428, 0, 0], [0, -17804, 0, -17804, 10102, -17804, 0, -17804], [-27176, 0, 0, 0, 0, -10968, 0, 0], [0, 4452, 0, 0, 0, 0, -12865, 0], [0, 0, 12117, 0, 0, 0, 0, -1400], [0, -17956, 0, -17956, 1815, -17956, 0, -17956], [-4304, 0, 0, 0, 0, 19504, 0, 0], [0, 1484, 0, 1484, -29374, 1484, 0, 1484]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_121_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_121_4_c_c();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
function MakeNewformModFrm_121_4_c_c(:prec:=8)
    chi := MakeCharacter_121_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 1;
    while true do
        trunc_vec := Vector(Kf, [0] cat [f_vec[i]: i in [1..prec]]);
        B := Basis(S, prec + 1);
        S_basismat := Matrix([AbsEltseq(g): g in B]);
        if Rank(S_basismat) eq Min(NumberOfRows(S_basismat), NumberOfColumns(S_basismat)) then
            S_basismat := ChangeRing(S_basismat,Kf);
            f_lincom := Solution(S_basismat,trunc_vec);
            f := &+[f_lincom[i]*Basis(S)[i] : i in [1..#Basis(S)]];
            return f;
        end if;
        error if prec eq maxprec, "Unable to distinguish newform within newspace";
        prec := Min(Ceiling(1.25 * prec), maxprec);
    end while;
end function;


// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_121_4_c_c();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function MakeNewformModSym_121_4_c_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_121_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![16, -16, 24, -32, 44, 16, 6, 2, 1]>],Snew);
    return Vf;
end function;