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


// To make the character of type GrpDrchElt, type "MakeCharacter_722_a();"
function MakeCharacter_722_a()
    N := 722;
    order := 1;
    char_gens := [363];
    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_722_a_Hecke(Kf)
    return MakeCharacter_722_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 := 4;
    raw_aps := [[2], [-5], [-12], [8], [9], [26], [114], [0], [-78], [-204], [98], [-334], [177], [-316], [-492], [678], [-579], [-352], [755], [6], [-145], [-316], [-567], [-114], [-943], [-1500], [-658], [-1440], [1280], [-369], [902], [-453], [2001], [-2935], [6], [2774], [-2728], [-1657], [2784], [2382], [-3645], [-1906], [1332], [1322], [3726], [-478], [-820], [926], [4977], [-4312], [-1821], [324], [341], [4863], [-3453], [-120], [-7068], [1388], [-5164], [-645], [6743], [-252], [-7117], [4410], [6725], [-4866], [2375], [-10333], [5109], [-2044], [-1701], [1770], [-10558], [-124], [44], [9312], [-11292], [-334], [5613], [-3355], [5796], [650], [4206], [-13078], [-2602], [7923], [2529], [7037], [-11730], [11762], [-3465], [-4020], [18146], [18528], [-16003], [13998], [-11328], [-1575], [-21268], [7748], [13796], [15672], [-12663], [-14670], [4643], [-18277], [-12612], [-23109], [-78], [21707], [728], [9218], [-27861], [23156], [25136], [10401], [-11737], [-23058], [-22860], [2820], [-11860], [-31330], [-4410], [-180], [-27412], [25836], [14930], [4146], [-18856], [17318], [-25831], [510], [-694], [4598], [32697], [-4510], [-3012], [12131], [8442], [-8307], [-16], [-22254], [-39670], [15483], [27188], [1752], [-16462], [22101], [43559], [15570], [-10144], [40887], [12599], [49152], [-8989], [26406], [43514], [28149], [35747], [12990], [11724], [25017], [-25894], [36591], [-24687], [-25968], [18584], [-48232], [59870], [28866], [16515], [21338], [5046], [-38953], [26990], [20991], [-43219], [-5916], [-2044], [-31834], [43742], [-13356], [4976], [19959], [63072], [37044], [-70540], [-15832], [12161], [-5922], [-18181], [-10284], [-55711], [-68808], [-4173], [50538], [67115], [19844], [14931], [-16506], [30162], [79112], [68714], [-42229], [57759], [-62106], [-33658], [35769], [35475], [-59941], [-31375], [52050], [75140], [50979], [-14742], [-1990], [36686], [39438], [55638], [-67782], [-27658], [-406], [59541], [-26020], [-58035], [84482], [-68481], [83544], [74468], [-44532], [-6364], [-25993], [1766], [891], [-17395], [-69186], [46529], [18846], [63951], [-38166], [67353], [-36421], [-70156], [57770], [27330], [-36162], [5276], [30567], [-96769], [6852], [13904], [46230], [-55494], [-22381], [-6186], [-25908], [-101746], [36953], [-37686], [-8038], [-111322], [-25635], [30536], [57752], [-32307], [-119539], [-106776], [42147], [-72388], [43770], [-82054], [41204], [-36097], [-33388], [-39538], [-94078], [66159], [32696], [-78373], [-37284], [-378], [100046], [-104316], [-46522], [127892], [81948], [-137107], [-75048], [-2728], [-90090], [87390], [-42588], [-74229], [-82908], [12032], [-29610], [-27106], [31740], [36780], [-69265], [-90403], [110886], [132992], [54441], [-145279], [61865], [58701], [56852], [19704], [-97228], [-100422], [-48630], [-77883], [-27991], [-170346], [-40390], [-71997], [129282], [-133345], [-110682], [-101953], [124109], [56838], [109556], [-108942], [-34102], [-31753], [120995], [68802], [169518], [27782], [21048], [169724], [-100548], [170435], [67548], [-70516], [-159453], [-36946], [123326], [-173608], [2589], [-144006], [-176020], [67206], [7755], [-155752], [29756], [-90354], [131418], [-182107], [-65899], [-8142], [71246], [-119428], [94059], [-4548], [-124185], [84657], [-136914], [141266], [11415], [-40776], [-208269], [21800], [-13714], [74340], [230642], [101429], [1497], [252980], [-123348], [79638], [78542], [58760], [-26724], [-94176], [28523], [-18447], [18125], [-186984], [-151758], [-2122], [144843], [-9415], [-58728], [-47836], [-128014], [237719], [-76734], [101555], [-32898], [242937], [-141409], [-25152], [92441], [-182656], [175329], [112769], [77874], [265130], [-110307], [144272], [33378], [270912], [17054], [-208216], [85437], [44084], [121527], [-103213], [-129732], [-234603], [56555], [-80449], [68670], [-116124], [79940], [-74958], [277212], [-26454], [9980], [-167886], [52239], [-4942], [-27216], [151083], [-286770], [-183988], [-23070]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_722_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_722_4_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_722_4_a_c(:prec:=1)
    chi := MakeCharacter_722_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_722_4_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_722_4_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_722_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![5, 1]>,<5,R![12, 1]>],Snew);
    return Vf;
end function;