
// Make newform 75.9.f.b in Magma, downloaded from the LMFDB on 25 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_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_75_9_f_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 := [625, 0, 0, 0, 119, 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, 79, 0, 0, 0, 1, 0, 0], [0, 0, 144, 0, 0, 0, 1, 0], [0, 0, 0, 827, 0, 0, 0, 8], [2975, 0, -1222, 0, 50, 0, -13, 0], [-2975, 0, -1222, 0, -50, 0, -13, 0], [0, 15675, 0, 6801, 0, 75, 0, 54], [0, -15675, 0, 6801, 0, -75, 0, 54]];
    Rf_basisdens := [1, 65, 325, 1625, 325, 325, 1625, 1625];
    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, 0, 1, 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, -2, 0, 0, 0, -1, 0, 0], [0, 0, 0, 27, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, -49, 0, 0, 0, 126, 0, 0], [6594, 0, 0, 0, 0, 0, 0, -674], [0, 0, 0, 6741, -3588, 0, 0, 0], [0, 15782, 0, 0, 0, 6550, 0, 0], [0, 0, -42379, 0, 0, 0, 3742, 0], [0, 0, 0, 26254, -17806, 0, 0, 0], [0, 0, -172578, 0, 0, 0, 14714, 0], [-855269, 0, 0, 0, 0, 0, 0, -12218], [0, -165284, 0, 0, 0, -28284, 0, 0], [-3628644, 0, 0, 0, 0, 0, 0, 51002], [0, 0, 0, 2878445, 120858, 0, 0, 0], [0, 390930, 0, 0, 0, -185028, 0, 0], [0, 0, 0, 6908924, 186994, 0, 0, 0], [0, 0, 1623114, 0, 0, 0, -231792, 0], [-9247765, 0, 0, 0, 0, 0, 0, 861704], [0, -7266903, 0, 0, 0, -1725330, 0, 0], [4137612, 0, 0, 0, 0, 0, 0, -1788530], [0, 0, 0, -6571876, -827556, 0, 0, 0], [0, 0, -7983770, 0, 0, 0, 3134420, 0], [0, 0, 0, 2620042, -3359044, 0, 0, 0], [0, 0, 69916476, 0, 0, 0, -793148, 0], [0, 7687027, 0, 0, 0, -9891360, 0, 0], [117865464, 0, 0, 0, 0, 0, 0, -3353654], [0, 0, 0, -60651080, 1439508, 0, 0, 0], [0, -98550600, 0, 0, 0, 2590962, 0, 0], [0, 0, -68922479, 0, 0, 0, -7949008, 0], [0, 0, 0, 35600592, 9865176, 0, 0, 0], [0, -11828028, 0, 0, 0, 11142060, 0, 0], [-94301820, 0, 0, 0, 0, 0, 0, 13820994], [0, -147609262, 0, 0, 0, -16727396, 0, 0], [0, 0, -459080806, 0, 0, 0, 4215288, 0], [0, 0, -62626362, 0, 0, 0, 38684056, 0], [-391069433, 0, 0, 0, 0, 0, 0, -8004750], [0, 135676283, 0, 0, 0, 58624584, 0, 0], [0, 0, 0, 109578453, 278610, 0, 0, 0], [0, -381194864, 0, 0, 0, -45699934, 0, 0], [0, 0, 0, 746499962, 10104166, 0, 0, 0], [0, 0, 42412290, 0, 0, 0, -60315280, 0], [208575841, 0, 0, 0, 0, 0, 0, 23248732], [476528274, 0, 0, 0, 0, 0, 0, 34999386], [0, 0, 0, -111773203, 148369116, 0, 0, 0], [0, -784974686, 0, 0, 0, 126889868, 0, 0], [0, 0, 158413183, 0, 0, 0, 94395066, 0], [1920334961, 0, 0, 0, 0, 0, 0, -43917838], [0, 0, 0, -269827649, 61869342, 0, 0, 0], [0, -984879344, 0, 0, 0, 237290066, 0, 0], [0, 0, -1039512781, 0, 0, 0, 148838848, 0], [0, 0, 0, -1240969260, -43386882, 0, 0, 0], [0, 0, -2074201764, 0, 0, 0, -39215738, 0], [3247785719, 0, 0, 0, 0, 0, 0, 15712976], [-2161723488, 0, 0, 0, 0, 0, 0, 12716240], [0, 1160676260, 0, 0, 0, -263973848, 0, 0], [0, 0, 0, -2300851452, 247711710, 0, 0, 0], [0, 0, -4201366134, 0, 0, 0, 91273622, 0], [-4671529486, 0, 0, 0, 0, 0, 0, -15956824], [0, 604620889, 0, 0, 0, -246647172, 0, 0], [-4646778522, 0, 0, 0, 0, 0, 0, -111467242], [0, 0, 0, 3433488991, 205138362, 0, 0, 0], [0, 0, 0, -1548051202, -341174120, 0, 0, 0], [0, -136122715, 0, 0, 0, 685601262, 0, 0], [-7551354786, 0, 0, 0, 0, 0, 0, 76715816], [0, 0, 0, 1199389863, 660867300, 0, 0, 0], [0, 4372643020, 0, 0, 0, -443122288, 0, 0], [-8912970358, 0, 0, 0, 0, 0, 0, -432045720], [0, 2965862349, 0, 0, 0, 1130299188, 0, 0], [0, -3645340758, 0, 0, 0, 693777780, 0, 0], [0, 0, 10882614902, 0, 0, 0, 129171064, 0], [0, 0, 0, -9839724174, 359728002, 0, 0, 0], [0, 0, 15592389624, 0, 0, 0, 419201298, 0], [0, 6780669039, 0, 0, 0, -1140650262, 0, 0], [0, 0, 0, -3560610485, 625738428, 0, 0, 0], [0, 0, 10677227765, 0, 0, 0, 159188590, 0], [0, 0, 0, -3437188432, -553425740, 0, 0, 0], [0, 0, 21699610104, 0, 0, 0, -739806782, 0], [0, 2042742805, 0, 0, 0, -404844588, 0, 0], [8308903980, 0, 0, 0, 0, 0, 0, 1983391994], [0, 0, 20848659419, 0, 0, 0, 331807348, 0], [0, 0, 33070528416, 0, 0, 0, -594634598, 0], [8929553458, 0, 0, 0, 0, 0, 0, -150187412], [-36374804214, 0, 0, 0, 0, 0, 0, -1331123818], [0, 0, 0, -1615342007, -2025126300, 0, 0, 0], [0, 0, -36626688365, 0, 0, 0, -40783270, 0], [0, 0, 0, 22436283476, 1954763812, 0, 0, 0], [0, 0, 32723746188, 0, 0, 0, 1689813776, 0], [0, 9388608096, 0, 0, 0, 2040949056, 0, 0], [-45339554388, 0, 0, 0, 0, 0, 0, -757112810], [0, 0, 0, 10039111940, 589440228, 0, 0, 0], [0, -10788616250, 0, 0, 0, 5350773542, 0, 0], [0, 0, -15903524610, 0, 0, 0, 1197825300, 0], [0, 25254584397, 0, 0, 0, -372921150, 0, 0], [-26879204460, 0, 0, 0, 0, 0, 0, 3036046504], [0, 0, -53719976609, 0, 0, 0, 1436699942, 0], [0, 0, 0, 27359391856, 480865862, 0, 0, 0], [0, 0, 58289619414, 0, 0, 0, -2404579892, 0], [14284268826, 0, 0, 0, 0, 0, 0, -4466668358], [0, 0, 0, 14914865605, 1791380778, 0, 0, 0], [69826693931, 0, 0, 0, 0, 0, 0, 1494493932], [0, 2769062696, 0, 0, 0, -1014143964, 0, 0], [0, -80933315598, 0, 0, 0, 1387722420, 0, 0], [0, 0, 0, -9382706538, -10297629354, 0, 0, 0], [0, 0, -8763719634, 0, 0, 0, 6520575702, 0], [76507449749, 0, 0, 0, 0, 0, 0, -5240929174], [0, -83448468233, 0, 0, 0, 4656528000, 0, 0], [0, -14645659660, 0, 0, 0, -5246138438, 0, 0], [0, 0, 0, -103322558720, -3361914442, 0, 0, 0], [0, 0, -115023383712, 0, 0, 0, 2782983396, 0], [138048973429, 0, 0, 0, 0, 0, 0, 5626322116], [0, 7358877172, 0, 0, 0, 8863413000, 0, 0], [0, 0, 0, -9125887988, -5003084184, 0, 0, 0], [0, -20776696192, 0, 0, 0, 12779014, 0, 0], [0, 0, 18243347119, 0, 0, 0, 8530710258, 0], [-53962870603, 0, 0, 0, 0, 0, 0, -7494981490], [-40842758364, 0, 0, 0, 0, 0, 0, -6909051988], [0, 0, 0, 170808237420, 478322148, 0, 0, 0], [0, 13705106152, 0, 0, 0, -8921521420, 0, 0], [0, 0, 0, -122659464202, -10346956280, 0, 0, 0], [0, 0, -206924935620, 0, 0, 0, -3496754950, 0], [194728352242, 0, 0, 0, 0, 0, 0, 1268994480], [0, 0, 0, 80962563044, 8761468404, 0, 0, 0], [0, -96023354526, 0, 0, 0, 7202451078, 0, 0], [0, 0, 0, 47790141248, 9940964140, 0, 0, 0], [-141796759166, 0, 0, 0, 0, 0, 0, 7669747336], [22854609330, 0, 0, 0, 0, 0, 0, 2109429154], [0, 0, -10343353489, 0, 0, 0, 2058475512, 0], [0, 0, -230301364002, 0, 0, 0, 13080086506, 0], [0, -43888696447, 0, 0, 0, 7751997834, 0, 0], [0, 0, 0, -38531931900, -11061955032, 0, 0, 0], [0, 0, 80065898834, 0, 0, 0, 11264084188, 0], [0, 0, 0, -186222337620, -9056604972, 0, 0, 0], [23729456854, 0, 0, 0, 0, 0, 0, 20647839496], [0, 2569968713, 0, 0, 0, 6090942624, 0, 0], [279175453488, 0, 0, 0, 0, 0, 0, 15136171068], [0, 0, 93825305413, 0, 0, 0, 7062410396, 0], [0, 0, 0, -50088913712, -10161325570, 0, 0, 0], [0, 229115622455, 0, 0, 0, 7153443582, 0, 0], [0, -84701813240, 0, 0, 0, 18806055992, 0, 0], [0, 0, 461098701180, 0, 0, 0, -2913464310, 0], [-412963418393, 0, 0, 0, 0, 0, 0, -7463252310], [324550296798, 0, 0, 0, 0, 0, 0, -4674765632], [0, 0, 0, 137475490677, -13019307534, 0, 0, 0], [0, -236677541188, 0, 0, 0, -4795151690, 0, 0], [0, 0, 509794762490, 0, 0, 0, -10129982520, 0], [0, 0, 416075690070, 0, 0, 0, 17311665090, 0], [0, 0, 0, -160645188927, -11194287720, 0, 0, 0], [0, -114495218380, 0, 0, 0, -24375668828, 0, 0], [0, 0, -145577534030, 0, 0, 0, -42671500960, 0], [0, 0, 0, 249636092960, 53870086468, 0, 0, 0], [0, 310969049261, 0, 0, 0, 13831383216, 0, 0], [247610384568, 0, 0, 0, 0, 0, 0, 20233671228], [0, 0, 0, -3127537655, 11681062698, 0, 0, 0], [0, 178261356470, 0, 0, 0, -69180672008, 0, 0], [0, 131384571820, 0, 0, 0, -79447561608, 0, 0], [-788650958538, 0, 0, 0, 0, 0, 0, 27199122720], [0, 0, -534799840015, 0, 0, 0, 5922947070, 0], [0, 0, 203925975726, 0, 0, 0, 6887043082, 0], [0, -152019029131, 0, 0, 0, 57607525188, 0, 0], [-150751836114, 0, 0, 0, 0, 0, 0, 11634589172], [0, -112664995462, 0, 0, 0, 103090023634, 0, 0], [0, 0, 0, 50020426836, -53777133108, 0, 0, 0], [0, 773996552212, 0, 0, 0, 7928625960, 0, 0], [-370772734194, 0, 0, 0, 0, 0, 0, -35315961348], [0, -400459939878, 0, 0, 0, -44207840760, 0, 0], [0, 0, 0, -80563234916, -82571137696, 0, 0, 0], [-1260003132223, 0, 0, 0, 0, 0, 0, 3847564190], [0, -223472461332, 0, 0, 0, -111149399616, 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_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_75_9_f_b(: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_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_75_9_f_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_75_f();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,9,sign)));
    Vf := Kernel([<2,R![252047376, 0, 0, 0, 58248, 0, 0, 0, 1]>],Snew);
    return Vf;
end function;