
// Make newform 1155.4.a.b in Magma, downloaded from the LMFDB on 24 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_b();".
// 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_b();".
// 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], [44], [-72], [-4], [-162], [102], [56], [-124], [18], [224], [120], [414], [660], [-334], [314], [-36], [110], [-316], [-732], [-924], [1154], [-270], [104], [468], [740], [-288], [1496], [-300], [-2376], [-520], [-966], [-796], [1286], [3626], [90], [-870], [-2100], [-3136], [-528], [2462], [186], [-1888], [-3490], [3272], [1260], [-724], [-4878], [-5166], [-1210], [6780], [3162], [-6060], [-4434], [-1528], [6794], [-4416], [-7462], [-6834], [-1486], [-5490], [9062], [-8346], [-8212], [-6262], [8172], [5642], [-3030], [-7914], [-808], [-14218], [3260], [576], [14046], [4754], [378], [-13894], [-12336], [2486], [-54], [3218], [13232], [-12744], [14202], [4070], [3894], [-9988], [6204], [16752], [4388], [10644], [2216], [-2502], [-9306], [-22356], [5630], [-7960], [-3940], [9786], [-9576], [15516], [-9718], [-1498], [5628], [-4452], [-20136], [-9718], [18200], [12266], [-6744], [-3862], [7448], [-25902], [12164], [-8448], [-20406], [-19524], [-26440], [-13558], [26322], [-25608], [-16294], [-162], [-26026], [-7446], [-13816], [-24172], [-1366], [-1080], [-13240], [-10564], [-30], [25658], [-16002], [33098], [16062], [-11868], [-5308], [2358], [4880], [27516], [-21016], [19902], [-18268], [-40620], [-32410], [-3738], [8978], [21036], [-38590], [-22866], [1310], [24420], [-15856], [29496], [-21022], [7338], [9924], [-25122], [42632], [-20568], [8076], [-15168], [-21736], [9872], [-43894], [-18], [-19944], [-40264], [-4242], [-40666], [-4636], [-25380], [-21166], [57462], [46244], [-17302], [-43972], [44292], [29732], [7344], [32430], [14994], [14294], [31484], [-5494], [912], [-6226], [48780], [4784], [-31158], [27060], [9798], [-3670], [-7108], [17916], [14862], [47034], [73112], [-8962], [57050], [48348], [-18714], [36488], [-17148], [4464], [39734], [-1186], [-67830], [82640], [-24516], [27036], [-12130], [-80200], [31602], [76062], [-6174], [3764], [67040], [-51246], [38768], [-43296], [-80332], [51846], [28356], [53864], [69444], [-86584], [-5152], [8420], [-106080], [29360], [59034], [-17470], [39798], [-24132], [102750], [-79152], [71012], [75296], [-38914], [42060], [91008], [-69592], [-56448], [-92962], [-120996], [-72766], [68754], [86130], [99782], [-12186], [113280], [80558], [-46762], [-16194], [13094], [26648], [-78876], [-9022], [-77668], [40062], [67430], [-47394], [21840], [-55540], [-71106], [26960], [-46342], [60626], [-35392], [-70018], [40232], [53220], [35264], [-90862], [92988], [-41382], [-90376], [95694], [-886], [76946], [-50868], [136658], [37638], [138524], [16470], [-99318], [-32604], [-61494], [37980], [-57070], [-116010], [-141172], [154914], [-23580], [-41122], [83342], [-76182], [-1900], [-144480], [-64672], [41186], [42996], [-101932], [155748], [-46882], [129366], [107922], [119904], [-27178], [177564], [56486], [-124944], [-72942], [132218], [-96936], [-26476], [-141130], [22950], [-66652], [7830], [145010], [-90256], [63068], [-24336], [-116778], [-152920], [-90198], [13784], [-165624], [-6178], [15972], [105950], [90732], [-153250], [-34660], [-79888], [-19344], [5250], [75800], [184038], [63024], [87500], [-171682], [-129612], [90894], [82412], [77690], [-203418], [104492], [-87256], [128100], [31722], [77340], [191238], [-190734], [171506], [-26682], [-51078], [86184], [114116], [164834], [29214], [-20392], [71822], [4980], [130358], [129384], [66822], [-143440], [-127240], [69480], [-174438], [-72934], [80166], [-215566], [-141198], [29448], [111416], [26970], [-154744], [18288], [-109864], [-164338], [164648], [-259404], [-139858], [-160494], [216972], [-100816], [91428], [-221890], [-2248], [143460], [13412], [-113574], [198470], [184692], [65456], [-212670], [-67842], [35912], [-34864], [-65364], [21452], [136572], [-213310], [-236562], [-182664], [158738], [225506], [-63882], [13338], [-51592], [-98946], [231642], [140334], [-232180], [272250], [-288036], [-39370], [-241962], [221976], [-117516], [298730], [-246540]];
    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_b();".
// 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_b(: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_b();".
// 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_b( : 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![-44, 1]>],Snew);
    return Vf;
end function;