
// Make newform 441.6.a.e in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_441_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_441_6_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_441_6_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_441_a();"
function MakeCharacter_441_a()
    N := 441;
    order := 1;
    char_gens := [344, 199];
    v := [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_441_a_Hecke(Kf)
    return MakeCharacter_441_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], [0], [0], [0], [0], [-427], [0], [3143], [0], [0], [2723], [-6661], [0], [22475], [0], [0], [0], [-38626], [-37939], [0], [-78127], [90857], [0], [0], [-134386], [0], [-211477], [0], [-247843], [0], [347111], [0], [0], [-454657], [0], [-408724], [109214], [678248], [0], [0], [0], [-853027], [0], [656375], [0], [-912268], [-288976], [304052], [0], [-1459507], [0], [0], [1296974], [0], [0], [0], [0], [2252852], [738389], [0], [-2334577], [0], [3202325], [0], [2567075], [0], [-546151], [2631725], [0], [4275614], [0], [0], [-2583175], [-5317273], [69893], [0], [0], [-5003425], [0], [-5170207], [0], [-4875799], [0], [-7491925], [3993332], [0], [0], [1185761], [0], [2922173], [0], [0], [-1364875], [0], [-2173693], [0], [0], [0], [-11728675], [-3022351], [12798200], [0], [0], [0], [5887799], [-12909925], [0], [0], [0], [-17434249], [-15680539], [-15823450], [0], [-12226039], [-16243876], [0], [-13384777], [0], [0], [0], [-690949], [17311523], [0], [0], [7019201], [0], [-22701382], [0], [15689261], [-17564827], [12817043], [0], [-27321949], [19852586], [0], [25001711], [0], [33106136], [0], [0], [22770776], [0], [22292348], [0], [-22648507], [0], [-3008425], [0], [3067736], [0], [-3839314], [0], [-45806623], [0], [26211989], [0], [-4218211], [0], [5297075], [0], [0], [0], [-32345311], [0], [0], [0], [60552827], [60472811], [-64590139], [0], [0], [59500574], [0], [-67975627], [-36018157], [0], [69527873], [0], [-58731148], [66382211], [76032275], [0], [47725925], [0], [0], [0], [50690114], [32476325], [67658189], [0], [-44568727], [0], [22314176], [0], [0], [0], [-92868301], [-77782750], [0], [0], [0], [70390901], [-94804150], [92601614], [0], [0], [-105845068], [0], [0], [-116198824], [80360711], [0], [-17335852], [0], [0], [67061351], [-34794964], [0], [0], [0], [-8052223], [-66119557], [0], [148772900], [0], [145526582], [0], [0], [108737825], [0], [127663073], [-134356264], [-25770523], [0], [168318227], [0], [161487557], [0], [0], [0], [0], [-79429777], [101258927], [-185903218], [0], [0], [146306825], [0], [173769632], [0], [-147551539], [0], [0], [30695357], [0], [0], [-92127727], [26052761], [0], [200077850], [152172077], [0], [-94649107], [191178575], [0], [-60122293], [0], [0], [-144785800], [0], [-955549], [25283600], [-111619123], [194217593], [197198414], [-266580748], [0], [-178037161], [-16209001], [0], [0], [172366601], [0], [-36264949], [-112650664], [0], [253600577], [0], [-223046593], [0], [0], [0], [0], [0], [318538523], [0], [-281230873], [0], [0], [-80933839], [347077850], [0], [-13787332], [0], [361677299], [284835689], [0], [-339759343], [0], [-181207177], [0], [0], [0], [-88899448], [0], [-354856411], [0], [0], [-397550923], [0], [-277250701], [183995675], [0], [-376200127], [0], [-222800851], [-409656439], [-453441373], [0], [0], [361720901], [0], [-85064161], [0], [455859377], [0], [437043518], [0], [-178208527], [-3054961], [405483275], [0], [0], [-185236501], [0], [0], [86699249], [239827136], [0], [0], [42863576], [-270721450], [0], [-550668748], [-453511957], [0], [0], [0], [0], [0], [-492315514], [0], [0], [0], [285806339], [-546221302], [0], [215227223], [616543226], [0], [393095339], [0], [0], [-376224499], [-174198475], [0], [0], [131241698], [0], [504001589], [0], [0], [-268304500], [0], [195595736], [0], [76688849], [402139850], [164900873], [0], [-624847543], [0], [0], [-485419039], [0], [733366598], [-753787468], [0], [-19970851], [0], [491811614], [0], [628317764], [0], [0], [731456999], [599768786], [0], [-270197977], [0], [-360091102], [0], [0], [358257224], [-109931575], [0], [0], [845156039], [0], [0], [0], [916245575], [0], [0], [331621850], [0], [0], [0], [413471576], [0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_441_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_441_6_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_441_6_a_e(:prec:=1)
    chi := MakeCharacter_441_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_441_6_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_441_6_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_441_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![0, 1]>,<5,R![0, 1]>,<13,R![427, 1]>],Snew);
    return Vf;
end function;