
// Make newform 192.7.g.a in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_192_g();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_192_g_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_7_g_a();".
// 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_7_g_a();".
// 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 := [1, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    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_g();"
function MakeCharacter_192_g()
    N := 192;
    order := 2;
    char_gens := [127, 133, 65];
    v := [1, 2, 2];
    // 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_g_Hecke();"
function MakeCharacter_192_g_Hecke(Kf)
    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 := 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 := 7;
    raw_aps := [[0, 0], [0, -9], [-150, 0], [0, -188], [0, -852], [-3394, 0], [5178, 0], [0, -3932], [0, -2304], [-32142, 0], [0, 18828], [76150, 0], [-70038, 0], [0, 58284], [0, -87528], [-66942, 0], [0, 225492], [257014, 0], [0, -185444], [0, 198096], [243442, 0], [0, 274220], [0, 597012], [-686766, 0], [-942686, 0], [259650, 0], [0, -56564], [0, -545100], [1023374, 0], [-1313934, 0], [0, -73404], [0, -1772004], [-1008678, 0], [0, 349892], [-2395542, 0], [0, -1879084], [2593798, 0], [0, -1716796], [0, -1947912], [-7203270, 0], [0, 1796748], [7016894, 0], [0, -3493056], [-9376606, 0], [-4772046, 0], [0, -3222404], [0, -4192084], [0, 2191284], [0, -8709900], [-5903890, 0], [13059474, 0], [0, 1073472], [-5651342, 0], [0, 16882908], [8193282, 0], [0, 3941208], [-14294958, 0], [0, 11858948], [1920926, 0], [-28892094, 0], [0, 5093172], [-3066846, 0], [0, 30813516], [0, 6431640], [-12650878, 0], [-3497118, 0], [0, 20209364], [39623698, 0], [0, 8648316], [-3409514, 0], [8559954, 0], [0, 14865456], [0, 41724028], [56440486, 0], [0, 22639852], [0, 13418784], [-101265750, 0], [-104856842, 0], [-96850038, 0], [-82302110, 0], [0, -33895212], [73360862, 0], [0, -73096632], [55974962, 0], [0, 9234684], [0, 66529692], [95537466, 0], [-129503774, 0], [105039162, 0], [0, 60296356], [0, -8924028], [0, 7259448], [0, 30331972], [0, 23368404], [0, -110689524], [0, 19194816], [-187406910, 0], [124377642, 0], [0, 96535612], [-9842482, 0], [0, 71820980], [-133942422, 0], [0, 6967188], [35008842, 0], [0, -110717468], [240733394, 0], [0, -211393644], [29153202, 0], [0, 75456144], [-380927662, 0], [0, 176050180], [-63447866, 0], [-33456126, 0], [0, 109687204], [0, -193933900], [-260654214, 0], [0, 215822196], [0, 140530512], [41230602, 0], [0, -57237540], [-385359722, 0], [48023090, 0], [-263635110, 0], [0, -291893316], [0, -45030636], [-466809918, 0], [-177559858, 0], [0, -166118952], [0, 69304212], [205696766, 0], [0, -277450164], [0, 113212008], [0, -103320532], [-254288242, 0], [452852250, 0], [-575007166, 0], [285200466, 0], [0, 117627796], [173957514, 0], [-447671334, 0], [0, -34249716], [38625042, 0], [0, -233140060], [0, -185345244], [69801614, 0], [0, -298333152], [34105366, 0], [596600970, 0], [0, -286942708], [0, -189785184], [737190550, 0], [-1058039550, 0], [0, 55070900], [0, -374660760], [0, -3516452], [0, 680523072], [0, 26069508], [-705122358, 0], [-732052414, 0], [-1640580006, 0], [0, 601053516], [-1016523894, 0], [0, -547400692], [0, 613387068], [-1106710614, 0], [0, 793554024], [0, 361169308], [1208530150, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_192_g_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_192_7_g_a();".
// 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_7_g_a(:prec:=2)
    chi := MakeCharacter_192_g();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 7));
    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_7_g_a();".
// 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_7_g_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_192_g();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,7,sign)));
    Vf := Kernel([<5,R![150, 1]>],Snew);
    return Vf;
end function;