
// Make newform 4032.3.d.j in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4032_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_4032_d_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_4032_3_d_j();".
// 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_4032_3_d_j();".
// 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 := [9, 0, 8, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -16, 0, -2], [4, 0, 1, 0], [0, -5, 0, -1]];
    Rf_basisdens := [1, 3, 1, 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_4032_d();"
function MakeCharacter_4032_d()
    N := 4032;
    order := 2;
    char_gens := [127, 3781, 1793, 577];
    v := [2, 2, 1, 2];
    // 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_4032_d_Hecke();"
function MakeCharacter_4032_d_Hecke(Kf)
    N := 4032;
    order := 2;
    char_gens := [127, 3781, 1793, 577];
    char_values := [[1, 0, 0, 0], [1, 0, 0, 0], [-1, 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 := 3;
    raw_aps := [[0, 0, 0, 0], [0, 0, 0, 0], [0, 2, 0, -1], [0, 0, 1, 0], [0, -4, 0, 2], [8, 0, 4, 0], [0, 2, 0, -5], [20, 0, 0, 0], [0, 4, 0, -2], [0, -4, 0, -5], [-4, 0, -8, 0], [-38, 0, 0, 0], [0, -6, 0, -7], [20, 0, 24, 0], [0, 0, 0, 4], [0, -24, 0, 7], [0, -8, 0, -4], [-58, 0, 16, 0], [-48, 0, -32, 0], [0, 4, 0, -2], [-24, 0, -20, 0], [-76, 0, 16, 0], [0, 8, 0, -24], [0, 18, 0, -23], [-72, 0, -44, 0], [0, -10, 0, -13], [-68, 0, -24, 0], [0, -12, 0, 34], [72, 0, -40, 0], [0, -8, 0, 3], [-172, 0, 16, 0], [0, -32, 0, 4], [0, 4, 0, -23], [48, 0, 64, 0], [0, -24, 0, -9], [72, 0, 8, 0], [58, 0, 48, 0], [-40, 0, 48, 0], [0, 8, 0, -24], [0, -34, 0, 3], [0, 12, 0, 38], [-136, 0, -20, 0], [0, 36, 0, 10], [134, 0, 0, 0], [0, 16, 0, 25], [88, 0, -72, 0], [-148, 0, 24, 0], [-32, 0, 72, 0], [0, 0, 0, 24], [216, 0, 20, 0], [0, -52, 0, 57], [0, -36, 0, 22], [248, 0, 36, 0], [0, 0, 0, 84], [0, -42, 0, -9], [0, -36, 0, -18], [0, -70, 0, 63], [20, 0, -8, 0], [-32, 0, 0, 0], [0, 20, 0, 15], [228, 0, -80, 0], [0, -102, 0, 37], [-108, 0, -32, 0], [0, -88, 0, 76], [-126, 0, 64, 0], [0, 48, 0, 1], [44, 0, 120, 0], [-320, 0, 8, 0], [0, 12, 0, 34], [-138, 0, -112, 0], [0, 6, 0, -51], [0, 92, 0, 10], [-200, 0, 120, 0], [318, 0, 32, 0], [420, 0, -8, 0], [0, -128, 0, -20], [0, -4, 0, 131], [-202, 0, 112, 0], [0, 12, 0, -39], [-232, 0, 84, 0], [0, 0, 0, 80], [176, 0, 160, 0], [0, -156, 0, 22], [-130, 0, 192, 0], [128, 0, -248, 0], [0, 68, 0, -74], [0, -152, 0, 91], [48, 0, 112, 0], [0, 2, 0, 85], [-36, 0, -16, 0], [0, 64, 0, -172], [0, 64, 0, 88], [400, 0, -120, 0], [0, 12, 0, -58], [12, 0, 280, 0], [0, 168, 0, -48], [0, 6, 0, -231], [0, 90, 0, 59], [-232, 0, 0, 0], [-208, 0, 16, 0], [592, 0, -112, 0], [0, 32, 0, -57], [0, 128, 0, 84], [0, -108, 0, -7], [232, 0, 272, 0], [-318, 0, 64, 0], [0, 104, 0, -48], [0, 66, 0, -29], [0, 12, 0, 26], [-418, 0, 0, 0], [-352, 0, -104, 0], [110, 0, 64, 0], [0, 44, 0, 31], [-264, 0, -272, 0], [172, 0, 48, 0], [0, 44, 0, -127], [-604, 0, 0, 0], [0, -48, 0, 16], [0, -12, 0, -99], [0, -52, 0, 270], [-198, 0, 272, 0], [-406, 0, -96, 0], [0, -114, 0, -101], [0, 12, 0, -70], [584, 0, -240, 0], [0, -76, 0, 59], [-8, 0, 24, 0], [0, 120, 0, 92], [852, 0, -184, 0], [152, 0, 76, 0], [880, 0, -208, 0], [0, 132, 0, -134], [-88, 0, 88, 0], [-184, 0, 40, 0], [0, 290, 0, -7], [306, 0, 160, 0], [0, 146, 0, -75], [-608, 0, 224, 0], [0, 246, 0, -53], [0, 160, 0, 51], [-48, 0, 208, 0], [0, -128, 0, 161], [516, 0, 32, 0], [0, -12, 0, -294], [696, 0, -28, 0], [0, 16, 0, -300], [-518, 0, 144, 0], [0, 162, 0, -87], [-484, 0, 192, 0], [0, -28, 0, 34], [-66, 0, -352, 0], [0, 258, 0, -93], [-724, 0, -312, 0], [0, -24, 0, 240], [-284, 0, 56, 0], [0, 180, 0, 74], [240, 0, 56, 0], [0, -258, 0, 167], [1262, 0, 0, 0], [0, 86, 0, -263], [0, 220, 0, 6], [0, -16, 0, -19], [-1268, 0, 144, 0], [0, -120, 0, -188], [0, 60, 0, 7], [0, 144, 0, -60], [112, 0, 312, 0], [-842, 0, 144, 0], [344, 0, -576, 0], [0, 54, 0, -69], [0, -308, 0, -50], [-486, 0, 272, 0], [0, 204, 0, -138], [232, 0, 536, 0], [1088, 0, 328, 0], [0, -74, 0, 141], [-368, 0, 512, 0], [0, 4, 0, -13], [-884, 0, 216, 0], [346, 0, 432, 0], [332, 0, 640, 0], [0, 104, 0, 120], [528, 0, 296, 0], [0, -74, 0, -355], [0, -412, 0, 178], [0, 318, 0, -45], [392, 0, -464, 0], [464, 0, 432, 0], [-968, 0, -280, 0], [0, -48, 0, 16], [1080, 0, -68, 0], [0, -84, 0, -266], [564, 0, -584, 0], [0, 346, 0, -211], [0, 468, 0, -46], [0, 290, 0, -21], [-598, 0, -192, 0], [-912, 0, -184, 0], [0, -126, 0, 25], [0, 312, 0, -100], [0, 24, 0, -367], [824, 0, 88, 0], [-1112, 0, -348, 0], [-776, 0, 284, 0], [0, -456, 0, 216], [0, 366, 0, -293], [832, 0, 168, 0], [0, -108, 0, 54], [0, 360, 0, -179], [-1204, 0, 192, 0], [-1198, 0, 384, 0], [0, -214, 0, 63], [1904, 0, 88, 0], [0, 112, 0, -240], [0, -48, 0, 560], [-130, 0, -576, 0], [528, 0, -280, 0], [0, 86, 0, 5], [0, -44, 0, 42], [0, 340, 0, -139], [-2088, 0, 200, 0], [1044, 0, 200, 0], [0, 240, 0, -51], [-600, 0, -568, 0], [0, 24, 0, -304], [-758, 0, 480, 0], [0, -418, 0, 367], [0, 308, 0, -354], [-1516, 0, -344, 0], [0, -276, 0, 374], [-328, 0, -152, 0], [-1908, 0, 112, 0], [576, 0, 200, 0], [0, -216, 0, 253], [-412, 0, -336, 0], [0, 168, 0, 24], [-936, 0, 484, 0], [0, 72, 0, -97], [0, 132, 0, 62], [0, 152, 0, 104], [0, 380, 0, -142], [-424, 0, 672, 0], [-2288, 0, 168, 0], [218, 0, 640, 0], [0, 470, 0, -377], [0, 48, 0, 124], [668, 0, -8, 0], [0, -232, 0, 240], [80, 0, 720, 0], [0, -84, 0, -354], [120, 0, -688, 0], [0, 714, 0, -149], [0, -228, 0, 194], [-1224, 0, 388, 0], [0, -170, 0, -341], [0, 308, 0, 138], [-80, 0, 552, 0], [-260, 0, 368, 0], [0, -262, 0, -283], [1166, 0, -384, 0], [2244, 0, -16, 0], [0, -644, 0, 158], [2712, 0, 68, 0], [810, 0, -688, 0], [0, -258, 0, 541], [-1368, 0, 352, 0], [0, -504, 0, 9], [0, 34, 0, 35], [1176, 0, 400, 0], [0, 180, 0, 323], [-1402, 0, 592, 0], [2204, 0, 168, 0], [1864, 0, -28, 0], [-1304, 0, -72, 0], [408, 0, -764, 0], [1724, 0, 40, 0], [0, -532, 0, 362], [-634, 0, 448, 0], [1386, 0, -320, 0], [0, 120, 0, 224], [0, 456, 0, -52], [2492, 0, -320, 0], [0, 168, 0, -340], [2806, 0, -240, 0], [-2168, 0, 32, 0], [0, 4, 0, 570], [-1280, 0, -64, 0], [0, 448, 0, 95], [892, 0, 24, 0], [0, 210, 0, 225], [0, -120, 0, -15], [0, 720, 0, -172], [0, 156, 0, 255], [0, -152, 0, -324], [850, 0, 288, 0], [0, -390, 0, 245], [-1616, 0, -504, 0], [0, -318, 0, 287], [0, 288, 0, 304], [1000, 0, -64, 0], [-882, 0, -416, 0], [0, 180, 0, 11], [-2580, 0, -208, 0], [0, 396, 0, -514], [-232, 0, -384, 0], [1280, 0, -72, 0], [0, -380, 0, -122], [-2072, 0, 60, 0], [0, -212, 0, 466], [-1754, 0, -672, 0], [0, -192, 0, 268], [0, -388, 0, -267], [0, 244, 0, -441], [2324, 0, -24, 0], [0, -316, 0, 554], [-2392, 0, 180, 0], [0, 912, 0, -284], [0, 140, 0, -782], [584, 0, 1236, 0], [0, -900, 0, 401], [1388, 0, 240, 0], [582, 0, 256, 0], [0, -174, 0, -699], [1704, 0, -568, 0], [0, 208, 0, -491], [1064, 0, 180, 0], [-3064, 0, -384, 0], [732, 0, 544, 0], [0, -308, 0, 62], [0, 868, 0, -371], [472, 0, 288, 0], [0, -428, 0, 237], [-1948, 0, -56, 0], [0, 632, 0, 224], [1800, 0, -752, 0], [0, -128, 0, -56], [-574, 0, 64, 0], [0, 334, 0, -449], [-184, 0, 420, 0], [396, 0, 968, 0], [-158, 0, 576, 0], [0, -732, 0, 127], [0, -366, 0, -449], [1088, 0, -152, 0], [0, -156, 0, 187], [0, 132, 0, 486], [1144, 0, 1092, 0], [812, 0, -696, 0], [0, 744, 0, -112], [0, -30, 0, -955], [1220, 0, -192, 0], [536, 0, -240, 0], [0, -168, 0, 721], [-2968, 0, -248, 0], [-318, 0, -1216, 0], [0, -22, 0, 179], [0, -592, 0, 596], [0, 432, 0, 404], [0, -88, 0, -355], [0, -356, 0, -522], [-2142, 0, 512, 0], [0, -742, 0, -215], [0, 212, 0, 114], [0, 20, 0, -170], [-288, 0, -320, 0], [-838, 0, 192, 0], [0, 30, 0, -727], [620, 0, 160, 0], [1482, 0, -224, 0], [0, -1204, 0, 506], [-252, 0, 112, 0], [0, -300, 0, -678], [0, -40, 0, -161], [-2076, 0, 248, 0], [-432, 0, -112, 0], [0, 792, 0, -428], [0, 436, 0, -782], [1230, 0, -1088, 0], [0, -238, 0, -429], [-4456, 0, 12, 0], [0, 78, 0, -717], [0, 928, 0, -429], [-624, 0, -376, 0], [0, -552, 0, 813], [1104, 0, -464, 0], [0, -160, 0, 960], [2392, 0, -600, 0], [-2280, 0, 692, 0], [3144, 0, -128, 0], [0, -800, 0, 560], [2216, 0, 1032, 0], [0, -1014, 0, 487], [0, 812, 0, -698], [116, 0, -1248, 0], [0, 980, 0, -318], [-2384, 0, 1112, 0], [-72, 0, -760, 0], [0, 86, 0, -435], [3832, 0, -304, 0], [0, -308, 0, 165], [-1802, 0, -912, 0], [0, -1032, 0, 451], [1788, 0, 800, 0], [0, -86, 0, 217], [0, -354, 0, -431], [3496, 0, 744, 0], [480, 0, 704, 0], [0, -840, 0, -155], [-2248, 0, -672, 0], [0, -640, 0, -224], [-798, 0, 256, 0], [0, 220, 0, -205], [0, -700, 0, 350], [3412, 0, 440, 0], [-3544, 0, 408, 0], [0, -266, 0, 321], [0, 532, 0, -534], [1044, 0, -1000, 0], [0, -402, 0, -627], [0, -784, 0, 824], [0, 436, 0, -341], [-134, 0, 48, 0], [0, 364, 0, -402], [0, -744, 0, 20], [-946, 0, 96, 0], [0, -550, 0, 493], [0, -212, 0, 1194], [0, -156, 0, -687], [-2192, 0, 896, 0], [0, 592, 0, -200]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4032_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4032_3_d_j();".
// 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_4032_3_d_j(:prec:=4)
    chi := MakeCharacter_4032_d();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    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_4032_3_d_j();".
// 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_4032_3_d_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4032_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![2916, 0, 116, 0, 1]>,<11,R![46656, 0, 464, 0, 1]>,<19,R![-20, 1]>],Snew);
    return Vf;
end function;