
// Make newform 25.9.c.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_25_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_25_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_25_9_c_a();".
// 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_25_9_c_a();".
// 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 := [1225, 0, 71, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 36, 0, 1], [2485, 106, 70, 1], [-2485, 106, -70, 1]];
    Rf_basisdens := [1, 35, 35, 35];
    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_25_c();"
function MakeCharacter_25_c()
    N := 25;
    order := 4;
    char_gens := [2];
    v := [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_25_c_Hecke();"
function MakeCharacter_25_c_Hecke(Kf)
    N := 25;
    order := 4;
    char_gens := [2];
    char_values := [[0, -1, 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 := 9;
    raw_aps := [[0, 0, 0, -1], [0, 0, 1, 0], [0, 0, 0, 0], [0, 0, 0, -231], [12132, 0, 0, 0], [0, 0, -204, 0], [0, 0, 0, 6484], [0, -168380, 0, 0], [0, 0, 18641, 0], [0, 666630, 0, 0], [-1042808, 0, 0, 0], [0, 0, 0, 174864], [-1321128, 0, 0, 0], [0, 0, 234231, 0], [0, 0, 0, -305721], [0, 0, -264524, 0], [0, -6498540, 0, 0], [-14393968, 0, 0, 0], [0, 0, 0, 964809], [-23065488, 0, 0, 0], [0, 0, 1468116, 0], [0, 2760680, 0, 0], [0, 0, -970489, 0], [0, -26130510, 0, 0], [0, 0, 0, 6815604], [180719802, 0, 0, 0], [0, 0, 6177951, 0], [0, 0, 0, -4266081], [0, -36562240, 0, 0], [0, 0, 10925496, 0], [0, 0, 0, -4286751], [384564492, 0, 0, 0], [0, 0, 0, 13696264], [0, 91666540, 0, 0], [0, -145299600, 0, 0], [-23591048, 0, 0, 0], [0, 0, 0, -56213256], [0, 0, -21716529, 0], [0, 0, 0, 41472209], [0, 0, -29632184, 0], [0, 1162047780, 0, 0], [-484016858, 0, 0, 0], [-1493540928, 0, 0, 0], [0, 0, 73932156, 0], [0, 0, 0, -17728996], [0, 1443807200, 0, 0], [-1571757268, 0, 0, 0], [0, 0, -38086959, 0], [0, 0, 0, -119379601], [0, -5090833670, 0, 0], [0, 0, -272649564, 0], [0, -645678360, 0, 0], [1040632472, 0, 0, 0], [-4150916748, 0, 0, 0], [0, 0, 0, -481285856], [0, 0, 134221671, 0], [0, -2628488880, 0, 0], [-2043958888, 0, 0, 0], [0, 0, 0, 363220224], [5507889192, 0, 0, 0], [0, 0, -642871839, 0], [0, 0, 378834856, 0], [0, 0, 0, 129630969], [-522580968, 0, 0, 0], [0, 0, -275509104, 0], [0, 0, 0, -273420316], [8559093092, 0, 0, 0], [0, 0, 0, 606020064], [0, 0, 0, 232470729], [0, 7996269850, 0, 0], [0, 0, -1682027424, 0], [0, 19207634760, 0, 0], [0, 0, 0, -1563464241], [0, 0, -636305784, 0], [0, -19596633020, 0, 0], [0, 0, 905145361, 0], [0, -35803506960, 0, 0], [0, 0, 0, -324770196], [33978402702, 0, 0, 0], [0, 11082575560, 0, 0], [0, -35416747980, 0, 0], [-29873104688, 0, 0, 0], [60683368392, 0, 0, 0], [0, 0, 3620884836, 0], [0, -8862939160, 0, 0], [0, 0, -1418645969, 0], [0, 59505460200, 0, 0], [0, 0, 0, 245176944], [4799330982, 0, 0, 0], [0, 0, 3565750071, 0], [0, 0, 0, -2154184591], [0, -46604383920, 0, 0], [0, 0, 0, 1380252039], [79476534972, 0, 0, 0], [0, -18361466500, 0, 0], [0, 0, -523177249, 0], [0, 43161479910, 0, 0], [29024359362, 0, 0, 0], [0, 0, -3599605359, 0], [-6677152378, 0, 0, 0], [0, 0, 0, -6112268721], [0, 0, 0, 2127013344], [0, 0, 1490851521, 0], [0, 56976784920, 0, 0], [-140041005988, 0, 0, 0], [0, 0, 0, -3651543576], [0, 0, 0, 12823302439], [0, 0, 44612456, 0], [0, -198445712400, 0, 0], [-201430381448, 0, 0, 0], [0, 0, 0, -11678433081], [0, 0, 9024024996, 0], [0, 0, 0, -7357638116], [0, -124104175780, 0, 0], [211880877992, 0, 0, 0], [-120191954328, 0, 0, 0], [0, 0, 7024422681, 0], [0, 0, 0, 14678146679], [0, 0, 14293590676, 0], [0, -261429116940, 0, 0], [-99055667168, 0, 0, 0], [0, 0, -8914614684, 0], [0, 0, 0, 19731789324], [0, 0, -17734567289, 0], [-45739644428, 0, 0, 0], [98358560352, 0, 0, 0], [0, 132350735110, 0, 0], [0, 214770685320, 0, 0], [0, 0, 0, -2873169351], [0, 0, 5641350936, 0], [0, -60831048860, 0, 0], [0, 0, -16031536119, 0], [343050020752, 0, 0, 0], [0, 0, 0, 6181929144], [588789918882, 0, 0, 0], [0, -395721342130, 0, 0], [0, 0, 27279875516, 0], [0, 0, 0, 34289491239], [0, 0, 0, -35645585596], [0, -426453892290, 0, 0], [-823140407468, 0, 0, 0], [807431464512, 0, 0, 0], [0, 0, -33557643759, 0], [0, 0, 0, 8459703049], [0, -320562078320, 0, 0], [0, 834529017240, 0, 0], [0, 0, -54508611924, 0], [0, 0, 0, 39962895544], [0, 329698356260, 0, 0], [0, 0, -854243879, 0], [0, 0, 0, 37269963624], [-660238408008, 0, 0, 0], [0, 0, -3716286639, 0], [0, 0, 0, -13407857111], [0, 0, 0, -42935771631], [1034347145832, 0, 0, 0], [0, -704399660480, 0, 0], [0, 18713654280, 0, 0], [0, 0, 0, 28238186964], [89080566822, 0, 0, 0], [0, 0, 0, 18464173129], [0, 0, -51778675224, 0], [0, 0, 0, 12857484159], [-919748335788, 0, 0, 0], [0, 0, 0, 73879198524], [0, 0, 61902840311, 0], [959784547472, 0, 0, 0], [0, 0, 0, 38414460204]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_25_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_25_9_c_a();".
// 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_25_9_c_a(:prec:=4)
    chi := MakeCharacter_25_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 9));
    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_25_9_c_a();".
// 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_25_9_c_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_25_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,9,sign)));
    Vf := Kernel([<2,R![79524, 0, 0, 0, 1]>],Snew);
    return Vf;
end function;