
// Make newform 441.4.e.y in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_441_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_441_e_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_441_4_e_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_4_e_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 := [86044, 16800, -15314, -2912, 1307, 176, -54, -4, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [22372, 3448, -3293, -308, 149, 6, -2, 0], [4518059, -5795360, -497414, 311680, 29565, -11168, -658, 188], [-11478684, 454250, 1137914, -120574, -31843, 4897, 558, -94], [-24320296, -17694113, -68156, 1820038, 111426, -63485, -2932, 1034], [-36898988, -3760032, 6478590, 210780, -388145, 3667, 10069, -685], [2554244, -26106296, -3891986, 3179236, 356991, -155726, -8917, 2744], [-44176664, -8027680, 8909612, 3410879, -369522, -235570, 2506, 5467]];
    Rf_basisdens := [1, 8946, 3072951, 1024317, 3072951, 2048634, 6145902, 6145902];
    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_e();"
function MakeCharacter_441_e()
    N := 441;
    order := 3;
    char_gens := [344, 199];
    v := [3, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_441_e_Hecke();"
function MakeCharacter_441_e_Hecke(Kf)
    N := 441;
    order := 3;
    char_gens := [344, 199];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 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 := [[1, 0, -1, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0], [28, 28, 0, 0, 0, 0, 6, 0], [0, 0, 0, 6, 0, -6, 0, -1], [0, 0, 0, -1, 9, 0, 0, 0], [0, 0, 0, 0, -4, -11, 0, -4], [8, -84, -8, 0, 0, 0, 8, 0], [-58, 0, -14, 0, 0, 0, 0, 0], [0, 0, 0, 38, -4, 0, 0, 0], [6, 56, -6, 0, 0, 0, 6, 0], [0, 0, 0, 31, 0, -31, 0, 3], [170, 0, -70, 0, 0, 0, 0, 0], [0, 0, 0, 0, -32, 26, 0, -32], [-14, -14, 0, 0, 0, 0, -36, 0], [0, 0, 0, 49, -20, 0, 0, 0], [0, 0, 0, 0, -27, 68, 0, -27], [448, 448, 0, 0, 0, 0, -76, 0], [-548, 0, -28, 0, 0, 0, 0, 0], [0, 0, 0, 37, 25, 0, 0, 0], [188, -168, -188, 0, 0, 0, 188, 0], [0, 0, 0, -1, 0, 1, 0, -8], [0, 0, 0, 0, 75, 157, 0, 75], [0, 0, 0, -189, 0, 189, 0, -91], [0, 0, 0, 8, -7, 0, 0, 0], [0, 0, 0, 0, 132, 14, 0, 132], [-20, -952, 20, 0, 0, 0, -20, 0], [-56, -56, 0, 0, 0, 0, -370, 0], [460, 0, 238, 0, 0, 0, 0, 0], [464, 0, -140, 0, 0, 0, 0, 0], [0, 0, 0, 0, -56, -111, 0, -56], [448, 448, 0, 0, 0, 0, 20, 0], [0, 0, 0, 305, 0, -305, 0, 284], [512, 910, -512, 0, 0, 0, 512, 0], [-1428, -1428, 0, 0, 0, 0, 204, 0], [0, 0, 0, 350, -183, 0, 0, 0], [314, 700, -314, 0, 0, 0, 314, 0], [0, 0, 0, 362, 0, -362, 0, 152], [0, 0, 0, 0, 233, -358, 0, 233], [1344, 1344, 0, 0, 0, 0, 412, 0], [0, 0, 0, 498, 0, -498, 0, -83], [204, -1680, -204, 0, 0, 0, 204, 0], [1834, 1834, 0, 0, 0, 0, 554, 0], [-170, 0, -1092, 0, 0, 0, 0, 0], [0, 0, 0, 118, 28, 0, 0, 0], [-964, 0, -84, 0, 0, 0, 0, 0], [0, 0, 0, 152, 0, -152, 0, -156], [0, 0, 0, -129, 340, 0, 0, 0], [0, 0, 0, 0, 315, -50, 0, 315], [-664, 896, 664, 0, 0, 0, -664, 0], [-1668, 0, 1064, 0, 0, 0, 0, 0], [0, 0, 0, 75, 99, 0, 0, 0], [0, 0, 0, -521, 0, 521, 0, 144], [0, 0, 0, 0, -183, -593, 0, -183], [2744, 2744, 0, 0, 0, 0, 412, 0], [0, 0, 0, 334, -543, 0, 0, 0], [0, 0, 0, 0, -380, 456, 0, -380], [2898, 2898, 0, 0, 0, 0, -440, 0], [-5728, 0, 336, 0, 0, 0, 0, 0], [0, 0, 0, -633, -96, 0, 0, 0], [0, 0, 0, 532, 0, -532, 0, 385], [0, 0, 0, -673, 0, 673, 0, 496], [0, 0, 0, -232, -544, 0, 0, 0], [0, 0, 0, 0, 395, -655, 0, 395], [-132, 3290, 132, 0, 0, 0, -132, 0], [258, -3724, -258, 0, 0, 0, 258, 0], [898, 0, 742, 0, 0, 0, 0, 0], [-84, -84, 0, 0, 0, 0, 34, 0], [0, 0, 0, -214, 0, 214, 0, 689], [0, 0, 0, -77, -237, 0, 0, 0], [-1364, -7588, 1364, 0, 0, 0, -1364, 0], [0, 0, 0, -1860, -332, 0, 0, 0], [-512, 6706, 512, 0, 0, 0, -512, 0], [-7586, 0, -490, 0, 0, 0, 0, 0], [0, 0, 0, 0, 880, -1138, 0, 880], [1288, 1288, 0, 0, 0, 0, 1126, 0], [0, 0, 0, 0, -743, -42, 0, -743], [1142, -6328, -1142, 0, 0, 0, 1142, 0], [0, 0, 0, -615, -79, 0, 0, 0], [0, 0, 0, -775, 0, 775, 0, -712], [-1930, 0, -952, 0, 0, 0, 0, 0], [13076, 13076, 0, 0, 0, 0, -456, 0], [0, 0, 0, 515, 0, -515, 0, 543], [0, 0, 0, 0, 284, -572, 0, 284], [-1980, -5712, 1980, 0, 0, 0, -1980, 0], [-2270, 0, -2576, 0, 0, 0, 0, 0], [-2346, -6930, 2346, 0, 0, 0, -2346, 0], [0, 0, 0, 1538, 0, -1538, 0, -289], [4608, 0, -3080, 0, 0, 0, 0, 0], [0, 0, 0, 0, 268, -393, 0, 268], [0, 0, 0, 822, -44, 0, 0, 0], [-2492, -2492, 0, 0, 0, 0, 1744, 0], [-1612, 0, 3108, 0, 0, 0, 0, 0], [-1604, 3360, 1604, 0, 0, 0, -1604, 0], [0, 0, 0, 1380, 0, -1380, 0, -132], [0, 0, 0, 0, -577, 1082, 0, -577], [0, 0, 0, 739, -1361, 0, 0, 0], [0, 0, 0, 0, 1036, -1065, 0, 1036], [5032, 2954, -5032, 0, 0, 0, 5032, 0], [-14642, 0, 2310, 0, 0, 0, 0, 0], [-13594, -13594, 0, 0, 0, 0, 972, 0], [0, 0, 0, -2039, 556, 0, 0, 0], [-174, 18872, 174, 0, 0, 0, -174, 0], [-756, -756, 0, 0, 0, 0, -3646, 0], [0, 0, 0, -941, -1405, 0, 0, 0], [0, 0, 0, -77, 0, 77, 0, -1204], [0, 0, 0, 0, 407, -651, 0, 407], [9688, 9688, 0, 0, 0, 0, -3480, 0], [0, 0, 0, -1555, 0, 1555, 0, -827], [0, 0, 0, 0, 416, -1460, 0, 416], [-8792, -8792, 0, 0, 0, 0, -3758, 0], [20746, 0, -1890, 0, 0, 0, 0, 0], [0, 0, 0, -2475, 1872, 0, 0, 0], [10684, 0, 1876, 0, 0, 0, 0, 0], [-13720, -13720, 0, 0, 0, 0, -1618, 0], [0, 0, 0, 353, 0, -353, 0, 1452], [0, 0, 0, -3430, 1156, 0, 0, 0], [1422, 2072, -1422, 0, 0, 0, 1422, 0], [-11846, 0, -1582, 0, 0, 0, 0, 0], [0, 0, 0, 2788, 361, 0, 0, 0], [9508, 0, 28, 0, 0, 0, 0, 0], [0, 0, 0, 0, 61, -1054, 0, 61], [-4032, -4032, 0, 0, 0, 0, -2276, 0], [0, 0, 0, 0, 2176, 959, 0, 2176], [13690, 0, 3374, 0, 0, 0, 0, 0], [-3130, -5320, 3130, 0, 0, 0, -3130, 0], [0, 0, 0, 0, -1176, -3254, 0, -1176], [0, 0, 0, -2474, 0, 2474, 0, -2544], [0, 0, 0, 0, -1893, 380, 0, -1893], [-6860, -6860, 0, 0, 0, 0, 4558, 0], [-12224, 0, -1764, 0, 0, 0, 0, 0], [2792, 14196, -2792, 0, 0, 0, 2792, 0], [-16182, 0, -3122, 0, 0, 0, 0, 0], [0, 0, 0, 0, -845, 4101, 0, -845], [0, 0, 0, 3585, 0, -3585, 0, 1779], [0, 0, 0, 2992, -1969, 0, 0, 0], [0, 0, 0, 335, 1036, 0, 0, 0], [0, 0, 0, -5046, 0, 5046, 0, 841], [-13454, -13454, 0, 0, 0, 0, 1602, 0], [0, 0, 0, 2525, 0, -2525, 0, -1360], [-664, 32354, 664, 0, 0, 0, -664, 0], [25928, 25928, 0, 0, 0, 0, -720, 0], [20452, 0, 3724, 0, 0, 0, 0, 0], [0, 0, 0, 2868, -1077, 0, 0, 0], [0, 0, 0, -962, 0, 962, 0, -3188], [0, 0, 0, 3922, 0, -3922, 0, -1307], [0, 0, 0, 4065, -991, 0, 0, 0], [0, 0, 0, 0, 2784, -2365, 0, 2784], [5300, 952, -5300, 0, 0, 0, 5300, 0], [-8674, -5432, 8674, 0, 0, 0, -8674, 0], [0, 0, 0, 2695, 0, -2695, 0, -2499], [-16476, 0, 6916, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1912, 5390, 0, 1912], [-20552, -20552, 0, 0, 0, 0, 1044, 0], [11688, 0, -8484, 0, 0, 0, 0, 0], [-1912, -34776, 1912, 0, 0, 0, -1912, 0], [0, 0, 0, 0, -2097, -1143, 0, -2097], [0, 0, 0, -221, 0, 221, 0, -2503], [0, 0, 0, 2492, -699, 0, 0, 0], [-4430, -13636, 4430, 0, 0, 0, -4430, 0], [-27638, 0, 5628, 0, 0, 0, 0, 0], [2676, 0, -1456, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1412, -5737, 0, 1412], [-14224, -14224, 0, 0, 0, 0, -10508, 0], [0, 0, 0, -2050, 140, 0, 0, 0], [1400, 1400, 0, 0, 0, 0, -9960, 0], [0, 0, 0, -6264, 817, 0, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_441_e_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_441_4_e_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_4_e_y(:prec:=8)
    chi := MakeCharacter_441_e();
    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_441_4_e_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_4_e_y( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_441_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![256, 16, 17, -1, 1]>,<5,R![614656, 0, 145824, 0, 33812, 0, 186, 0, 1]>,<13,R![2458624, 0, -3234, 0, 1]>],Snew);
    return Vf;
end function;