
// Make newform 1815.4.a.e in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1815_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_1815_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_1815_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_1815_a();"
function MakeCharacter_1815_a()
    N := 1815;
    order := 1;
    char_gens := [1211, 727, 1696];
    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_1815_a_Hecke(Kf)
    return MakeCharacter_1815_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 := [[-1], [3], [5], [24], [0], [-22], [14], [20], [-168], [-230], [-288], [-34], [-122], [188], [256], [-338], [100], [-742], [-84], [-328], [38], [240], [-1212], [330], [866], [1218], [-88], [-36], [970], [1042], [-1936], [-732], [-2214], [-20], [1330], [1208], [-3514], [-2068], [24], [618], [3340], [-178], [-1888], [-1922], [-2526], [-1160], [4468], [6032], [-2636], [4830], [-2682], [-2320], [-2002], [132], [-7614], [4888], [1270], [-1072], [5394], [-2442], [-2772], [-4542], [-5116], [-2808], [-7318], [2246], [1332], [11534], [-11956], [-4870], [10722], [-120], [3936], [-3022], [-13340], [-1008], [9630], [7126], [-8718], [10870], [-9700], [862], [-15792], [11602], [440], [-10188], [-13310], [-3226], [-6582], [15072], [476], [19680], [-5944], [-10772], [8140], [13768], [22150], [1562], [668], [6138], [10484], [-3606], [-12252], [14550], [25468], [12866], [-14844], [-20402], [10760], [-14282], [-11056], [16418], [-10374], [-5260], [21352], [-29118], [5772], [-14264], [6902], [-20140], [-3218], [7518], [18114], [-23868], [172], [22138], [3070], [15600], [20696], [30778], [-11740], [-2632], [-20528], [21646], [-18282], [24190], [-25698], [-33436], [-37594], [-4730], [8748], [-44142], [3992], [14444], [42150], [13400], [8658], [-42826], [-35900], [-3088], [35274], [25042], [12572], [21864], [31236], [8272], [-20200], [31010], [39174], [4138], [23676], [-18922], [-39656], [-33228], [-974], [-13608], [13472], [3234], [13870], [-1618], [37020], [-54938], [16008], [36198], [2320], [-40950], [-38052], [23742], [5848], [26570], [-2224], [59428], [-25538], [17254], [50112], [9550], [60474], [-52628], [39430], [-5152], [-50558], [10268], [28812], [56422], [-46476], [-37318], [-12562], [24102], [16254], [-58472], [44490], [13968], [-3474], [-49570], [25140], [50886], [-39520], [30068], [-15450], [-8908], [-21746], [-52018], [-19848], [-524], [-53880], [-43078], [58784], [-38322], [95096], [-21018], [-17182], [47800], [-60990], [-82208], [27364], [-59630], [56202], [-76000], [-76936], [-55572], [86262], [16820], [-62912], [-39322], [-1948], [105504], [41970], [-68942], [9540], [38232], [68892], [-75012], [-54968], [-97770], [110478], [-113800], [25136], [-118148], [7180], [-122272], [-2086], [11198], [22536], [112410], [-38582], [84180], [-27218], [24844], [-1794], [-86186], [123728], [-65516], [-81470], [32058], [88866], [5980], [67030], [-61078], [-75572], [-12382], [-50218], [98716], [-61558], [-42240], [17454], [122072], [-65964], [98970], [-66522], [-3852], [-62192], [-1928], [108904], [-60222], [73404], [87312], [4402], [77874], [96680], [-20130], [-15658], [67196], [55638], [-100212], [110698], [-66150], [-26848], [-122898], [102300], [-49196], [-92442], [-96886], [9200], [-46788], [58852], [119906], [132516], [-40330], [-125400], [-93822], [28608], [-48690], [-40482], [20012], [81304], [-89530], [107340], [-102432], [66882], [-128370], [128308], [-48694], [-156262], [-68528], [-117882], [-19118], [-17860], [-121388], [115824], [-55102], [-115062], [88006], [147040], [-9932], [-66932], [-60364], [-174010], [-10082], [107642], [-150816], [206542], [-88534], [83490], [53592], [-23258], [109860], [155102], [-161564], [42768], [-164434], [184548], [-141414], [94262], [-56992], [-186990], [88758], [138080], [146988], [156654], [67192], [101954], [-34522], [-21984], [66620], [-102004], [-119558], [-118806], [3768], [-117962], [137532], [230580], [214688], [-7470], [104088], [-16154], [8620], [-223872], [1438], [53550], [228374], [-89338], [-107238], [204584], [43294], [119460], [-144248], [98192], [185486], [60108], [70896], [93570], [49822], [67540], [35996], [78952], [157558], [1600], [-50310], [105172], [-23982], [-26470], [54402], [115904], [262346], [94210], [265928], [-66634], [157678], [124572], [230460], [115278], [98994], [-39788], [167748], [-167546], [38422], [-198080], [275176], [209586], [2728], [45350], [-55006], [-165504], [245660], [209882], [37366], [90812], [-99210], [-88348], [210200]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1815_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1815_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_1815_4_a_e(:prec:=1)
    chi := MakeCharacter_1815_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_1815_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_1815_4_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1815_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![1, 1]>,<7,R![-24, 1]>],Snew);
    return Vf;
end function;