
// Make newform 1155.4.a.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1155_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_1155_4_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_1155_4_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_1155_a();"
function MakeCharacter_1155_a()
    N := 1155;
    order := 1;
    char_gens := [386, 232, 661, 211];
    v := [1, 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_1155_a_Hecke(Kf)
    return MakeCharacter_1155_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 := [[-3], [-3], [-5], [7], [-11], [-82], [54], [80], [48], [-234], [-28], [-82], [270], [-28], [-300], [582], [-684], [758], [524], [552], [110], [944], [1368], [42], [1658], [-1194], [-484], [-1884], [-394], [-1422], [824], [-1896], [2874], [-1024], [-3570], [-1888], [1202], [-3052], [1392], [-1122], [-84], [3122], [-3720], [-3670], [3294], [-1132], [-1348], [-2692], [1680], [1922], [-6390], [-336], [-5242], [-5484], [2154], [4104], [-1158], [-1528], [494], [-4206], [4760], [1398], [-3040], [-8388], [6458], [-6834], [9260], [5330], [4308], [-4690], [-9414], [2880], [2972], [2414], [13172], [2172], [-12666], [-6334], [-14910], [10550], [3540], [-14146], [-12024], [698], [-2896], [-3588], [4626], [17426], [3390], [-6208], [2676], [-12480], [14048], [-10692], [-21724], [16272], [-20646], [17082], [13736], [7622], [-15532], [-15498], [-11424], [1026], [-7828], [-7630], [10500], [-13482], [22872], [-17194], [15680], [-21922], [14634], [11468], [-6160], [25170], [-11860], [-7356], [-24858], [5676], [-10942], [-7678], [-28698], [-16452], [5756], [-9402], [2534], [6036], [-18268], [-610], [8756], [-26112], [-22648], [-24802], [8118], [5918], [27930], [30872], [4386], [20346], [4016], [8910], [-41488], [19116], [-23494], [-7188], [23942], [-21258], [-33292], [22344], [-7402], [-7062], [-24604], [13464], [-2092], [30888], [-28960], [34914], [37694], [12294], [-30900], [50562], [-1384], [-9060], [-12126], [-8196], [-25936], [-8818], [-6766], [-56046], [58932], [51842], [-8568], [38042], [6956], [-44238], [34652], [-36618], [-23392], [-9490], [-38176], [55128], [7598], [18726], [24912], [-44478], [23366], [-3292], [-46318], [26952], [-32686], [-26316], [16628], [-29646], [33780], [-12798], [-51046], [64502], [-51594], [38928], [27126], [45896], [13802], [-21994], [-21876], [86874], [49004], [-68892], [39114], [7100], [-25630], [31290], [-90232], [-76764], [-48144], [13826], [-4936], [58398], [-52584], [-49098], [-46258], [71408], [48210], [54224], [93456], [93086], [-66006], [-98736], [40928], [-74028], [34838], [78848], [35384], [-15654], [10796], [-76584], [-45022], [654], [-17748], [-10524], [-23964], [28424], [68492], [-11194], [-58866], [78240], [-52204], [81228], [37868], [-98064], [-65626], [-53802], [103560], [-55366], [-118194], [53052], [-107098], [93224], [-121278], [1166], [-42736], [9828], [-76642], [29894], [20322], [-820], [21990], [-63966], [-72004], [-103362], [-41374], [-70156], [45674], [-135520], [102854], [103988], [-40524], [-137146], [28586], [26544], [33840], [105848], [-116616], [141158], [133184], [-19704], [69122], [39486], [-9484], [66366], [-48666], [100788], [95418], [7992], [-47914], [123390], [95708], [116274], [-52896], [123056], [-45850], [25206], [178448], [-15372], [-61900], [-23326], [91044], [89210], [6984], [-66370], [-38592], [-88890], [134730], [-5044], [-49824], [39854], [80940], [-23928], [-135406], [-33894], [-110896], [-58054], [-36186], [108488], [-130014], [10778], [90092], [173612], [108384], [189822], [-182698], [176838], [79640], [-9216], [-51748], [79308], [-147058], [94974], [89930], [-4336], [-123610], [-81126], [-13650], [59168], [-131802], [-31980], [-98350], [-179620], [120960], [123066], [-117928], [28634], [13302], [-58048], [101198], [-70938], [138108], [114720], [-146694], [20904], [170414], [-148986], [-144192], [-107604], [118148], [83690], [-22530], [-73312], [4538], [213300], [-2740], [182640], [69678], [-165112], [-1618], [-246108], [-205896], [-43618], [-52554], [-16738], [-46446], [-118518], [-45328], [65610], [-67720], [-16572], [189848], [45074], [-30652], [-89388], [-136078], [60090], [46956], [-256804], [-144360], [-1222], [-47104], [-111102], [187292], [49806], [114806], [20514], [-37696], [20346], [-260370], [22304], [-14914], [-179982], [252452], [252324], [-81850], [-213042], [-253980], [213716], [117818], [-131166], [-67848], [-75196], [-263166], [-204360], [-137202], [97814], [54144], [-106680], [-2998], [-46494], [97236], [119154], [-18916], [252504]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1155_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1155_4_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_1155_4_a_a(:prec:=1)
    chi := MakeCharacter_1155_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_1155_4_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_1155_4_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1155_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![3, 1]>,<13,R![82, 1]>],Snew);
    return Vf;
end function;