
// Make newform 722.4.a.e in Magma, downloaded from the LMFDB on 29 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_e();".
// 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_e();".
// 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], [3], [-32], [4], [-69], [19], [0], [67], [51], [-132], [-14], [-413], [129], [-617], [383], [-599], [-217], [-225], [701], [1015], [349], [-592], [-1349], [-613], [1235], [1632], [2060], [1055], [1006], [1987], [-1803], [-669], [-2725], [71], [-656], [-1053], [68], [-921], [-1893], [-20], [1839], [2992], [-1393], [-4214], [767], [2365], [-2439], [-1708], [4618], [3219], [-4236], [-2429], [243], [1047], [1905], [-5833], [-3727], [-5294], [1375], [-1307], [3818], [873], [4180], [-3165], [4539], [3660], [-5173], [-8591], [6946], [-8226], [11385], [-2953], [5006], [6764], [-4963], [3623], [-7629], [-9117], [4935], [6516], [10915], [-5509], [-3753], [7813], [-6117], [-7146], [-18118], [16935], [-7788], [12500], [-12105], [296], [3213], [3017], [-7277], [-10693], [-7190], [8647], [4043], [-5389], [6727], [-19908], [-8730], [-4732], [-23882], [-16547], [-15029], [13787], [11382], [-25312], [-23497], [-13221], [15316], [-6049], [-24089], [1633], [14592], [-23430], [4135], [-8285], [23990], [690], [5760], [4348], [-10289], [-30745], [841], [-271], [-8102], [15649], [-10335], [-14669], [-41437], [-34258], [6855], [-29457], [20716], [3722], [11358], [8479], [13371], [-26585], [36603], [31238], [30657], [4443], [-6969], [39319], [9380], [-10249], [-28698], [31779], [3567], [-31079], [32856], [-7736], [30519], [9407], [26815], [17449], [-39873], [-11979], [18201], [37398], [44037], [9829], [39983], [53755], [-23289], [22380], [2383], [-32319], [9022], [36355], [-5529], [-26889], [-52441], [53496], [-9089], [-10793], [-37796], [-52949], [21059], [-47848], [34734], [51155], [22213], [5926], [-28312], [-7341], [46491], [-29156], [30207], [72627], [-68577], [39895], [-73301], [80246], [79224], [-21993], [-38033], [-23841], [43171], [-59451], [-48201], [-54073], [48399], [-33105], [-27496], [-20365], [-24685], [-56700], [66599], [15688], [24795], [10961], [11838], [-3392], [28703], [-42853], [70984], [-60329], [-74455], [-45295], [13127], [-18426], [-35671], [-56187], [-39492], [-54109], [-60533], [5336], [34686], [22800], [56209], [-18226], [60186], [44761], [-5681], [2773], [27604], [39739], [-15945], [50695], [-50272], [-23749], [89127], [-95839], [44187], [36274], [-28665], [-27384], [73519], [79859], [83187], [46299], [7628], [2499], [-28993], [-83777], [58485], [130371], [-5993], [41083], [-41884], [19574], [-55638], [72747], [-131505], [-71134], [-116316], [-99797], [15712], [-90553], [-78163], [-67916], [-35749], [-13213], [36391], [-29628], [145916], [46479], [109098], [141637], [75963], [76478], [-46993], [54997], [-143770], [-41850], [-135208], [491], [93972], [-47573], [-72510], [71959], [-7225], [-135095], [109940], [86467], [19331], [57867], [-42044], [43441], [55], [-107609], [-35233], [168699], [-8078], [173228], [129395], [113727], [-123716], [-41991], [120190], [42863], [-9063], [-121565], [-61522], [-101143], [-15221], [160803], [-111309], [283], [30103], [-159533], [157780], [64737], [154083], [56107], [-137297], [121509], [67932], [-11745], [-127377], [49434], [-212318], [-4986], [142816], [-20873], [6119], [-14061], [113160], [159431], [128745], [59983], [137291], [109221], [-65222], [14983], [-162149], [-168117], [-197784], [55627], [-192066], [-27363], [-46755], [106987], [55731], [-29069], [-197865], [83259], [16256], [-40675], [207471], [-19050], [196097], [-215961], [145747], [12980], [-50063], [71983], [-82923], [93930], [-154379], [53704], [37823], [-45617], [66615], [86586], [212542], [141783], [213743], [43160], [-28383], [-238096], [-272769], [-199121], [-17004], [28575], [220227], [65772], [-84049], [19443], [73471], [9629], [95134], [275189], [-237621], [261515], [-152797], [82552], [-267757], [-58133], [-56671], [-8421], [-89538], [-82801], [-94088], [-93013], [-126317], [-293568], [129200], [168906], [37210], [200151], [118280], [-85333], [215147], [-112869], [251755], [-116816], [135799], [-154202], [138294], [-220692], [-69565], [22252], [180165]];
    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_e();".
// 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_e(: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_e();".
// 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_e( : 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![-3, 1]>],Snew);
    return Vf;
end function;