
// Make newform 294.6.a.d in Magma, downloaded from the LMFDB on 06 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_294_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_294_6_a_d();".
// 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_294_6_a_d();".
// 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_294_a();"
function MakeCharacter_294_a()
    N := 294;
    order := 1;
    char_gens := [197, 199];
    v := [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_294_a_Hecke(Kf)
    return MakeCharacter_294_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 := [[-4], [-9], [86], [0], [34], [-3], [-1904], [-1489], [-224], [-6508], [1731], [-7633], [15414], [18491], [18462], [-19956], [-31828], [-57654], [-60563], [-44834], [20821], [-30531], [110602], [-58992], [-119846], [100010], [121691], [-48648], [-152075], [-60886], [-151965], [235502], [325508], [3211], [-151884], [76648], [-389710], [-112372], [52550], [-135256], [250638], [199233], [-238770], [85691], [-71408], [-711352], [-260260], [105656], [654750], [557713], [-1247594], [-496926], [-277618], [-308328], [408762], [1088124], [-668290], [-830664], [925073], [1336348], [-992957], [563544], [2827033], [-1127314], [-2360129], [-2224200], [-3703039], [1214325], [-977904], [511282], [3027522], [4594556], [-1112731], [-2458949], [-4101299], [-2594132], [2234066], [-2063997], [1152828], [5934125], [771666], [-2875419], [-137862], [1565255], [4881576], [-1301516], [-3131410], [6492685], [5347172], [3372853], [2234522], [-2521364], [1916717], [5828748], [-10004861], [1136658], [4019370], [-5520276], [8944721], [849057], [8613396], [7798790], [1072714], [-1015242], [-6780933], [-3305369], [-11983328], [-5310198], [2422356], [-7106593], [17919405], [13979010], [-5255942], [1443013], [15172304], [-144848], [-27469], [8557830], [12503034], [18047068], [3341443], [-8470657], [14655276], [19761612], [13583237], [-12991504], [1908734], [-11119974], [8374057], [4644477], [-11062329], [1972446], [15024639], [-4724262], [-8578352], [17616751], [-1254202], [7091208], [-2716296], [-21873922], [-17235248], [-22619126], [1626328], [-22830450], [25859317], [-12306116], [-19141609], [-4755072], [-9198760], [-17353186], [-35562182], [-26305560], [12039437], [-133590], [-12747579], [24325272], [-38480459], [39667806], [14842751], [46706300], [40237946], [24557884], [53431265], [-2814852], [25471278], [-2901348], [2737835], [-27407905], [-53371339], [-21443136], [50365520], [-13135778], [18990228], [36235461], [-14870721], [33001760], [-6839523], [-10379150], [-61834960], [-46402957], [49084623], [-42891824], [-34827827], [29296388], [15035486], [-17690868], [-76338162], [-8609431], [40488249], [42793230], [-7974143], [74601462], [-59833400], [28437916], [-47433732], [52740376], [36842555], [72437326], [-51595518], [-35241948], [-87231690], [-50375907], [-104537482], [-70710510], [-42717030], [-42778158], [12371024], [31401066], [-96117060], [37952828], [-36629497], [99056456], [59721780], [20358860], [873924], [-83338081], [-41717792], [37065532], [23704900], [105756394], [46171441], [18774679], [91851234], [35635336], [-44291442], [-67179526], [14642824], [-107896714], [-9876843], [-120414522], [64297689], [27612652], [-5208203], [111720894], [94368815], [96863766], [150116533], [26379630], [-38626836], [-95918338], [124319170], [24370367], [-166643809], [-130676322], [111929176], [-140415756], [-17786751], [37083934], [-80252248], [-21618216], [-12605255], [51264072], [-87681954], [135199573], [-199064192], [177051736], [23460197], [-178418031], [-167431702], [33600878], [-75997079], [7816184], [205856569], [99482479], [106239726], [-66180065], [37403250], [-85276438], [-11602532], [81545262], [104587575], [-35399068], [62132709], [-106135843], [-91239062], [164761668], [-156157370], [95720859], [207110083], [-230958696], [61696680], [46642389], [-240224346], [-167778253], [-71730180], [-26117726], [112860201], [496270], [-274790425], [-31468446], [-139152060], [-159961500], [283926534], [31056932], [-67872361], [36782358], [271337243], [-4416300], [-267429726], [45809649], [-167559986], [-292625982], [295625932], [20915412], [-238106749], [-153718459], [65402870], [-42905707], [-260516288], [357215159], [-224136804], [148969202], [75442586], [-376240192], [352821272], [-201992167], [107731638], [-215211712], [-58193839], [-267916134], [126195995], [86581927], [-311362434], [31886461], [-79219114], [-272569639], [-154810471], [-209332469], [-301998380], [-386985482], [-285816859], [144575206], [353073171], [-334053266], [-29020067], [-331147210], [42534330], [-110943748], [-246402043], [-251859329], [196868795], [133561728], [-214196784], [252942207], [-420377082], [-166642950], [-52376395], [225656156], [-76421094], [203400978], [428799716], [356889002], [-176217846], [90034152], [26509387], [206999842], [-101749990], [-442533876], [126171184], [55869442], [-353950790], [95070502], [-21417862], [205601038], [276872911], [252835814], [399450744], [348429291], [-375313778], [-17502020], [-176470997], [541303422], [204239870], [-305691539], [-408602531], [476624856], [-167641448], [-442599746], [245570068], [-272254135], [445786080], [517389980], [31174288], [-63924084], [406363348], [-350587636], [148022645], [448361614], [-87859571], [-343390238], [-470373175], [-630415314], [264613660], [609818441], [-618523762], [-125972262], [425195236], [-147703262], [398118465], [-365622050], [184320062], [-41343684], [97828120], [-528082342], [487384842], [-133598245], [-458559026], [481730388], [-88624693], [142250740], [263752402], [-546201572], [-475485008], [443337180], [179091353], [770435602], [495899782], [176713915], [573547308], [-473310352], [-762436664], [35263883], [-689013368], [-401880306], [439196534], [851833274], [-491550202], [-235816008], [-84951684], [38174776]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_294_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_294_6_a_d();".
// 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_294_6_a_d(:prec:=1)
    chi := MakeCharacter_294_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_294_6_a_d();".
// 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_294_6_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_294_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![-86, 1]>,<11,R![-34, 1]>],Snew);
    return Vf;
end function;