
// Make newform 784.6.a.l in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_784_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_784_6_a_l();".
// 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_784_6_a_l();".
// 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_784_a();"
function MakeCharacter_784_a()
    N := 784;
    order := 1;
    char_gens := [687, 197, 689];
    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_784_a_Hecke(Kf)
    return MakeCharacter_784_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], [20], [74], [0], [-124], [-478], [1198], [3044], [-184], [-3282], [-5728], [10326], [8886], [9188], [23664], [11686], [16876], [18482], [15532], [31960], [4886], [-44560], [67364], [-71994], [-48866], [-51606], [180424], [65700], [-112706], [-23502], [94592], [70292], [277290], [-130308], [-401530], [75976], [394322], [11724], [-551928], [-432894], [-559620], [-604710], [409152], [540866], [-629898], [283048], [-142756], [889696], [1143156], [695786], [-347126], [1642960], [1167438], [-790612], [129790], [-70888], [-1790174], [-1773616], [-275450], [594170], [1092428], [-333654], [1059972], [-1336488], [-1644186], [-1723698], [-2749628], [-3414894], [-730764], [2297490], [1170718], [-3886536], [933040], [-392218], [4729300], [1897344], [-3722954], [-3338078], [4274898], [2573190], [5268276], [-973354], [-3557360], [1954958], [-3296808], [5058196], [2127298], [289130], [-2668702], [-7586192], [-1419612], [-1884064], [6013880], [-4292316], [-1345092], [202008], [-9783438], [10483030], [6210172], [5080878], [-3346868], [7003774], [-12981884], [1899418], [1662996], [-8773442], [5183932], [-8498578], [-11247096], [3464390], [-999712], [9813398], [-5347446], [-6827684], [3609704], [-13385342], [-9911148], [-17835928], [-4323234], [-19785828], [-15777158], [6787618], [14994218], [-11558044], [-220156], [4789326], [4268918], [-16195952], [6534264], [-13161710], [14234764], [21583544], [-18659376], [-2566810], [25958566], [-5532674], [-8329398], [-13652252], [8546258], [7584842], [6184732], [-2781018], [-16389464], [-22951148], [3501362], [5296680], [20294842], [4827846], [-13021044], [39238688], [13462206], [917710], [-24548804], [-16146280], [20336132], [-10772560], [-41856568], [-29984546], [-14240202], [41454594], [15407868], [-20632806], [-11872424], [1532220], [17432082], [2232696], [-22250080], [-53266198], [-9449806], [-31254118], [16618836], [-8923278], [-51964904], [-48319574], [47597264], [39178246], [10906036], [-53639082], [-47251064], [4817794], [50231488], [57498452], [-19838730], [-28130538], [3458544], [51489210], [-61224338], [46108404], [41517706], [49314432], [56821118], [33163524], [-65545828], [35948114], [86632908], [-65043146], [13670770], [-81245618], [91682878], [-68948568], [-21824098], [-39135088], [-25562822], [-64028770], [-23772708], [42054258], [94486784], [-13854996], [-18920278], [-66580100], [85148754], [-110651910], [36763208], [38512460], [-85758328], [13478326], [-89036144], [115278446], [-73901304], [20183406], [4487318], [11879064], [100450434], [115723696], [130132836], [-48394618], [-71662458], [-16017696], [-95843064], [56058980], [28060158], [-58775804], [8840512], [-154856342], [28392252], [63395216], [-165773330], [74975686], [-71990540], [90996808], [-89041476], [-110781268], [172738024], [131124190], [-4594770], [-142350664], [-48392288], [-22757964], [34917860], [-54739568], [-103211058], [-13861698], [53796568], [-29641450], [39726306], [90981084], [-64808890], [183127948], [39431274], [-80347354], [102181760], [93291372], [179767754], [-184588206], [100483550], [-367564], [18873086], [-98880794], [56840596], [138816374], [45232226], [102815836], [38660678], [-88873312], [211304270], [71353880], [219244116], [-95772274], [46077610], [179017444], [9557152], [-219488392], [263721304], [-60149750], [-46059844], [290455280], [-24854638], [260984646], [-12359944], [178663198], [-128862530], [119947716], [-212334374], [-202626564], [196403550], [-79997614], [4049696], [25097946], [-43722900], [293262548], [139976854], [-124087138], [268302448], [260497244], [-149604108], [112426082], [65425188], [97412290], [19252456], [23736758], [79129296], [136780038], [92511650], [-38979508], [106629752], [351719350], [-170304636], [-240331584], [-364398914], [150170514], [293187364], [-250532294], [60287890], [-261844192], [-289407350], [66892494], [-55551636], [-343470900], [121305056], [-364972842], [-100272386], [273008718], [-237211200], [-142448172], [-327074364], [-411162612], [9829102], [-80300130], [-239736842], [230161968], [348913510], [22013274], [274723146], [-471379176], [19087918], [-61720756], [-396790614], [-335867164], [-110139024], [-112015526], [191640660], [432547562], [301081630], [-72797424], [-221606074], [223866310], [-202606112], [442552412], [293886514], [28201320], [-97325770], [353340630], [-28802640], [-241614284], [-291172556], [228443082], [560548866], [50897240], [-437627462], [26832268], [-133502244], [-412818224], [339652198], [-504296168], [-541934962], [478755300], [-201993120], [537498974], [-517875186], [-476085146], [-191578062], [31650794], [-168103416], [158346210], [-505850636], [-838968], [-157618608], [-357178598], [-116167468], [344971392], [580380802], [620317130], [435480324], [29610084], [693153480], [579279226], [-272987616], [673580598], [322321252], [-157141466], [327459250], [228995778], [113695088], [-354681530], [293885930], [656652616], [127847998], [405649842], [-145458364], [641303316], [-143152466], [614691334], [-597958988], [592340300], [-324945078], [-434490238], [115801536], [-427625944], [-87341970], [-513314056], [74891630], [-84058262], [246440272], [648689708], [-474417706], [-385163102], [-393826660], [-863864454], [-244868148], [14406616]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_784_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_784_6_a_l();".
// 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_784_6_a_l(:prec:=1)
    chi := MakeCharacter_784_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_784_6_a_l();".
// 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_784_6_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_784_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![-20, 1]>],Snew);
    return Vf;
end function;