
// Make newform 75.9.f.c in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_75_f();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_75_f_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_75_9_f_c();".
// 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_75_9_f_c();".
// 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 := [256, 0, 0, 0, -7, 0, 0, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 9, 0, 0, 0, 1, 0], [0, 11, 0, 0, 0, -1, 0, 0], [0, 0, 0, 71, 0, 0, 0, -1], [-42, 0, 0, 0, 12, 0, 0, 0], [0, 87, 0, 0, 0, 3, 0, 0], [0, 0, 69, 0, 0, 0, -3, 0], [0, 0, 0, 3, 0, 0, 0, 27]];
    Rf_basisdens := [1, 80, 20, 320, 5, 10, 8, 160];
    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_75_f();"
function MakeCharacter_75_f()
    N := 75;
    order := 4;
    char_gens := [26, 52];
    v := [4, 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_75_f_Hecke();"
function MakeCharacter_75_f_Hecke(Kf)
    N := 75;
    order := 4;
    char_gens := [26, 52];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 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, 2, 0, -1, 0, 0], [0, 0, 27, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, -1471, 0, 96, 0, 0], [13494, 0, 0, 0, 0, 0, -116, 0], [0, 0, 3531, 0, 0, 0, 0, 1092], [0, 0, 0, 1318, 0, -620, 0, 0], [0, 91571, 0, 0, 2332, 0, 0, 0], [0, 0, -12986, 0, 0, 0, 0, 13724], [0, 148062, 0, 0, 23404, 0, 0, 0], [-363539, 0, 0, 0, 0, 0, 20168, 0], [0, 0, 0, -1456796, 0, 32016, 0, 0], [4239276, 0, 0, 0, 0, 0, -27652, 0], [0, 0, 444685, 0, 0, 0, 0, -121332], [0, 0, 0, 1614270, 0, 161712, 0, 0], [0, 0, 1243604, 0, 0, 0, 0, -168356], [0, 7828614, 0, 0, 148848, 0, 0, 0], [3705875, 0, 0, 0, 0, 0, 538636, 0], [0, 0, 0, 379023, 0, -1122900, 0, 0], [-3530868, 0, 0, 0, 0, 0, 101260, 0], [0, 0, -5871476, 0, 0, 0, 0, 1523544], [0, -24785990, 0, 0, -232600, 0, 0, 0], [0, 0, 6252442, 0, 0, 0, 0, 3756056], [0, 85933356, 0, 0, -535288, 0, 0, 0], [0, 0, 0, 23773483, 0, 3498360, 0, 0], [-17266056, 0, 0, 0, 0, 0, 429964, 0], [0, 0, 20916920, 0, 0, 0, 0, 484368], [0, 0, 0, 44448720, 0, 4164852, 0, 0], [0, -35244959, 0, 0, -3166108, 0, 0, 0], [0, 0, -82586688, 0, 0, 0, 0, -2056704], [0, 0, 0, 70122708, 0, 9292320, 0, 0], [57775140, 0, 0, 0, 0, 0, 4091556, 0], [0, 0, 0, 54062002, 0, -15120296, 0, 0], [0, 331564334, 0, 0, 6337008, 0, 0, 0], [0, 532970358, 0, 0, 5221976, 0, 0, 0], [-44025023, 0, 0, 0, 0, 0, -7552920, 0], [0, 0, 0, 282977387, 0, 15950364, 0, 0], [0, 0, 407764053, 0, 0, 0, 0, -956340], [0, 0, 0, -240328936, 0, -17405644, 0, 0], [0, 0, -334173418, 0, 0, 0, 0, -34013924], [0, 869248110, 0, 0, 1865920, 0, 0, 0], [-64663559, 0, 0, 0, 0, 0, -30242452, 0], [-655379946, 0, 0, 0, 0, 0, -28057236, 0], [0, 0, 656134507, 0, 0, 0, 0, 32342136], [0, 0, 0, 836248226, 0, -25003312, 0, 0], [0, 953680273, 0, 0, -40395864, 0, 0, 0], [-973881409, 0, 0, 0, 0, 0, -46064492, 0], [0, 0, -2208071689, 0, 0, 0, 0, 37525032], [0, 0, 0, 440840504, 0, -19936924, 0, 0], [0, -1148056261, 0, 0, -18982172, 0, 0, 0], [0, 0, 62383740, 0, 0, 0, 0, 67809348], [0, -391309284, 0, 0, 74673092, 0, 0, 0], [1096668479, 0, 0, 0, 0, 0, -9305456, 0], [-2570500848, 0, 0, 0, 0, 0, -21820240, 0], [0, 0, 0, 2277684100, 0, -14759168, 0, 0], [0, 0, 5110507068, 0, 0, 0, 0, 13860300], [0, 2418584106, 0, 0, -107644988, 0, 0, 0], [-666316066, 0, 0, 0, 0, 0, 22749184, 0], [0, 0, 0, 91850761, 0, 257862588, 0, 0], [-2231098122, 0, 0, 0, 0, 0, 113505332, 0], [0, 0, 1728936671, 0, 0, 0, 0, 22365972], [0, 0, 2753347058, 0, 0, 0, 0, -329752280], [0, 0, 0, 2735061515, 0, 229682412, 0, 0], [4448071554, 0, 0, 0, 0, 0, 207122984, 0], [0, 0, -4009951767, 0, 0, 0, 0, 265917480], [0, 0, 0, 4188423740, 0, -177636448, 0, 0], [4044414422, 0, 0, 0, 0, 0, -143032560, 0], [0, 0, 0, -4705261539, 0, 565936368, 0, 0], [0, 0, 0, 1910051478, 0, -691876200, 0, 0], [0, 9404544662, 0, 0, 156769024, 0, 0, 0], [0, 0, -6008543154, 0, 0, 0, 0, 395611692], [0, -14487479856, 0, 0, 9407388, 0, 0, 0], [0, 0, 0, -6611628879, 0, 191304288, 0, 0], [0, 0, -13673178115, 0, 0, 0, 0, -282982692], [0, -16847811685, 0, 0, -313043540, 0, 0, 0], [0, 0, -3709512592, 0, 0, 0, 0, -1123823240], [0, -9698415096, 0, 0, -516914812, 0, 0, 0], [0, 0, 0, -4021440995, 0, 22509732, 0, 0], [-24236388660, 0, 0, 0, 0, 0, -38460484, 0], [0, -13022093101, 0, 0, -1027865312, 0, 0, 0], [0, 169643976, 0, 0, 1374707372, 0, 0, 0], [29596657258, 0, 0, 0, 0, 0, -14675848, 0], [-11900280594, 0, 0, 0, 0, 0, 227342468, 0], [0, 0, -3334011337, 0, 0, 0, 0, -578525760], [0, 5978656405, 0, 0, -993306880, 0, 0, 0], [0, 0, 106276196, 0, 0, 0, 0, 916712872], [0, 34647835548, 0, 0, 1066665136, 0, 0, 0], [0, 0, 0, 4237415064, 0, -2531476944, 0, 0], [-18485540628, 0, 0, 0, 0, 0, -1773719420, 0], [0, 0, 20411840740, 0, 0, 0, 0, 10237968], [0, 0, 0, -26287406110, 0, -104133508, 0, 0], [0, 23957881650, 0, 0, -377428080, 0, 0, 0], [0, 0, 0, -8178198117, 0, 404265480, 0, 0], [108059039580, 0, 0, 0, 0, 0, -131323904, 0], [0, -11215857719, 0, 0, 1519370132, 0, 0, 0], [0, 0, 15837052216, 0, 0, 0, 0, 981577532], [0, -25879612026, 0, 0, -491465632, 0, 0, 0], [-52149289254, 0, 0, 0, 0, 0, 523888108, 0], [0, 0, -3201267715, 0, 0, 0, 0, -3012400932], [-95754494629, 0, 0, 0, 0, 0, -475899732, 0], [0, 0, 0, 45266820944, 0, 2498605656, 0, 0], [0, 0, 0, -34125807582, 0, 2935507440, 0, 0], [0, 0, 39639041022, 0, 0, 0, 0, -1785381204], [0, -89466309954, 0, 0, -102557988, 0, 0, 0], [155779060979, 0, 0, 0, 0, 0, 1023491044, 0], [0, 0, 0, -6951320657, 0, 5310942120, 0, 0], [0, 0, 0, 1607933140, 0, -2917165868, 0, 0], [0, 0, -70003480160, 0, 0, 0, 0, 2898825428], [0, 111870553968, 0, 0, 3267022056, 0, 0, 0], [-117482308451, 0, 0, 0, 0, 0, -125326576, 0], [0, 0, 0, 52866753628, 0, 3491728200, 0, 0], [0, 0, -128161796548, 0, 0, 0, 0, -1058574504], [0, 0, 0, -75420357488, 0, 2390856484, 0, 0], [0, 88710577009, 0, 0, 4958192028, 0, 0, 0], [171769470947, 0, 0, 0, 0, 0, 2866902880, 0], [-97651508844, 0, 0, 0, 0, 0, -5250977272, 0], [0, 0, -44022843660, 0, 0, 0, 0, 1447033848], [0, 0, 0, 59252460728, 0, 2762730440, 0, 0], [0, 0, 3084923018, 0, 0, 0, 0, -14235496520], [0, 21429312060, 0, 0, -5959327940, 0, 0, 0], [3869689882, 0, 0, 0, 0, 0, 2607092400, 0], [0, 0, 140420518084, 0, 0, 0, 0, 1302337704], [0, 0, 0, -31966489854, 0, 12386869788, 0, 0], [0, 0, 112139812208, 0, 0, 0, 0, -4080176600], [-31058874866, 0, 0, 0, 0, 0, 5166780944, 0], [-44700992430, 0, 0, 0, 0, 0, -10614731564, 0], [0, -98892307969, 0, 0, -8459971668, 0, 0, 0], [0, -108167372022, 0, 0, 2680456196, 0, 0, 0], [0, 0, 0, 91753314047, 0, -14038740096, 0, 0], [0, 0, -162908193060, 0, 0, 0, 0, -1725243912], [0, 140167194974, 0, 0, 625585768, 0, 0, 0], [0, 0, 211970230140, 0, 0, 0, 0, -9136193592], [272210834914, 0, 0, 0, 0, 0, -9514299616, 0], [0, 0, 0, 35531327057, 0, -11372359236, 0, 0], [-176285457072, 0, 0, 0, 0, 0, 6395844552, 0], [0, -301884229787, 0, 0, 7109128856, 0, 0, 0], [0, 0, -41529175712, 0, 0, 0, 0, 15485589380], [0, 0, 0, -163281947335, 0, 8767163172, 0, 0], [0, 0, 0, -236196775240, 0, -2085109648, 0, 0], [0, -665362160820, 0, 0, 3728350260, 0, 0, 0], [61018444657, 0, 0, 0, 0, 0, -15813091860, 0], [-266506438002, 0, 0, 0, 0, 0, -10775172008, 0], [0, 0, 55167421917, 0, 0, 0, 0, -9889453824], [0, 0, 0, -211074261332, 0, -5029958660, 0, 0], [0, -522754269310, 0, 0, 5104764720, 0, 0, 0], [0, 331143275970, 0, 0, -12042611340, 0, 0, 0], [0, 0, -268971847977, 0, 0, 0, 0, -13880331660], [0, 0, 0, -17997685100, 0, 11905500952, 0, 0], [0, 323016628750, 0, 0, -8135643520, 0, 0, 0], [0, 0, 106998895280, 0, 0, 0, 0, -30596481032], [0, 0, 0, 229444975109, 0, 19823982276, 0, 0], [-25618571352, 0, 0, 0, 0, 0, 9196186872, 0], [0, 0, 341959093985, 0, 0, 0, 0, 1653217068], [0, 0, 0, -283415488790, 0, 9790467592, 0, 0], [0, 0, 0, -271382315660, 0, 20713011072, 0, 0], [886508446122, 0, 0, 0, 0, 0, 2250347160, 0], [0, -615956323105, 0, 0, 10661670000, 0, 0, 0], [0, -12558729234, 0, 0, 6624697172, 0, 0, 0], [0, 0, 0, -690535061179, 0, -9060301992, 0, 0], [870455110686, 0, 0, 0, 0, 0, 16461940448, 0], [0, 0, 0, -414164233538, 0, -3577830716, 0, 0], [0, 0, -600329842884, 0, 0, 0, 0, -9937477128], [0, 0, 0, 223255579468, 0, -16974201960, 0, 0], [-142655336334, 0, 0, 0, 0, 0, 17979232968, 0], [0, 0, 0, 683441314698, 0, -6668441520, 0, 0], [0, 0, -193403536436, 0, 0, 0, 0, -14348595856], [-437917159993, 0, 0, 0, 0, 0, 7475657920, 0], [0, 0, 0, -5439861348, 0, -10210456056, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_75_f_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_75_9_f_c();".
// 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_75_9_f_c(:prec:=8)
    chi := MakeCharacter_75_f();
    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_75_9_f_c();".
// 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_75_9_f_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_75_f();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,9,sign)));
    Vf := Kernel([<2,R![43237380096, 0, 0, 0, 505728, 0, 0, 0, 1]>],Snew);
    return Vf;
end function;