
// Make newform 441.6.a.y in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_441_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_441_6_a_y();".
// 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_441_6_a_y();".
// 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 := [-15, 72, -71, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [148, -294, -6, 4], [1692, -3360, -72, 48], [-864, -24, 24, 0]];
    Rf_basisdens := [1, 7, 7, 1];
    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_441_a();"
function MakeCharacter_441_a()
    N := 441;
    order := 1;
    char_gens := [344, 199];
    v := [1, 1];
    // 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;

function MakeCharacter_441_a_Hecke(Kf)
    return MakeCharacter_441_a();
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 := 6;
    raw_aps := [[0, 1, 0, 0], [0, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 0], [0, 43, 0, 0], [0, 0, 0, -1], [0, 0, -11, 0], [0, 0, 0, 1], [0, 341, 0, 0], [0, 518, 0, 0], [0, 0, 0, 11], [-5466, 0, 0, 0], [0, 0, 99, 0], [12540, 0, 0, 0], [0, 0, -100, 0], [0, -1738, 0, 0], [0, 0, 428, 0], [0, 0, 0, 55], [-29996, 0, 0, 0], [0, 7051, 0, 0], [0, 0, 0, 56], [80168, 0, 0, 0], [0, 0, 308, 0], [0, 0, -209, 0], [0, 0, 0, 154], [0, 0, 1067, 0], [0, 0, 0, -55], [0, -11813, 0, 0], [73854, 0, 0, 0], [0, -3388, 0, 0], [175120, 0, 0, 0], [0, 0, -1452, 0], [0, -19756, 0, 0], [0, 0, 0, 22], [0, -1046, 0, 0], [310200, 0, 0, 0], [0, 0, 0, 297], [126556, 0, 0, 0], [0, 0, -3432, 0], [0, 0, -1881, 0], [0, -14663, 0, 0], [0, 0, 0, -253], [0, -13321, 0, 0], [-306306, 0, 0, 0], [0, -41318, 0, 0], [0, 0, 0, -264], [-1210308, 0, 0, 0], [0, 0, 0, -858], [0, 0, 1408, 0], [0, 0, 0, 891], [0, 118780, 0, 0], [0, -128039, 0, 0], [0, 0, 0, 1662], [0, 0, -2168, 0], [0, 0, -12893, 0], [0, -169531, 0, 0], [0, 0, -22891, 0], [0, 0, 0, 1255], [-256234, 0, 0, 0], [0, 101980, 0, 0], [0, 0, 0, 571], [0, 0, -7337, 0], [0, 0, 0, -77], [0, 0, -3036, 0], [0, 0, 0, -1166], [0, 73238, 0, 0], [2639052, 0, 0, 0], [-455070, 0, 0, 0], [0, -149987, 0, 0], [0, 0, 0, -1211], [0, 0, -11771, 0], [0, -342685, 0, 0], [0, 0, 0, 3432], [-1586618, 0, 0, 0], [1271676, 0, 0, 0], [0, 0, 51524, 0], [0, 565114, 0, 0], [0, 0, 0, 253], [0, 365684, 0, 0], [0, 0, 0, 2926], [0, 0, 35828, 0], [991750, 0, 0, 0], [0, -390697, 0, 0], [0, 0, 0, -8910], [0, 0, 0, 7270], [0, -55715, 0, 0], [0, -594616, 0, 0], [6556902, 0, 0, 0], [0, 0, 41723, 0], [5628536, 0, 0, 0], [0, 0, 42208, 0], [0, 0, 71324, 0], [7036152, 0, 0, 0], [0, -124651, 0, 0], [3058956, 0, 0, 0], [0, 0, -62524, 0], [0, 0, -61655, 0], [0, 0, -68023, 0], [0, 0, 0, 2188], [9049502, 0, 0, 0], [1917212, 0, 0, 0], [0, 300970, 0, 0], [0, 0, 107844, 0], [0, 104920, 0, 0], [5246164, 0, 0, 0], [0, 0, 0, -13288], [0, 0, -50304, 0], [0, 0, 48433, 0], [0, 1060499, 0, 0], [0, 0, 0, 4148], [0, 0, 0, -8458], [-15237398, 0, 0, 0], [0, 1304776, 0, 0], [0, 0, 0, -17270], [-4066544, 0, 0, 0], [0, -1123892, 0, 0], [0, 0, 0, 781], [0, 0, -152032, 0], [0, 762806, 0, 0], [0, 1055735, 0, 0], [0, 0, 0, 14311], [-9532974, 0, 0, 0], [0, 0, -64757, 0], [0, 504581, 0, 0], [0, 0, 0, -26532], [0, 1947218, 0, 0], [3613686, 0, 0, 0], [0, 0, 56860, 0], [0, 0, 0, -19899], [0, 0, 0, -3883], [21614780, 0, 0, 0], [0, -1733821, 0, 0], [24562416, 0, 0, 0], [2029158, 0, 0, 0], [0, 0, -59609, 0], [0, 0, 0, -1242], [0, 0, -18525, 0], [0, 0, 0, -15278], [0, 0, -86657, 0], [0, -274856, 0, 0], [0, 0, 0, 7820], [0, -303698, 0, 0], [-24072544, 0, 0, 0], [0, -177805, 0, 0], [0, 0, 0, 30393], [0, 0, -148048, 0], [0, 0, 0, -7051], [0, 0, 389367, 0], [0, 0, 0, 2409], [0, -4690279, 0, 0], [16551458, 0, 0, 0], [0, 0, 148633, 0], [25263228, 0, 0, 0], [0, 0, -324368, 0], [11003412, 0, 0, 0], [0, -4736633, 0, 0], [3782064, 0, 0, 0], [0, 0, 148455, 0], [0, 0, 0, -35376], [0, 0, 257697, 0], [0, -718025, 0, 0], [0, -3046196, 0, 0], [-33314248, 0, 0, 0], [0, 0, 40536, 0], [0, -1262888, 0, 0], [0, 0, 275000, 0], [22997688, 0, 0, 0], [0, 0, 0, -60225], [-242638, 0, 0, 0], [0, 0, 10143, 0], [0, -1751485, 0, 0], [0, 0, 0, -32703], [0, 7307947, 0, 0], [-39655066, 0, 0, 0], [0, 0, 0, -17292], [0, 0, 253781, 0], [-20258788, 0, 0, 0], [0, -7592882, 0, 0], [0, 0, 0, 41887], [0, 0, 0, -14453], [-38605568, 0, 0, 0], [0, 0, 192720, 0], [5046490, 0, 0, 0], [0, 0, 428197, 0], [0, -3090967, 0, 0], [0, 0, 351143, 0], [24255858, 0, 0, 0], [0, 0, 0, -13244], [-45571130, 0, 0, 0], [0, 0, -53020, 0], [0, 0, 0, 2464], [0, -9617717, 0, 0], [-1521972, 0, 0, 0], [0, 0, 783883, 0], [0, 7897471, 0, 0], [0, 0, -790571, 0], [67258290, 0, 0, 0], [50359234, 0, 0, 0], [0, 0, -699897, 0], [0, 0, -835692, 0], [0, -825218, 0, 0], [0, 0, 0, -9802], [0, 0, 0, 100837], [0, 0, 0, 66804], [0, 0, 539088, 0], [0, 0, 135795, 0], [0, 0, 0, 14102], [0, -7265345, 0, 0], [0, -7886360, 0, 0], [0, 0, 0, 101189], [31897118, 0, 0, 0], [0, 0, -277091, 0], [60866136, 0, 0, 0], [0, 0, 364496, 0], [0, 0, 415492, 0], [0, 0, 0, -69982], [101077944, 0, 0, 0], [0, 0, 63745, 0], [0, -10064483, 0, 0], [0, 4270442, 0, 0], [-117345162, 0, 0, 0], [0, 0, 0, -134179], [0, -4522760, 0, 0], [-141893520, 0, 0, 0], [0, 0, 1060532, 0], [-58495338, 0, 0, 0], [0, 0, -973389, 0], [0, 7612913, 0, 0], [0, 0, 0, -61293], [0, 11824517, 0, 0], [63671166, 0, 0, 0], [0, 0, 0, -111429], [93710232, 0, 0, 0], [0, -12946396, 0, 0], [0, 0, 0, -178365], [0, 0, 439032, 0], [0, 0, 0, -93126], [0, 13159510, 0, 0], [0, 16406269, 0, 0], [0, 0, -1090684, 0], [0, 5253017, 0, 0], [0, 0, 0, 44484], [0, 0, 0, -81906], [113888370, 0, 0, 0], [0, 0, 375155, 0], [0, 0, -753192, 0], [0, 0, 0, 153307], [0, 0, 1118776, 0], [-697004, 0, 0, 0], [0, 5705921, 0, 0], [-13138158, 0, 0, 0], [0, 0, -1140799, 0], [0, 856603, 0, 0], [0, 0, 0, 26488], [0, 0, 5863, 0], [0, 221879, 0, 0], [-148420438, 0, 0, 0], [0, 0, 0, 138269], [0, 0, 1894927, 0], [0, 0, 0, 57430], [173286256, 0, 0, 0], [0, 23526593, 0, 0], [0, 0, 0, -21043], [0, 0, 0, -144825], [0, 0, 345993, 0], [0, 0, 0, 90354], [0, 2147750, 0, 0], [0, 0, 1083105, 0], [-74707028, 0, 0, 0], [0, -15654362, 0, 0], [0, 0, 0, 77825], [-53546604, 0, 0, 0], [0, 0, 0, 101816], [-9422160, 0, 0, 0], [0, 0, 0, -151172], [0, 0, 0, -76879], [0, -11565565, 0, 0], [-90325950, 0, 0, 0], [-40071306, 0, 0, 0], [0, 0, 1836296, 0], [0, 0, 2063248, 0], [39140000, 0, 0, 0], [0, 0, -2342736, 0], [0, 0, 0, 66263], [0, 0, 0, 26256], [0, 4341799, 0, 0], [92161134, 0, 0, 0], [0, 6900518, 0, 0], [0, 0, 0, 180103], [0, 0, 918555, 0], [0, -32802506, 0, 0], [0, 0, -1702404, 0], [0, -5269232, 0, 0], [0, 0, 2866820, 0], [-236963650, 0, 0, 0], [0, 0, -2348049, 0], [0, 0, 0, -86812], [0, 0, 2962905, 0], [0, 0, 1568336, 0], [0, 0, 0, 295910], [0, 0, 0, -374078], [0, -7098838, 0, 0], [-124625864, 0, 0, 0], [0, 25580599, 0, 0], [-67254076, 0, 0, 0], [-190412958, 0, 0, 0], [0, 26235781, 0, 0], [0, 0, 0, 272437], [0, 32610347, 0, 0], [140627322, 0, 0, 0], [0, 0, 1633192, 0], [0, 39323570, 0, 0], [0, -12066880, 0, 0], [242241492, 0, 0, 0], [0, 11213941, 0, 0], [0, 0, 0, -247500], [0, 0, 1479544, 0], [0, -32130023, 0, 0], [0, 0, 0, 244068], [0, -3173608, 0, 0], [0, 0, 0, 115587], [155998314, 0, 0, 0], [0, 0, -1612149, 0], [-145090728, 0, 0, 0], [0, 32113696, 0, 0], [0, 0, 0, 178354], [-86400052, 0, 0, 0], [0, 0, 0, -335027], [0, 28826623, 0, 0], [0, 27930310, 0, 0], [-23782110, 0, 0, 0], [0, -22784938, 0, 0], [0, 0, 0, -422885], [0, 0, -1476420, 0], [46895420, 0, 0, 0], [0, 0, 1005236, 0], [168438962, 0, 0, 0], [0, 0, 863379, 0], [0, 0, 0, -21648], [0, 0, 0, 223663], [-217864282, 0, 0, 0], [0, -27919672, 0, 0], [0, 0, -1102695, 0], [15308448, 0, 0, 0], [0, 18119926, 0, 0], [0, 21906655, 0, 0], [0, 0, 0, -240053], [-306500148, 0, 0, 0], [0, 0, 4993384, 0], [0, 0, -4516237, 0], [0, 0, 0, -159995], [-185411302, 0, 0, 0], [0, -25769854, 0, 0], [0, 0, 0, 282578], [262257094, 0, 0, 0], [0, 0, -85635, 0], [0, 0, -4612420, 0], [0, 0, -233024, 0], [0, 924320, 0, 0], [0, -47103397, 0, 0], [402076246, 0, 0, 0], [0, 0, 1642355, 0], [0, 23818663, 0, 0], [0, 66490115, 0, 0], [0, 0, 0, 333872], [526087530, 0, 0, 0], [0, 0, 272437, 0], [111675256, 0, 0, 0], [1764774, 0, 0, 0], [0, -10256015, 0, 0], [0, 0, 0, 399751], [0, -5966929, 0, 0], [0, -24854686, 0, 0], [0, 0, 0, -753797], [-217023586, 0, 0, 0], [0, 0, 112740, 0], [0, -45759407, 0, 0], [0, 0, 0, 105236], [0, 0, -2622719, 0], [0, 0, 0, 257598], [0, 0, -2487497, 0], [0, -29748224, 0, 0], [-198653664, 0, 0, 0], [0, 8461496, 0, 0], [0, 0, 0, 148016], [0, 0, -6149164, 0], [19034808, 0, 0, 0], [0, 0, 0, -275759], [439466060, 0, 0, 0], [0, 0, 399092, 0], [124490750, 0, 0, 0], [0, 0, 1667193, 0], [0, -22317493, 0, 0], [0, 0, 0, -537449], [0, -74861237, 0, 0], [-94106694, 0, 0, 0], [0, 0, 0, 601556], [0, 0, 2700389, 0], [-270885716, 0, 0, 0], [0, 24781514, 0, 0], [0, 0, 0, -588369], [0, 7565536, 0, 0], [261956728, 0, 0, 0], [0, 0, 3719155, 0], [0, 0, 4852441, 0], [0, 0, 0, -291028], [77893870, 0, 0, 0], [0, 32640764, 0, 0], [0, 0, 0, -787446], [0, 0, -4815052, 0], [0, 0, 0, 931524], [0, -10732262, 0, 0], [0, 12832237, 0, 0], [142617420, 0, 0, 0], [-828327610, 0, 0, 0], [0, 0, 2811269, 0], [0, 67142329, 0, 0], [0, 0, 0, 264781], [0, 0, 4037913, 0], [0, 0, -8178676, 0], [0, 71235362, 0, 0], [0, 0, 0, 289147], [0, -46313377, 0, 0], [0, 0, 315172, 0], [0, 0, 0, -233354], [0, 0, -7664733, 0], [0, -96176839, 0, 0], [0, 4914964, 0, 0], [0, 0, 0, 580844], [0, 0, -3367320, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_441_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_441_6_a_y();".
// 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_441_6_a_y(:prec:=4)
    chi := MakeCharacter_441_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_441_6_a_y();".
// 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_441_6_a_y( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_441_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![-76, 0, 1]>,<5,R![-9936, 0, 1]>,<13,R![-755136, 0, 1]>],Snew);
    return Vf;
end function;