
// Make newform 25.9.c.b 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_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_9_c_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 := [4608, -3168, 1089, -30, 2, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [-62928, 41631, 790, -10, -22, 39], [-21504, 1028583, -5530, 70, 154, -273], [-2347872, 838569, -45790, -4990, -2178, 761], [244704, -83733, 2030, -3570, 146, -77], [187392, -823209, 48190, -610, -1342, -921]];
    Rf_basisdens := [1, 66000, 66000, 66000, 6000, 66000];
    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, 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], [12, 12, 1, 0, 0, 1], [0, 0, 0, 0, 0, 0], [434, -434, 0, -119, 7, 0], [3792, 0, -85, 25, -85, 25], [20015, 20015, -80, 0, 0, -554], [43617, -43617, 0, 2366, 466, 0], [0, 54264, -684, 930, 684, -930], [-4722, -4722, -1581, 0, 0, -1859], [0, -451044, -2386, -15980, 2386, 15980], [-99628, 0, 3045, -34425, 3045, -34425], [72653, -72653, 0, 7536, -1506, 0], [422352, 0, -12505, -23675, -12505, -23675], [-105376, -105376, -5323, 0, 0, -85519], [2583906, -2583906, 0, -90779, 4263, 0], [2162457, 2162457, 4186, 0, 0, 271376], [0, -1372608, -30152, 508490, 30152, -508490], [4266032, 0, -95625, -466875, -95625, -466875], [5539832, -5539832, 0, -101959, 103661, 0], [-2912988, 0, 78125, 949375, 78125, 949375], [-18480997, -18480997, -12756, 0, 0, -499584], [0, -22879824, -122456, -1313680, 122456, 1313680], [2441256, 2441256, 212813, 0, 0, 273261], [0, 38523288, 442572, 666960, -442572, -666960], [31017911, -31017911, 0, -586904, -861272, 0], [-19173978, 0, 224930, -1271450, 224930, -1271450], [26457662, 26457662, 1421251, 0, 0, 1125301], [-86184756, 86184756, 0, -545119, -449663, 0], [0, 31156182, 447483, -3184635, -447483, 3184635], [50237145, 50237145, -1507590, 0, 0, 1566646], [-65588170, 65588170, 0, 18019401, 2163915, 0], [-273813048, 0, 32615, -2875475, 32615, -2875475], [-213144357, 213144357, 0, -793064, 1735164, 0], [0, -127641072, -802768, 14803210, 802768, -14803210], [0, 478785450, -944075, -8169325, 944075, 8169325], [65969972, 0, -2971995, 17771175, -2971995, 17771175], [266408939, -266408939, 0, 29673206, -4432228, 0], [-192971380, -192971380, -5454015, 0, 0, 29067921], [-312422898, 312422898, 0, -44722659, 2265971, 0], [426100413, 426100413, 6303374, 0, 0, -42873984], [0, -599966064, 3801984, -614130, -3801984, 614130], [696255242, 0, 1284900, -30448500, 1284900, -30448500], [-1106203308, 0, -10311595, -2294825, -10311595, -2294825], [-277671511, -277671511, -3519878, 0, 0, -36502994], [259030101, -259030101, 0, -67504504, -1497002, 0], [0, -829441200, 5656200, -17612100, -5656200, 17612100], [258341552, 0, 1514955, -75265575, 1514955, -75265575], [-493604602, -493604602, -4044421, 0, 0, -185359159], [416556540, -416556540, 0, 176532901, -24941055, 0], [0, 1129375716, 23043554, 65534020, -23043554, -65534020], [1349619021, 1349619021, -26999042, 0, 0, -44662714], [0, -2243177112, 3277972, -22856740, -3277972, 22856740], [-1113200128, 0, -4925025, 15694125, -4925025, 15694125], [1345888152, 0, 11714975, 97859125, 11714975, 97859125], [1414353489, -1414353489, 0, 19004406, 11172722, 0], [-2875309950, -2875309950, 44864375, 0, 0, 97709121], [0, 1908516354, 38032401, 36623955, -38032401, -36623955], [-6499196308, 0, 11894145, -13025925, 11894145, -13025925], [-2379706705, 2379706705, 0, 145488526, -71123840, 0], [5016655872, 0, -50236705, -227930675, -50236705, -227930675], [-1701149764, -1701149764, -20038847, 0, 0, 34249261], [3258221859, 3258221859, 15987732, 0, 0, -173813594], [-761206336, 761206336, 0, 45793881, 80285397, 0], [3684052812, 0, 14906945, 317362075, 14906945, 317362075], [6424350125, 6424350125, 22244750, 0, 0, 93649646], [4757382147, -4757382147, 0, 49066366, -6281244, 0], [3922970432, 0, -50925165, 195186225, -50925165, 195186225], [-1881186457, 1881186457, 0, 303770336, 62667464, 0], [2343357456, -2343357456, 0, -140941179, -71526187, 0], [0, -296898420, 41041270, 379629500, -41041270, -379629500], [-1611261633, -1611261633, 96348416, 0, 0, -32885424], [0, 10324510872, -11372532, 332660640, 11372532, -332660640], [-1519639858, 1519639858, 0, 1295908441, -59138909, 0], [-3591178207, -3591178207, 103268914, 0, 0, 1041045016], [0, -16175152344, 50941164, -410560530, -50941164, 410560530], [6081109206, 6081109206, -103840437, 0, 0, 1711937161], [0, -6023163522, 95453807, -137708915, -95453807, 137708915], [4872109841, -4872109841, 0, 232362096, -182236782, 0], [12447086562, 0, 19799840, 1020822400, 19799840, 1020822400], [0, 11769401622, -211899157, 786846115, 211899157, -786846115], [0, 16127298024, -58270244, -346434670, 58270244, 346434670], [-12382914208, 0, 162930495, -1264668675, 162930495, -1264668675], [22668681852, 0, -7882135, -823491725, -7882135, -823491725], [-21704715889, -21704715889, -148174272, 0, 0, 219771336], [0, -22294366872, -73799468, -698255440, 73799468, 698255440], [15729645324, 15729645324, -223007023, 0, 0, -715716819], [0, 11657161170, -59009895, -355909275, 59009895, 355909275], [-23514589651, 23514589651, 0, -941989394, -158564498, 0], [-3975489498, 0, 154900130, -857399450, 154900130, -857399450], [-977819830, -977819830, 62967535, 0, 0, -1728042179], [-8391245268, 8391245268, 0, 1409709341, 242392561, 0], [0, 13708552776, -118992556, 3013121620, 118992556, -3013121620], [12650156138, -12650156138, 0, -1310520639, 461142399, 0], [-29094356688, 0, 154753835, -141208775, 154753835, -141208775], [0, 36117312840, 320560460, 349136650, -320560460, -349136650], [58452692502, 58452692502, 140489371, 0, 0, 450237701], [0, 65411580492, -20481002, -2020031860, 20481002, 2020031860], [-31148393058, 0, -488727730, 674893450, -488727730, 674893450], [35866548428, 35866548428, -200891631, 0, 0, 1297329141], [-55302913018, 0, 373023090, 3398136150, 373023090, 3398136150], [-2886866644, 2886866644, 0, -2034828779, 74696113, 0], [15638499129, -15638499129, 0, 5271800456, 376146442, 0], [3895496460, 3895496460, 768291105, 0, 0, 1820983321], [0, 8433759354, 974047901, 3252699805, -974047901, -3252699805], [16546660352, 0, -184179165, 1349076225, -184179165, 1349076225], [-22888348255, 22888348255, 0, 364713126, -1345138590, 0], [133303982808, -133303982808, 0, -1521485339, -285137091, 0], [-2117913321, -2117913321, 758728792, 0, 0, -4964969344], [0, 10200326880, 41140720, -6125504500, -41140720, 6125504500], [60350065952, 0, 935064975, 1274764125, 935064975, 1274764125], [-41296907686, 41296907686, 0, 4474844981, 1157665247, 0], [8740061675, 8740061675, 984996300, 0, 0, 4120652046], [44607072357, -44607072357, 0, -9371016234, -659815114, 0], [0, -28262726736, -115855184, -7351864870, 115855184, 7351864870], [-108497984788, 0, -1301011695, 2612361675, -1301011695, 2612361675], [170480263392, 0, 311659055, -334127075, 311659055, -334127075], [-86221783576, -86221783576, -617063123, 0, 0, -3777116219], [93464480346, -93464480346, 0, 2780485121, 101212783, 0], [33468363957, 33468363957, -1308245514, 0, 0, 11227931176], [0, -49649727048, -415774012, 9600866290, 415774012, -9600866290], [-22792449088, 0, -650085105, -6640914675, -650085105, -6640914675], [16586085383, 16586085383, 1299260984, 0, 0, -4819321384], [38894238645, -38894238645, 0, 13216567576, 137057910, 0], [-159096477024, -159096477024, -1825454027, 0, 0, 4651890161], [-9268808608, 0, 172817955, -5437660575, 172817955, -5437660575], [-92064580368, 0, -723467305, 9346848325, -723467305, 9346848325], [0, -91371073548, -1312600262, -6633803860, 1312600262, 6633803860], [0, 31028339784, 1244960196, -3493097220, -1244960196, 3493097220], [-75808690870, 75808690870, 0, -4370729399, 723559615, 0], [28626517781, 28626517781, 879360838, 0, 0, 1091896336], [0, 121971175008, -757312248, 5363929710, 757312248, -5363929710], [158547362874, 158547362874, -1999459473, 0, 0, -7084738919], [-383877681868, 0, 773347845, -433246425, 773347845, -433246425], [1346978399, -1346978399, 0, 22654756206, -711422448, 0], [68753234802, 0, 2623805480, 5837867800, 2623805480, 5837867800], [0, -41874110496, 813925376, 1542422080, -813925376, -1542422080], [213269695083, 213269695083, 846167884, 0, 0, -12486616834], [71075985608, -71075985608, 0, -1134597439, -824901091, 0], [133129672611, -133129672611, 0, -22814060754, -2548340572, 0], [0, 34850159832, 3593637708, 6122561640, -3593637708, -6122561640], [440571412472, 0, 374646735, 10322542725, 374646735, 10322542725], [-71712678768, 0, -261469945, -20327612075, -261469945, -20327612075], [-257362517842, -257362517842, 3701490259, 0, 0, 6605060941], [-80345632080, 80345632080, 0, -14737935499, 4699653685, 0], [0, 298486302546, 2990371449, -4233508605, -2990371449, 4233508605], [0, -32063325552, -4643806888, -1963045940, 4643806888, 1963045940], [-172094874973, -172094874973, 353540996, 0, 0, -15957351874], [-51525961821, 51525961821, 0, -2998743944, -1758728508, 0], [0, -780756500448, -610917112, 6103291690, 610917112, -6103291690], [105854348250, 105854348250, -771356225, 0, 0, -18942085579], [95242021715, -95242021715, 0, -24461789674, 5573900420, 0], [-214407545328, 0, -294607705, 8964564325, -294607705, 8964564325], [19976206316, 19976206316, -1103627007, 0, 0, 45886967961], [-428624652222, 428624652222, 0, -12880224639, -276079081, 0], [576777488924, -576777488924, 0, 7619870881, -2048129423, 0], [-205532546508, 0, -557169835, -5333021225, -557169835, -5333021225], [0, 467639521584, -4778404104, 36308412180, 4778404104, -36308412180], [0, 316127770446, -4277860201, -32402810405, 4277860201, 32402810405], [759300982853, -759300982853, 0, -8168563914, -538685706, 0], [204886465482, 0, 4364033540, -10891438100, 4364033540, -10891438100], [102349467696, -102349467696, 0, 4946943721, 7956041733, 0], [-65565329523, -65565329523, -3783866354, 0, 0, 14543994926], [-665422870858, 665422870858, 0, 22071611141, -6392139109, 0], [131925098472, 0, -6012938185, 32670346525, -6012938185, 32670346525], [-198482073345, 198482073345, 0, 15934829976, 1741659440, 0], [-226529644734, -226529644734, -1412522857, 0, 0, 22556890761], [-482380299508, 0, -3815586495, -23125736325, -3815586495, -23125736325], [-176100860209, 176100860209, 0, 36805683046, 7585544368, 0]];
    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_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_9_c_b(:prec:=6)
    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_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_9_c_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_25_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,9,sign)));
    Vf := Kernel([<2,R![5068928, -1248128, 153664, -2400, 2, -2, 1]>],Snew);
    return Vf;
end function;