
// Make newform 25.6.a.b in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_25_a();"
// 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_6_a_b();".
// 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_6_a_b();".
// 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 := [-60, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_a();"
function MakeCharacter_25_a()
    N := 25;
    order := 1;
    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;

function MakeCharacter_25_a_Hecke(Kf)
    return MakeCharacter_25_a();
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 := 6;
    raw_aps := [[-2, -1], [-11, 2], [0, 0], [-102, 4], [-73, -50], [164, 32], [-677, -136], [-1625, 70], [-786, 12], [-2000, 80], [-1098, 1100], [-1202, 384], [14077, -400], [2564, -2128], [-13652, 1544], [13114, 752], [5000, 1960], [-11198, -2000], [20823, -1586], [-43148, -1000], [34589, 1112], [35250, -5020], [-45861, -858], [-41625, 10440], [57598, 10944], [29502, 14400], [-113636, -9048], [-80727, 1554], [-108250, -13440], [-8711, 10832], [-180502, 2324], [-153348, -4800], [43923, -35616], [-18625, -24210], [262000, -36400], [-71498, -10100], [-21602, 44304], [-28961, -40818], [-182052, -8136], [-124536, 22512], [414875, 23230], [302402, -18000], [-287798, 56900], [-67061, 20472], [562098, -19056], [-66500, -12200], [269177, -88350], [435964, 78312], [-4252, -49376], [-7500, -51520], [-900486, 16992], [176000, -140960], [-218423, -17000], [-175623, -81750], [-1053102, 136704], [-1431586, 28732], [98000, 112720], [1600102, 63100], [-1066752, -94976], [-286098, 45600], [1101639, -20858], [-1711686, -122928], [1146773, 139154], [1859802, -105900], [-850586, -147168], [134948, -154736], [-1616973, 220550], [642173, -136816], [812473, 364994], [-670250, 257200], [-638886, 171552], [-831750, -156540], [-2309052, -217736], [-415786, 600512], [284125, 135730], [-37986, -557508], [-719250, 515040], [3176348, -26656], [-1974123, 142200], [-110875, 122160], [4028875, -207730], [3130852, 157600], [2859402, 377700], [1462139, -426808], [-359000, -451760], [-440061, -280578], [-106375, -443000], [-3668977, 385904], [-798948, 644400], [-4714836, -324968], [1562948, -412736], [-2427750, -75420], [-4307702, -359916], [-2298548, -521200], [6056500, -143600], [-4372636, 670552], [-7792750, 45760], [2314477, -378400], [163589, -633238], [-828048, 285200], [8821973, 423794], [5792148, -206496], [-3552336, 427032], [9722625, 541920], [-6855148, 736800], [6189373, -565776], [-913077, 1671534], [5967689, -64928], [-3527750, 901700], [-1806373, -465000], [1121648, 1161104], [5112914, -1113568], [9115698, -155136], [11394500, 114720], [9524902, -1312100], [7628202, -129600], [-7355436, 1459072], [-15241652, -646456], [1325114, 1563952], [-11117875, -292790], [-4828448, -994400], [-10401786, 682912], [907248, 1722624], [17356389, 733242], [-4827173, -1378850], [-5671748, -1608400], [3200500, -371840], [-18584250, -678180], [6179248, -685776], [437764, -2039808], [-519500, 1468240], [-1427186, 865772], [-6525248, 2185600], [-17730352, 1101104], [-9544323, 728400], [3606125, 1263720], [-3028536, -2595888], [9039548, -566416], [18754598, -976256], [13785250, -564640], [-5091948, 1248800], [-14215398, 2810400], [1689964, 3170712], [3958123, 324974], [-3361500, 3033680], [5830000, -1930960], [-15349386, 86752], [6309523, -95296], [-5290625, 274510], [4966664, 3112432], [-11895252, 2066224], [-6518098, -4366400], [25193389, -966558], [-5956452, 413784], [-9108852, -2055296], [-3679948, 2198200], [21519250, 2975620], [10942750, -3521920], [10717173, -3463016], [-18438548, 1863200], [-39946152, 996744], [-5646761, -550048], [32214448, -12336], [16922727, 733950], [-2211377, 3261224], [-44473986, -1359108], [-22978798, 1950900], [-15077652, -5482256]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_25_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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