
// Make newform 256.5.c.j in Magma, downloaded from the LMFDB on 14 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_256_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_256_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_256_5_c_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_256_5_c_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 := [1, 0, -1, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 8, 0, -4], [-2, 0, 4, 0], [0, 0, 0, 8]];
    Rf_basisdens := [1, 1, 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_256_c();"
function MakeCharacter_256_c()
    N := 256;
    order := 2;
    char_gens := [255, 5];
    v := [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_256_c_Hecke();"
function MakeCharacter_256_c_Hecke(Kf)
    N := 256;
    order := 2;
    char_gens := [255, 5];
    char_values := [[-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]];
    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 := 5;
    raw_aps := [[0, 0, 0, 0], [0, 0, 1, 0], [0, 3, 0, 0], [0, 0, 0, -5], [0, 0, -57, 0], [0, -37, 0, 0], [-198, 0, 0, 0], [0, 0, 73, 0], [0, 0, 0, -63], [0, 63, 0, 0], [0, 0, 0, -212], [0, -253, 0, 0], [-18, 0, 0, 0], [0, 0, 447, 0], [0, 0, 0, -306], [0, 471, 0, 0], [0, 0, -1521, 0], [0, -145, 0, 0], [0, 0, 521, 0], [0, 0, 0, -981], [4310, 0, 0, 0], [0, 0, 0, -518], [0, 0, 2625, 0], [-3114, 0, 0, 0], [4730, 0, 0, 0], [0, 3, 0, 0], [0, 0, 0, 1127], [0, 0, -681, 0], [0, 2091, 0, 0], [-2142, 0, 0, 0], [0, 0, 0, 632], [0, 0, 2649, 0], [32526, 0, 0, 0], [0, 0, 319, 0], [0, 4983, 0, 0], [0, 0, 0, 1777], [0, 39, 0, 0], [0, 0, 8273, 0], [0, 0, 0, 2727], [0, -4605, 0, 0], [0, 0, 3057, 0], [0, -5329, 0, 0], [0, 0, 0, 864], [-29446, 0, 0, 0], [0, -5853, 0, 0], [0, 0, 0, 179], [0, 0, -21935, 0], [0, 0, 0, -2476], [0, 0, -8127, 0], [0, -6549, 0, 0], [105750, 0, 0, 0], [0, 0, 0, -2898], [13306, 0, 0, 0], [0, 0, 18351, 0], [-2142, 0, 0, 0], [0, 0, 0, -7389], [0, -1197, 0, 0], [0, 0, 0, -12214], [0, 11919, 0, 0], [-116586, 0, 0, 0], [0, 0, -41001, 0], [0, 6075, 0, 0], [0, 0, -11511, 0], [0, 0, 0, 17973], [-15826, 0, 0, 0], [0, 16311, 0, 0], [0, 0, 10039, 0], [158114, 0, 0, 0], [0, 0, 35391, 0], [0, -257, 0, 0], [41346, 0, 0, 0], [0, 0, 0, 18855], [0, 0, 0, 9958], [0, 19511, 0, 0], [0, 0, 4831, 0], [0, 0, 0, 19728], [0, 7323, 0, 0], [0, 11811, 0, 0], [33210, 0, 0, 0], [123950, 0, 0, 0], [0, 0, -7191, 0], [0, -2741, 0, 0], [0, 0, 0, 38070], [-237062, 0, 0, 0], [0, 0, 0, 1061], [0, 0, -65817, 0], [49338, 0, 0, 0], [-206866, 0, 0, 0], [0, 28131, 0, 0], [0, 0, 0, -17206], [0, 0, -78087, 0], [0, 0, 0, 22932], [0, 0, 0, 13519], [0, 0, 49263, 0], [0, 0, -42399, 0], [0, 0, 0, 23013], [0, 63663, 0, 0], [-332658, 0, 0, 0], [0, 0, 101047, 0], [0, -22825, 0, 0], [0, 0, 11081, 0], [0, -77997, 0, 0], [0, 0, 112809, 0], [461646, 0, 0, 0], [0, 0, 62087, 0], [-282590, 0, 0, 0], [0, 0, -102489, 0], [119682, 0, 0, 0], [0, 0, 0, -63135], [576406, 0, 0, 0], [0, 0, 0, -58084], [0, 42235, 0, 0], [294678, 0, 0, 0], [0, 0, -100249, 0], [0, 0, 0, -54251], [-68742, 0, 0, 0], [0, 0, -176247, 0], [0, 0, 0, 14355], [0, -42477, 0, 0], [0, 0, -96159, 0], [0, -42809, 0, 0], [379066, 0, 0, 0], [0, -29565, 0, 0], [0, 0, -3825, 0], [0, 0, -140271, 0], [0, 17295, 0, 0], [0, 81547, 0, 0], [0, 0, 0, -56646], [0, 0, 0, 75601], [0, 151887, 0, 0], [0, 0, 145185, 0], [0, 0, 0, 62415], [0, 0, 0, -25922], [0, -25265, 0, 0], [-93906, 0, 0, 0], [162362, 0, 0, 0], [0, -72837, 0, 0], [0, 0, 11089, 0], [0, -38841, 0, 0], [813294, 0, 0, 0], [0, 0, -345369, 0], [0, 98343, 0, 0], [0, 0, 0, 86101], [0, 0, -149769, 0], [0, -144545, 0, 0], [0, 0, 0, 65043], [0, 39167, 0, 0], [-324018, 0, 0, 0], [0, 0, 184415, 0], [0, 0, 0, -49932], [0, 5083, 0, 0], [-876510, 0, 0, 0], [0, 0, -352135, 0], [0, 0, 0, 106749], [0, 0, -232241, 0], [0, 0, 0, -77238], [0, 0, 0, -116255], [1635066, 0, 0, 0], [1169558, 0, 0, 0], [0, 9915, 0, 0], [0, 0, -56343, 0], [-1613106, 0, 0, 0], [0, 0, 0, 144227], [0, 0, 388239, 0], [803322, 0, 0, 0], [0, 0, 0, -73791], [0, 0, 0, 22780], [0, 274419, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_256_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_256_5_c_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_256_5_c_j(:prec:=4)
    chi := MakeCharacter_256_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 5));
    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_256_5_c_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_256_5_c_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_256_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,5,sign)));
    Vf := Kernel([<3,R![12, 0, 1]>,<5,R![-432, 0, 1]>],Snew);
    return Vf;
end function;