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


// To make the character of type GrpDrchElt, type "MakeCharacter_704_a();"
function MakeCharacter_704_a()
    N := 704;
    order := 1;
    char_gens := [639, 133, 321];
    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_704_a_Hecke(Kf)
    return MakeCharacter_704_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], [-29], [31], [230], [121], [-112], [-1142], [-612], [1941], [-1192], [1037], [-8083], [-10444], [58], [-8656], [20318], [-21351], [-47044], [48093], [24967], [-42288], [72410], [-15806], [-114761], [-5159], [61426], [-185896], [-23970], [56326], [-261903], [-87404], [265122], [245857], [-363594], [55750], [-65642], [275367], [291940], [337344], [116742], [-19107], [16177], [-685333], [-309292], [120930], [-915536], [-134580], [-468839], [275022], [642281], [-1504848], [304694], [1271808], [629965], [544086], [1989334], [-1754458], [1658240], [42634], [319510], [-2027348], [-718844], [-1981420], [1510300], [2000919], [259331], [51203], [266870], [622800], [-2436490], [1559571], [-1919608], [-3612251], [-3939682], [-2188289], [-768387], [-324313], [-334758], [-902022], [-5004574], [-3001236], [-4562238], [-4897826], [6728757], [3350336], [-7124343], [-2709285], [2413612], [6560652], [4724207], [-2284439], [-951544], [-3514843], [-5787192], [1029124], [727370], [1946297], [-10313283], [-6868396], [-10054476], [9857248], [14589166], [-10241316], [-751816], [-7018540], [-3363767], [14058548], [-5394196], [12020376], [1646358], [-4884506], [-3490112], [9120722], [14663515], [16387005], [-3268353], [8328425], [-2496941], [789105], [-8313926], [4335171], [7293134], [-15581402], [-2169304], [-13219475], [25939506], [-3575311], [1958141], [-15535975], [14600204], [-20668246], [-11706452], [12760715], [14086854], [23382160], [-10957520], [-16933594], [-7516552], [-3937885], [-17360900], [27085002], [-35938390], [505509], [-29995488], [-29694153], [14137137], [4685394], [-41284552], [-3548051], [30760536], [-30553528], [42101773], [57164], [11610630], [20985492], [-47412500], [-40432586], [33075690], [-31513244], [9541470], [22420753], [16898478], [30694648], [33566411], [24789677], [-5226059], [-24082600], [13260598], [-31350226], [6729761], [3452046], [-39349702], [34022508], [57281052], [8788879], [8020761], [-61850570], [-53042979], [-47310284], [-25851564], [-20898904], [33834990], [30263427], [10130446], [35676967], [56898486], [20117780], [-42902896], [41165654], [32551254], [5972089], [58449806], [-21313679], [-53582190], [-13394000], [-43835261], [37437550], [-5292047], [32405310], [-27172786], [8740456], [51793266], [63685422], [-53932208], [-43636285], [-42812657], [-44450669], [113692612], [75295656], [43098992], [-2737072], [-21383691], [-9505379], [-94548940], [81676050], [-48288145], [-58510952], [-8705292], [71803552], [46976865], [-107978288], [-80459400], [-79696591], [12905727], [-5176192], [125943662], [-6801994], [94421688], [-19943760], [-72160608], [33689863], [71701216], [130306202], [-8271960], [-57148483], [37423534], [-64813591], [2144872], [145074939], [51966327], [77925795], [-61241008], [86568700], [-127498705], [82600616], [42528244], [170357852], [-47721948], [191563130], [155852142], [-112060160], [57061190], [34271507], [-87112354], [-56104446], [6305220], [-103442902], [27086282], [24741759], [-53299886], [103316756], [183499388], [65537466], [-44272886], [-105428562], [-64068336], [-204822627], [-13565475], [85314322], [215647198], [95633415], [108490595], [-1833798], [-193968332], [52053708], [165615033], [68242683], [-2969186], [-73225672], [-221073352], [135706012], [111701559], [-49345800], [-121975238], [129858852], [-58975257], [-148746630], [-139915078], [-4355049], [96045306], [-2898045], [-82039756], [106919692], [243720218], [-116515170], [258242580], [12746555], [181769889], [-328859590], [134504426], [-133716726], [193218300], [-122439012], [120611556], [116569815], [-109252505], [30202539], [-87315725], [86028588], [-154247784], [82684192], [54175930], [-108152018], [-225552499], [-156052080], [-61525262], [92568287], [-18426138], [-147456526], [-18001464], [-247573320], [-322855255], [-112934738], [295661511], [-317900706], [-97345741], [-41430993], [-360114989], [228829204], [-90288564], [-2740806], [103550682], [313256258], [-52296000], [-281421704], [259724409], [-240765345], [-90898188], [116459791], [274359382], [-430689101], [492497063], [-202836872], [-420501167], [-55448811], [385667522], [247439333], [280461991], [-343257740], [294193217], [28314136], [-256257117], [-445176510], [232747236], [-84115666], [-186524674], [224746791], [81796070], [349040130], [-507204917], [319183842], [11239246], [-352489959], [354273330], [135015327], [-340560411], [334244708], [47109010], [-514313028], [-262749099], [-215625560], [227505546], [355277648], [-219965318], [441363211], [-569134980], [-521417234], [177545710], [341795178], [100703134], [-168520974], [316479935], [-494743258], [587892770], [436185960], [649208589], [-346494480], [15808479], [349166732], [399963613], [356646677], [561872769], [129286629], [-63116077], [-347712363], [-621945020], [-567370670], [229747126], [449636084], [-580187478], [-263514766], [587814897], [413077072], [13733934], [-291075924], [91000346], [371283210], [-294880640], [512828812], [-546099109], [238293458], [824009594], [-182641996], [296061582], [-425864766], [843738647], [68628240], [-371378587], [259085078], [-420420662], [-595272527], [-203451616], [-103767456], [-215368902], [-119903574], [-710347819], [235542739], [101567706], [364422239], [-433754320]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_704_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_704_6_a_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_704_6_a_a(:prec:=1)
    chi := MakeCharacter_704_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_704_6_a_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_704_6_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_704_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![29, 1]>],Snew);
    return Vf;
end function;