
// Make newform 9.12.a.c in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9_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_9_12_a_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_9_12_a_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 := [-70, 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_9_a();"
function MakeCharacter_9_a()
    N := 9;
    order := 1;
    char_gens := [2];
    v := [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_9_a_Hecke(Kf)
    return MakeCharacter_9_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 := 12;
    raw_aps := [[0, 1], [0, 0], [0, 224], [58100, 0], [0, -3200], [762650, 0], [0, -178752], [-10301704, 0], [0, 207104], [0, -2808800], [106159508, 0], [-9574450, 0], [0, -2161600], [1590697400, 0], [0, -28695296], [0, 20943648], [0, -115091200], [-3092621098, 0], [-9113820400, 0], [0, 66739200], [620142950, 0], [10618486484, 0], [0, 1195288192], [0, -1223376000], [131872902350, 0], [0, 54224800], [79533799100, 0], [0, 3959016192], [-28933749286, 0], [0, 4100248448], [449318207900, 0], [0, 8006835200], [0, -9174962240], [781317642896, 0], [0, -29046263200], [-460586025292, 0], [-417639990250, 0], [566141915000, 0], [0, -16648420096], [0, 44955873760], [0, 25677830400], [1141661801378, 0], [0, -79032608000], [-6131493466750, 0], [0, 6926626848], [4268544723884, 0], [6861321888272, 0], [-11005303962100, 0], [0, -176718190208], [-11389485601774, 0], [0, -184650810240], [0, 409437881600], [12869816285102, 0], [0, -71155190400], [0, 55748999936], [0, -596297271296], [0, -526094402400], [29689656585932, 0], [9535078954850, 0], [0, 775573024000], [-37108671796000, 0], [0, 676331138336], [3853704285200, 0], [0, 1011847692800], [-27812729222950, 0], [0, -522074390240], [-136922823408928, 0], [-52514439443650, 0], [0, 756778418816], [-148523581955434, 0], [0, 2894407255936], [0, -3310534348800], [164227881391700, 0], [149639898398750, 0], [7846456919096, 0], [0, -1120030218496], [0, 4744632200800], [-10118549477050, 0], [0, 6244543572800], [92525815403126, 0], [0, -4717075753600], [-405553801060462, 0], [0, 9690068332800], [185422052670050, 0], [501756559736684, 0], [0, -2674678068608], [0, 12935529643200], [-464508367447450, 0], [0, -3984104650400], [271686117787100, 0], [0, -16074833760384], [0, 5918106342400], [-96745568789500, 0], [0, -9021440051200], [284706871730144, 0], [0, -9174330923520], [0, -21508499740000], [0, 161579208000], [-1005427206032200, 0], [881900646294602, 0], [-1798718806931800, 0], [0, -28235491134240], [0, 28388241746816], [0, -29011076331200], [-1564792264329328, 0], [910933722218450, 0], [0, 5285486574592], [0, 49927123870848], [0, -69306076806400], [1810567202859338, 0], [-1641168272592100, 0], [-647249524112050, 0], [0, 3205549398272], [1163380512376544, 0], [2129850706971332, 0], [0, 46557706494400], [-4930571336282200, 0], [0, -40011144203520], [0, 19464507819872], [0, 20392035980800], [-1858893400812322, 0], [1226327667019250, 0], [0, 57975372624736], [0, -23809570041984], [-223558598534152, 0], [0, -25300026338400], [3539978955324626, 0], [0, 126796686374400], [8818563183628100, 0], [1757326016206250, 0], [-3768007494629104, 0], [0, -53486814411520], [3280919697200708, 0], [-11537940295376350, 0], [0, 103428863518400], [-8285288617486846, 0], [0, 22564310905248], [-2834076626227000, 0], [0, 86075401496672], [0, 82015411377600], [-1047601220904952, 0], [0, -149307734444000], [6222298737140900, 0], [0, 175997363894016], [8475659146147466, 0], [0, -352187618048000], [14101013781607550, 0], [0, 287642857897024], [1930318309662344, 0], [0, 265201206324480], [-21953906552496250, 0], [0, -419212194643200], [26365128887300600, 0], [0, -405328893200896], [-25795161576059800, 0], [0, -500365865388800], [-24951410513140444, 0], [0, 29465993300800], [22588075585721450, 0], [0, 360993468264800], [0, 820981188635392], [0, 673753525737024], [-29080188393372100, 0], [0, -584130401769600], [0, -831497004079552], [0, -190374493148672], [-2903562026226268, 0], [-3748871297110450, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9_12_a_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_9_12_a_c(:prec:=2)
    chi := MakeCharacter_9_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 12));
    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_9_12_a_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_9_12_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([<2,R![-2520, 0, 1]>],Snew);
    return Vf;
end function;