
// Make newform 576.4.a.m in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_576_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_576_4_a_m();".
// 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_576_4_a_m();".
// 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_576_a();"
function MakeCharacter_576_a()
    N := 576;
    order := 1;
    char_gens := [127, 325, 65];
    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_576_a_Hecke(Kf)
    return MakeCharacter_576_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 := [[0], [0], [0], [20], [0], [70], [0], [-56], [0], [0], [308], [-110], [0], [520], [0], [0], [0], [-182], [880], [0], [1190], [884], [0], [0], [-1330], [0], [1820], [0], [646], [0], [380], [0], [0], [-2576], [0], [1748], [3850], [3400], [0], [0], [0], [-3458], [0], [-1150], [0], [-5236], [-6032], [-3220], [0], [-4466], [0], [0], [-7378], [0], [0], [0], [0], [812], [4030], [0], [-5600], [0], [-10640], [0], [10010], [0], [-992], [-4930], [0], [11914], [0], [0], [4340], [-12350], [8584], [0], [0], [-1190], [0], [8246], [0], [-17138], [0], [-2590], [14924], [0], [0], [12710], [0], [-19780], [0], [0], [20900], [0], [15136], [0], [0], [0], [12040], [22678], [-1640], [0], [0], [0], [-23312], [-17710], [0], [0], [0], [-29302], [-28420], [-17390], [0], [26656], [1892], [0], [-13160], [0], [0], [0], [20482], [24050], [0], [0], [16072], [0], [-36146], [0], [-10780], [-15050], [-31376], [0], [-23452], [41470], [0], [-4606], [0], [-43400], [0], [0], [-39368], [0], [-12220], [0], [-17066], [0], [46690], [0], [-31304], [0], [-50150], [0], [20680], [0], [-44840], [0], [2756], [0], [-55510], [0], [0], [0], [-50020], [0], [0], [0], [-45628], [-28910], [50654], [0], [0], [40138], [0], [-15370], [21476], [0], [60352], [0], [67340], [-39494], [12980], [0], [-61490], [0], [0], [0], [-56810], [75040], [-73834], [0], [23870], [0], [37312], [0], [0], [0], [-7198], [56950], [0], [0], [0], [63308], [83230], [-49714], [0], [0], [85484], [0], [0], [41272], [81650], [0], [48620], [0], [0], [76538], [15860], [0], [0], [0], [-98642], [29036], [0], [-77380], [0], [-53534], [0], [0], [-109060], [0], [8710], [69496], [-103588], [0], [-113960], [0], [112574], [0], [0], [0], [0], [-31808], [100100], [49786], [0], [0], [-121660], [0], [118816], [0], [114550], [0], [0], [84854], [0], [0], [108862], [-121520], [0], [4970], [-24820], [0], [-34706], [134890], [0], [-64064], [0], [0], [-142760], [0], [-138278], [-92720], [51590], [133796], [-71890], [127820], [0], [111274], [5402], [0], [0], [-59092], [0], [-155918], [138040], [0], [-90610], [0], [22484], [0], [0], [0], [0], [0], [121210], [0], [5852], [0], [0], [-174440], [75530], [0], [171236], [0], [150568], [166430], [0], [12166], [0], [-60590], [0], [0], [0], [131560], [0], [-183274], [0], [0], [-31570], [0], [171808], [-69190], [0], [187220], [0], [-163618], [106216], [52360], [0], [0], [204262], [0], [-142324], [0], [-103952], [0], [-6806], [0], [47558], [-129220], [-203870], [0], [0], [87932], [0], [0], [114478], [-188480], [0], [0], [222712], [70310], [0], [178220], [217474], [0], [0], [0], [0], [0], [-7310], [0], [0], [0], [80080], [152570], [0], [-249100], [-179062], [0], [60424], [0], [0], [257348], [-255530], [0], [0], [178850], [0], [-39130], [0], [0], [-205900], [0], [271096], [0], [-267388], [-219170], [131920], [0], [-261826], [0], [0], [-280280], [0], [-254410], [206444], [0], [-272792], [0], [112714], [0], [191900], [0], [0], [8372], [41830], [0], [-58520], [0], [108290], [0], [0], [-235352], [-282490], [0], [0], [34580], [0], [0], [0], [263410], [0], [0], [277130], [0], [0], [0], [323512], [0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_576_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_576_4_a_m();".
// 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_576_4_a_m(:prec:=1)
    chi := MakeCharacter_576_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_576_4_a_m();".
// 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_576_4_a_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_576_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![0, 1]>,<7,R![-20, 1]>,<11,R![0, 1]>],Snew);
    return Vf;
end function;