
// Make newform 1155.2.a.i 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_2_a_i();".
// 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_2_a_i();".
// 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 := 2;
    raw_aps := [[0], [1], [1], [-1], [-1], [-4], [-5], [1], [-5], [3], [-6], [-12], [-2], [13], [-6], [1], [-11], [5], [-10], [-6], [-4], [-8], [5], [13], [-19], [2], [9], [18], [-10], [9], [-19], [4], [-10], [4], [6], [6], [21], [4], [12], [2], [22], [-2], [12], [-14], [-24], [-8], [26], [-13], [-3], [-14], [20], [25], [2], [-28], [8], [4], [17], [-5], [10], [-18], [-28], [-13], [14], [8], [-9], [2], [25], [17], [28], [1], [-26], [1], [-11], [-11], [13], [24], [-12], [-38], [22], [2], [-33], [1], [36], [10], [21], [24], [-6], [-27], [-10], [-22], [-32], [28], [-34], [-37], [-5], [-21], [11], [-21], [-24], [-10], [11], [-42], [-36], [-25], [-20], [-18], [8], [-26], [-34], [-13], [-38], [-26], [26], [10], [13], [-34], [13], [0], [11], [-37], [14], [11], [31], [12], [22], [-7], [25], [-39], [-5], [-46], [-18], [18], [5], [10], [-34], [5], [-34], [-36], [-26], [30], [20], [-3], [-4], [20], [6], [-39], [22], [42], [34], [3], [11], [-15], [40], [33], [16], [56], [-50], [26], [22], [-12], [47], [58], [1], [57], [-3], [-6], [-25], [-26], [-4], [8], [45], [-26], [27], [-29], [10], [-14], [-16], [12], [-18], [-2], [-32], [60], [-22], [17], [11], [-39], [-5], [31], [-58], [18], [-50], [6], [44], [-41], [44], [-32], [20], [48], [-25], [-20], [-21], [61], [19], [50], [17], [-48], [6], [-14], [15], [-70], [-11], [11], [-64], [-24], [-60], [50], [51], [-38], [8], [51], [36], [16], [-38], [-16], [63], [-60], [-34], [-6], [-44], [65], [8], [-28], [64], [47], [-59], [65], [-12], [28], [-34], [24], [60], [-19], [64], [-41], [-21], [60], [-16], [15], [-40], [-60], [-62], [-2], [60], [2], [-55], [-51], [1], [50], [-46], [-78], [-15], [-48], [27], [26], [16], [24], [-36], [-33], [-39], [-4], [-38], [14], [-27], [42], [-4], [-40], [-33], [-64], [-18], [-24], [-39], [40], [4], [37], [-4], [-8], [-54], [72], [26], [2], [-44], [-52], [32], [44], [34], [0], [-8], [-44], [-48], [-16], [10], [-32], [60], [15], [13], [58], [-45], [-40], [-38], [57], [-48], [26], [-27], [26], [42], [39], [60], [-21], [74], [11], [-32], [-18], [58], [-24], [64], [56], [36], [-57], [2], [68], [38], [2], [-59], [60], [-34], [-12], [-25], [14], [76], [-50], [22], [-77], [-54], [-32], [27], [13], [-28], [26], [20], [-78], [-65], [68], [12], [-16], [-32], [51], [-32], [-68], [38], [-75], [-57], [6], [-52], [-11], [-17], [10], [-33], [11], [22], [-44], [64], [32], [51], [-29], [-88], [-52], [55], [68], [20], [68], [-67], [3], [-8], [-74], [-73], [78], [67], [3], [52], [-56], [81], [-86], [6], [7], [38], [-9], [-84], [54], [29], [-65], [43], [-51], [-33], [-44], [40], [-15], [-30], [46], [33], [-69], [96], [6], [-4], [-24], [66], [79], [-13], [73], [-24], [0], [-2], [42], [63], [26], [11], [48], [15], [-91], [2], [-108]];
    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_2_a_i();".
// 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_2_a_i(:prec:=1)
    chi := MakeCharacter_1155_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    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_2_a_i();".
// 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_2_a_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1155_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![0, 1]>,<13,R![4, 1]>,<17,R![5, 1]>],Snew);
    return Vf;
end function;