
// Make newform 192.6.a.k in Magma, downloaded from the LMFDB on 17 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_192_a();"
// 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_6_a_k();".
// 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_6_a_k();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_192_a();"
function MakeCharacter_192_a()
    N := 192;
    order := 1;
    char_gens := [127, 133, 65];
    v := [1, 1, 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;

function MakeCharacter_192_a_Hecke(Kf)
    return MakeCharacter_192_a();
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 := 6;
    raw_aps := [[0], [9], [-26], [-36], [180], [-318], [-566], [1260], [-4176], [182], [-9612], [1874], [13394], [-5868], [-14328], [-3730], [-38052], [39370], [-65052], [18432], [-50790], [-1836], [-63108], [86474], [-118062], [-17666], [15156], [145404], [136914], [131234], [-79236], [146340], [259906], [359820], [304790], [283212], [-478342], [-195444], [595512], [335086], [-415404], [-431478], [-55872], [469522], [638254], [507204], [-792972], [-908532], [-937188], [-439638], [534778], [-1582560], [763986], [609444], [-538622], [-597096], [1868902], [-1865412], [111978], [364250], [817596], [-1513666], [-1499436], [590328], [-28822], [-1899770], [237852], [-1812798], [-759420], [1022314], [1180754], [2596320], [3360708], [5018194], [1881684], [1193184], [-5683834], [2771386], [-4382342], [-965622], [4771260], [2031258], [-3001896], [4202098], [-7017084], [1517796], [-6241702], [-693222], [-6023890], [-4227300], [-81684], [-1294200], [141084], [-4425444], [4832532], [-9011664], [1645382], [-3709454], [-5295132], [-5611038], [-10202436], [10856798], [-3718404], [12691042], [-6418260], [6334994], [-16180452], [-15978494], [-15434784], [645034], [13220028], [1307842], [1257866], [5222124], [-11318292], [4394650], [8520444], [15008256], [14147710], [18911844], [-9388414], [-2669566], [-20705066], [14970564], [14806620], [22474118], [13099530], [-7205112], [5131980], [2037042], [27355284], [7025544], [-7537644], [11259738], [12478418], [-17454286], [16839854], [-26068068], [21340750], [-1935070], [-13446540], [-24138626], [-31242564], [-32960340], [3997890], [30573936], [13748450], [34966274], [25639092], [-20963808], [-20447558], [-19489262], [-31798980], [-14181912], [8453124], [-35024544], [-29900196], [3421546], [-5945078], [26552750], [-12357036], [-37293086], [29341044], [30906180], [-13909606], [-28303704], [-53286300], [30350722], [39255042], [-35179418], [65516364], [-39697030], [33825960], [64302378], [4542372], [-34568422], [2709180], [36300422], [56032596], [4164170], [33290532], [-31207860], [-68764854], [-19915510], [-48293424], [-27228506], [29377938], [-45471132], [-50944086], [36019584], [1294818], [-45975924], [11434356], [-53746450], [16255620], [-47214326], [19272194], [37785906], [-11759038], [-14803128], [19259758], [14202396], [1655946], [28838802], [30034980], [-37735610], [3447900], [9829548], [20587258], [-67122108], [-52223614], [4473382], [-117110268], [56552796], [35219664], [32491786], [-99922284], [-27174742], [-108588600], [-105645986], [-105695142], [65256228], [120947818], [3285756], [8478972], [94806914], [-27244502], [53780616], [-71728668], [-89505252], [-65481582], [-44280756], [49587660], [-59129558], [-143816508], [21390264], [-141802014], [40455446], [-74985516], [68826528], [24158844], [-27170676], [-19525572], [-73140118], [92544946], [117268416], [37254996], [-32878476], [97611516], [41247648], [-43156734], [111560626], [-178858080], [113565066], [106838854], [164783268], [-127112502], [14902092], [3962414], [2987098], [-111936708], [160595748], [-187784646], [31968794], [38013482], [155303892], [-128431106], [-174016022], [-152122716], [131481638], [-170960678], [231455268], [134058618], [167542308], [-229205838], [28766916], [104972436], [82455466], [140547098], [-35437212], [-32538744], [-167042412], [163992096], [-210314750], [7580628], [-42704352], [120316434], [-247855930], [241591788], [171967058], [53010910], [-248201100], [41829962], [-33100596], [148041770], [-145006690], [-14590692], [-20239634], [-37246860], [64714860], [-251851238], [-324746050], [-10951740], [-173091564], [193067460], [-291270078], [196024788], [-28686078], [264964032], [-60168926], [-108195984], [-344738930], [-185980390], [-128962116], [-218229048], [-225966870], [18324900], [-223181064], [28060530], [195852994], [-38111148], [-166771862], [-332505034], [-240545484], [-126986606], [229304802], [128713500], [398177316], [-29745504], [90723622], [-180664974], [-246969698], [-20329236], [-177373836], [71963820], [332126676], [294106970], [228900370], [153606042], [445128300], [81845186], [-41657086], [391986526], [-161433468], [-13395514], [-347663988], [-273071670], [-94883652], [239389416], [-430978498], [202994028], [-20018022], [90508438], [182141388], [-186231070], [263264410], [-31940208], [70844796], [-405608150], [-157899816], [-114475630], [84455546], [-114181200], [239396436], [-83376108], [30742970], [319582502], [-465701652], [-35500390], [-157306788], [80333316], [82894320], [-217572466], [-141082452], [-274286958], [600486300], [-602136864], [18759202], [139234522], [68131866], [532889662], [42212066], [-151093620], [48952546], [246443004], [-702561960], [-74918700], [262479498], [-295419204], [132040008], [-418421406], [80473270], [-680816340], [506844108], [9930456], [-40090134], [-242022852], [639430706], [-267553404], [-179444138], [124079050], [248789066], [470400300], [476709602], [493571294], [528277644], [263486802], [248698330], [-57971124], [529575084], [-660041374], [-693194938], [349284708], [-226154196], [-385272294], [666774278], [247691520], [-133529652], [-487655206], [734177952], [-113686786], [891594866], [227738880], [-259215084], [-842909798], [249408806], [387058860], [785721322], [700706196], [-706662576]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_192_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_192_6_a_k();".
// 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_6_a_k(:prec:=1)
    chi := MakeCharacter_192_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_6_a_k();".
// 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_6_a_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_192_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![26, 1]>,<7,R![36, 1]>],Snew);
    return Vf;
end function;