
// Make newform 441.4.e.x in Magma, downloaded from the LMFDB on 25 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_x();".
// 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_x();".
// 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 := [1764, 0, 798, 0, 319, 0, 19, 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], [1764, 0, 6061, 0, 319, 0, 19, 0], [0, 1764, 0, 6061, 0, 319, 0, 19], [-2392, 0, 0, 0, 0, 0, 1, 0], [0, -3987, 0, 0, 0, 0, 0, 1], [-59052, 0, -23606, 0, -1595, 0, -74, 0], [0, -64638, 0, -25839, 0, -1595, 0, -81]];
    Rf_basisdens := [1, 1, 13398, 13398, 319, 319, 6699, 4466];
    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, 0, 1, 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 := [[0, 1, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, -1, 0, -1, 0, 0, 0, -1], [0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, -3, 0, 0], [-25, 0, 0, 0, 1, 0, 0, 0], [0, 26, 0, 0, 0, -2, 0, 0], [0, 0, -61, 0, 11, 0, -11, 0], [0, 46, 0, 46, 0, 0, 0, 2], [0, 0, 0, 45, 0, -1, 0, 1], [45, 0, 45, 0, 0, 0, -20, 0], [0, 0, -81, 0, -25, 0, 25, 0], [0, 0, 0, 72, 0, -16, 0, 16], [-223, 0, 0, 0, -27, 0, 0, 0], [0, 44, 0, 44, 0, 0, 0, 16], [0, 1, 0, 0, 0, -7, 0, 0], [0, -73, 0, 0, 0, -17, 0, 0], [0, 0, -310, 0, -46, 0, 46, 0], [-463, 0, -463, 0, 0, 0, 19, 0], [0, 0, 0, 0, 0, 36, 0, -36], [441, 0, 441, 0, 0, 0, 7, 0], [0, 0, 23, 0, -42, 0, 42, 0], [0, 0, 0, -189, 0, 21, 0, -21], [0, 314, 0, 314, 0, 0, 0, -22], [-798, 0, 0, 0, -91, 0, 0, 0], [0, -478, 0, 0, 0, 26, 0, 0], [0, 0, -509, 0, -3, 0, 3, 0], [0, -71, 0, -71, 0, 0, 0, 1], [255, 0, 255, 0, 0, 0, 5, 0], [0, 0, 0, 288, 0, -124, 0, 124], [105, 0, 0, 0, -206, 0, 0, 0], [0, 269, 0, 269, 0, 0, 0, 17], [0, -98, 0, 0, 0, 86, 0, 0], [291, 0, 0, 0, 125, 0, 0, 0], [0, 46, 0, 46, 0, 0, 0, -154], [1180, 0, 1180, 0, 0, 0, -207, 0], [214, 0, 214, 0, 0, 0, -358, 0], [0, 0, 1912, 0, -170, 0, 170, 0], [0, 0, 0, 738, 0, 130, 0, -130], [0, 26, 0, 26, 0, 0, 0, -114], [0, 604, 0, 0, 0, -104, 0, 0], [647, 0, 0, 0, -461, 0, 0, 0], [0, 748, 0, 748, 0, 0, 0, 16], [2665, 0, 2665, 0, 0, 0, 162, 0], [0, 0, 0, 126, 0, -58, 0, 58], [3372, 0, 3372, 0, 0, 0, 4, 0], [784, 0, 0, 0, -88, 0, 0, 0], [740, 0, 0, 0, 235, 0, 0, 0], [0, 557, 0, 0, 0, 193, 0, 0], [0, 0, 487, 0, 477, 0, -477, 0], [0, 406, 0, 406, 0, 0, 0, -118], [0, 0, 0, 162, 0, 78, 0, -78], [830, 0, 830, 0, 0, 0, 615, 0], [0, 0, 0, -1557, 0, -11, 0, 11], [0, -1198, 0, -1198, 0, 0, 0, 174], [0, -296, 0, 0, 0, 240, 0, 0], [0, -865, 0, 0, 0, -221, 0, 0], [0, 0, -4924, 0, -265, 0, 265, 0], [-2641, 0, -2641, 0, 0, 0, 91, 0], [0, 0, 0, -18, 0, -314, 0, 314], [4861, 0, 4861, 0, 0, 0, -391, 0], [0, 0, 0, 747, 0, -103, 0, 103], [-4375, 0, 0, 0, -245, 0, 0, 0], [0, -748, 0, 0, 0, 316, 0, 0], [0, 0, 5221, 0, -702, 0, 702, 0], [0, -1961, 0, -1961, 0, 0, 0, -109], [0, 0, 299, 0, 861, 0, -861, 0], [-4835, 0, 0, 0, -568, 0, 0, 0], [0, -836, 0, 0, 0, -416, 0, 0], [-5782, 0, 0, 0, 616, 0, 0, 0], [0, -352, 0, 0, 0, -324, 0, 0], [0, 154, 0, 154, 0, 0, 0, 42], [-1017, 0, -1017, 0, 0, 0, 340, 0], [0, 0, 1211, 0, -375, 0, 375, 0], [5343, 0, 0, 0, 307, 0, 0, 0], [0, -2314, 0, -2314, 0, 0, 0, 346], [0, 1522, 0, 0, 0, 494, 0, 0], [0, 0, -4779, 0, 403, 0, -403, 0], [0, 640, 0, 640, 0, 0, 0, 44], [5033, 0, 5033, 0, 0, 0, 966, 0], [0, 0, 0, 2916, 0, 444, 0, -444], [-11131, 0, 0, 0, 405, 0, 0, 0], [0, 1432, 0, 0, 0, 572, 0, 0], [-1291, 0, 0, 0, 1903, 0, 0, 0], [0, 0, -1308, 0, 415, 0, -415, 0], [0, -125, 0, -125, 0, 0, 0, -685], [0, 0, 0, -486, 0, 18, 0, -18], [0, 0, -1319, 0, 82, 0, -82, 0], [0, 0, 0, 342, 0, 386, 0, -386], [4339, 0, 0, 0, 1847, 0, 0, 0], [0, -3484, 0, -3484, 0, 0, 0, -824], [0, 2384, 0, 0, 0, -220, 0, 0], [4301, 0, 4301, 0, 0, 0, 40, 0], [0, 0, 0, 4221, 0, 223, 0, -223], [0, 0, 5425, 0, -1235, 0, 1235, 0], [0, 0, 0, -378, 0, 714, 0, -714], [0, -2899, 0, -2899, 0, 0, 0, -603], [0, -1864, 0, 0, 0, 544, 0, 0], [0, 0, -7447, 0, -1531, 0, 1531, 0], [0, 0, 341, 0, -1989, 0, 1989, 0], [9160, 0, 0, 0, 458, 0, 0, 0], [0, -1493, 0, 0, 0, -393, 0, 0], [0, -1441, 0, 0, 0, -1329, 0, 0], [0, -4598, 0, -4598, 0, 0, 0, 538], [7723, 0, 7723, 0, 0, 0, -477, 0], [-14117, 0, -14117, 0, 0, 0, 1340, 0], [0, 0, 0, -1719, 0, -437, 0, 437], [0, 350, 0, 350, 0, 0, 0, 238], [0, 3610, 0, 0, 0, 866, 0, 0], [15633, 0, 0, 0, -256, 0, 0, 0], [0, 0, -8747, 0, 720, 0, -720, 0], [12914, 0, 12914, 0, 0, 0, 2308, 0], [0, 0, 0, -5076, 0, -252, 0, 252], [-293, 0, -293, 0, 0, 0, 215, 0], [19796, 0, 0, 0, -87, 0, 0, 0], [0, -5660, 0, 0, 0, 512, 0, 0], [8227, 0, 0, 0, -1383, 0, 0, 0], [0, -1900, 0, 0, 0, -556, 0, 0], [0, 2989, 0, 2989, 0, 0, 0, 137], [0, 0, 0, -3564, 0, -456, 0, 456], [-13121, 0, -13121, 0, 0, 0, -1849, 0], [-8285, 0, 0, 0, 1922, 0, 0, 0], [0, 1043, 0, 1043, 0, 0, 0, 1351], [0, -3401, 0, 0, 0, -1129, 0, 0], [0, 0, 325, 0, 2547, 0, -2547, 0], [0, 0, 0, 6453, 0, 915, 0, -915], [0, 0, 13266, 0, 2036, 0, -2036, 0], [0, -2890, 0, -2890, 0, 0, 0, 862], [8821, 0, 0, 0, -618, 0, 0, 0], [0, 0, 14823, 0, -2603, 0, 2603, 0], [21423, 0, 21423, 0, 0, 0, -2047, 0], [0, 0, 0, 7506, 0, -1122, 0, 1122], [0, 0, -25859, 0, -110, 0, 110, 0], [5570, 0, 0, 0, 2310, 0, 0, 0], [0, 9566, 0, 9566, 0, 0, 0, -1046], [-9455, 0, 0, 0, 3174, 0, 0, 0], [0, 2690, 0, 0, 0, -1342, 0, 0], [-18392, 0, -18392, 0, 0, 0, 944, 0], [0, 0, 0, 657, 0, 967, 0, -967], [0, -1268, 0, 0, 0, -928, 0, 0], [6808, 0, 0, 0, 1770, 0, 0, 0], [0, 5995, 0, 5995, 0, 0, 0, 219], [-25188, 0, -25188, 0, 0, 0, -2884, 0], [0, 0, 0, 1269, 0, 411, 0, -411], [-5095, 0, -5095, 0, 0, 0, -4041, 0], [0, 0, 0, 1278, 0, -1670, 0, 1670], [-11243, 0, 0, 0, -4905, 0, 0, 0], [0, 3860, 0, 0, 0, -1068, 0, 0], [0, 0, -29384, 0, 648, 0, -648, 0], [0, -5210, 0, -5210, 0, 0, 0, -778], [0, 0, -15962, 0, -1646, 0, 1646, 0], [0, 0, 0, 7074, 0, -942, 0, 942], [11483, 0, 0, 0, 879, 0, 0, 0], [0, -1846, 0, -1846, 0, 0, 0, 1962], [-6911, 0, -6911, 0, 0, 0, 4635, 0], [0, 0, 0, -432, 0, -1980, 0, 1980], [0, 0, -12949, 0, -1191, 0, 1191, 0], [0, -2512, 0, -2512, 0, 0, 0, -804], [18789, 0, 0, 0, 488, 0, 0, 0], [0, -2755, 0, 0, 0, -571, 0, 0], [0, -1052, 0, -1052, 0, 0, 0, 396], [0, 0, 0, -4284, 0, -80, 0, 80], [38599, 0, 0, 0, -1846, 0, 0, 0], [0, 4859, 0, 4859, 0, 0, 0, -1469], [0, 12628, 0, 0, 0, 116, 0, 0], [0, -7624, 0, 0, 0, 1084, 0, 0], [16651, 0, 16651, 0, 0, 0, 288, 0], [-42689, 0, -42689, 0, 0, 0, -43, 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_x();".
// 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_x(: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_x();".
// 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_x( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_441_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![1764, 0, 798, 0, 319, 0, 19, 0, 1]>,<5,R![1084253184, 0, 14257824, 0, 154561, 0, 433, 0, 1]>,<13,R![602, 51, 1]>],Snew);
    return Vf;
end function;