
// Make newform 25.6.b.b in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_25_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_25_b_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_6_b_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_b_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 := [3600, 0, 121, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -81, 0, -1], [0, -61, 0, -1], [303, 0, 5, 0]];
    Rf_basisdens := [1, 20, 12, 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_25_b();"
function MakeCharacter_25_b()
    N := 25;
    order := 2;
    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_b_Hecke();"
function MakeCharacter_25_b_Hecke(Kf)
    N := 25;
    order := 2;
    char_gens := [2];
    char_values := [[-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 := 6;
    raw_aps := [[0, -1, 1, 0], [0, -2, -1, 0], [0, 0, 0, 0], [0, 4, 18, 0], [-103, 0, 0, 10], [0, -32, 52, 0], [0, -136, 217, 0], [1583, 0, 0, 14], [0, -12, -150, 0], [1952, 0, 0, 16], [-438, 0, 0, -220], [0, 384, 10, 0], [13837, 0, 0, 80], [0, 2128, -764, 0], [0, 1544, 1804, 0], [0, -752, 3074, 0], [-6176, 0, 0, 392], [-12398, 0, 0, 400], [0, -1586, -3213, 0], [-43748, 0, 0, 200], [0, -1112, 7585, 0], [-32238, 0, 0, -1004], [0, 858, -9687, 0], [35361, 0, 0, 2088], [0, 10944, -18086, 0], [38142, 0, 0, -2880], [0, 9048, -28156, 0], [0, 1554, 15213, 0], [116314, 0, 0, -2688], [0, -10832, 4757, 0], [0, 2324, 34706, 0], [-156228, 0, 0, 960], [0, -35616, 12585, 0], [33151, 0, 0, -4842], [-240160, 0, 0, -7280], [-77558, 0, 0, 2020], [0, 44304, -22262, 0], [0, 40818, -30283, 0], [0, -8136, 41292, 0], [0, -22512, -11400, 0], [-428813, 0, 0, 4646], [291602, 0, 0, 3600], [-253658, 0, 0, -11380], [0, -20472, -1129, 0], [0, -19056, -100986, 0], [73820, 0, 0, -2440], [216167, 0, 0, 17670], [0, -78312, 134180, 0], [0, -49376, 30476, 0], [38412, 0, 0, -10304], [0, -16992, -169902, 0], [-91424, 0, 0, -28192], [-228623, 0, 0, 3400], [-224673, 0, 0, 16350], [0, 136704, 128598, 0], [0, -28732, -269078, 0], [-165632, 0, 0, 22544], [1637962, 0, 0, -12620], [0, -94976, 270336, 0], [-258738, 0, 0, -9120], [0, 20858, 207813, 0], [0, 122928, -416094, 0], [0, 139154, -312847, 0], [1796262, 0, 0, 21180], [0, 147168, -258418, 0], [0, -154736, 65852, 0], [-1484643, 0, 0, -44110], [0, -136816, -46345, 0], [0, 364994, -381491, 0], [515930, 0, 0, 51440], [0, -171552, -24846, 0], [925674, 0, 0, -31308], [0, -217736, 592452, 0], [0, -600512, 277150, 0], [-365563, 0, 0, 27146], [0, 557508, -342102, 0], [410226, 0, 0, 103008], [0, -26656, -619276, 0], [-1888803, 0, 0, -28440], [37579, 0, 0, 24432], [-3904237, 0, 0, -41546], [3225412, 0, 0, -31520], [3086022, 0, 0, -75540], [0, 426808, 36343, 0], [630056, 0, 0, -90352], [0, 280578, -256359, 0], [372175, 0, 0, -88600], [0, 385904, 502253, 0], [-412308, 0, 0, -128880], [0, 324968, -1137948, 0], [0, -412736, -64948, 0], [2473002, 0, 0, -15084], [0, -359916, 1077490, 0], [-2611268, 0, 0, 104240], [-5970340, 0, 0, -28720], [0, -670552, -472196, 0], [7765294, 0, 0, 9152], [2087437, 0, 0, 75680], [0, 633238, -347225, 0], [-656928, 0, 0, -57040], [0, 423794, -2018671, 0], [0, -206496, -1034532, 0], [0, -427032, -454248, 0], [-10047777, 0, 0, 108384], [-6413068, 0, 0, -147360], [0, -565776, -898409, 0], [0, 1671534, -820305, 0], [0, 64928, 1154581, 0], [2986730, 0, 0, 180340], [-2085373, 0, 0, 93000], [0, 1161104, -920992, 0], [0, 1113568, 354442, 0], [0, -155136, -1730058, 0], [-11463332, 0, 0, 22944], [8737642, 0, 0, 262420], [7550442, 0, 0, 25920], [0, -1459072, -595644, 0], [0, -646456, 3436204, 0], [0, -1563952, 1203394, 0], [11293549, 0, 0, -58558], [-5425088, 0, 0, 198880], [0, -682912, -1670610, 0], [0, 1722624, -1215024, 0], [0, -733242, 3911223, 0], [-5654483, 0, 0, 275770], [-6636788, 0, 0, 321680], [-2977396, 0, 0, -74368], [18991158, 0, 0, -135636], [0, -685776, -824384, 0], [0, 2039808, -1136332, 0], [-361444, 0, 0, 293648], [0, -865772, 234026, 0], [-5213888, 0, 0, -437120], [0, 1101104, 2885408, 0], [-9107283, 0, 0, -145680], [-4364357, 0, 0, 252744], [0, 2595888, -2163240, 0], [0, -566416, -1468060, 0], [0, -976256, -3165166, 0], [-13446466, 0, 0, -112928], [-4342668, 0, 0, -249760], [-12529158, 0, 0, -562080], [0, -3170712, 2240420, 0], [0, 324974, -986609, 0], [1541292, 0, 0, 606736], [-4671424, 0, 0, -386192], [0, -86752, -3017826, 0], [0, -95296, -1204727, 0], [5125919, 0, 0, 54902], [0, -3112432, 2860792, 0], [0, 2066224, 1139316, 0], [-9137938, 0, 0, 873280], [0, 966558, 4458743, 0], [0, 413784, 943020, 0], [0, -2055296, 3054948, 0], [-2361028, 0, 0, -439640], [-23304622, 0, 0, 595124], [-8829598, 0, 0, -704384], [0, -3463016, -65625, 0], [-17320628, 0, 0, -372640], [0, 996744, 7391184, 0], [0, 550048, -1459381, 0], [0, -12336, -6435488, 0], [17363097, 0, 0, -146790], [0, 3261224, -1514459, 0], [0, 1359108, -9710262, 0], [-21808258, 0, 0, -390180], [0, -5482256, 6304884, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_25_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_25_6_b_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_b_b(:prec:=4)
    chi := MakeCharacter_25_b();
    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_b_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_b_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_25_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![2916, 0, 133, 0, 1]>],Snew);
    return Vf;
end function;