
// Make newform 192.9.e.f in Magma, downloaded from the LMFDB on 02 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_192_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_192_e_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_192_9_e_f();".
// 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_192_9_e_f();".
// 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 := [14, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 6]];
    Rf_basisdens := [1, 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_192_e();"
function MakeCharacter_192_e()
    N := 192;
    order := 2;
    char_gens := [127, 133, 65];
    v := [2, 2, 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_192_e_Hecke();"
function MakeCharacter_192_e_Hecke( : Kf := false)
    N := 192;
    order := 2;
    char_gens := [127, 133, 65];
    char_values := [[1, 0], [1, 0], [-1, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), 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]];
    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], [45, -3], [0, 10], [1750, 0], [0, 310], [-25730, 0], [0, 3336], [18938, 0], [0, 20956], [0, -20530], [351478, 0], [-1335170, 0], [0, 83540], [-3526150, 0], [0, 181784], [0, 294066], [0, 610910], [-753602, 0], [2268890, 0], [0, -758220], [27672770, 0], [22980982, 0], [0, -2066606], [0, 3234540], [147271010, 0], [0, 4612250], [166063510, 0], [0, -1004634], [109975102, 0], [0, 12817304], [-275993930, 0], [0, 12878330], [0, -9245564], [-142668262, 0], [0, 36491650], [-423860522, 0], [759850750, 0], [668159930, 0], [0, -8744156], [0, -45576634], [0, -57414270], [-471706562, 0], [0, 7206560], [-1588397950, 0], [0, 23954154], [-647586218, 0], [58110362, 0], [-4401996170, 0], [0, 157502506], [1865694142, 0], [0, -121217196], [0, 101319160], [-1746671998, 0], [0, 61269150], [0, -353529664], [0, -14367724], [0, -154705770], [1442163958, 0], [-3380464130, 0], [0, 179181580], [-10425277990, 0], [0, -462926534], [-2993093350, 0], [0, -287231060], [32773730, 0], [0, 524707454], [-12009972838, 0], [15921372770, 0], [0, -220398034], [7295673982, 0], [0, -309076496], [0, -713126460], [-13636439690, 0], [24406208830, 0], [-19839249862, 0], [0, 673198336], [0, 801745610], [23567251390, 0], [0, 613329800], [35847963458, 0], [0, 997759370], [14953485118, 0], [0, 2852728920], [-5229535390, 0], [-43480117418, 0], [0, -1687027586], [0, 1316284800], [-20218143550, 0], [0, -3126182410], [-4160086730, 0], [0, 1283469906], [0, -1991758480], [-57283550570, 0], [0, -3230571610], [-26436786022, 0], [0, -3353360244], [0, 2873877790], [0, -3408232380], [-84677117830, 0], [-143469576002, 0], [164171470010, 0], [0, -6878413626], [0, 6887429474], [0, -5139414980], [-163410272038, 0], [74228236130, 0], [0, -2997230474], [0, -1053206136], [0, -1351319300], [33791119682, 0], [38236640950, 0], [-108066371330, 0], [0, -210485164], [22984541978, 0], [101892049558, 0], [0, 5247377440], [-26267998150, 0], [0, -13831976556], [0, -1551651434], [0, 1679824210], [139618842238, 0], [-129783145630, 0], [0, 15173646074], [0, 4582461414], [358259489402, 0], [0, 11105725950], [388874108542, 0], [0, -1495480920], [-253113063530, 0], [-207602193410, 0], [415014203738, 0], [0, 14730094276], [477977751478, 0], [89506613950, 0], [0, 25455447260], [256194491138, 0], [0, 4477630026], [-215788071430, 0], [0, 29833768654], [0, 4425029460], [-271548692998, 0], [0, -25088137870], [442271505430, 0], [0, 20246935326], [132534653182, 0], [0, -2170184140], [724500894910, 0], [0, -18559602164], [754443310778, 0], [0, 918909936], [-598157593730, 0], [0, 7229667480], [-606459078790, 0], [0, -20753033396], [747110838650, 0], [0, -40136002360], [1146989049622, 0], [0, -19423371920], [198880707170, 0], [0, -57046589690], [0, -60427061054], [0, -22341924996], [-110988400490, 0], [0, -13157277930], [0, -27131048344], [0, 81965583356], [572336197558, 0], [1446142152190, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_192_e_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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