
// Make newform 1155.2.a.p in Magma, downloaded from the LMFDB on 19 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_p();".
// 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_p();".
// 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
        poly := [-2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
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, 0], [-1, 0], [-1, 0], [1, 0], [2, 1], [1, 2], [-1, 2], [-1, 2], [3, 3], [2, 1], [-2, 3], [4, -5], [-5, 1], [6, 3], [3, -4], [13, -1], [5, -4], [-6, 0], [-4, -5], [0, 6], [-4, 3], [3, -10], [7, 5], [-3, 3], [6, 4], [1, -9], [-6, 1], [10, -5], [-3, -8], [1, -9], [6, 3], [8, 4], [14, 0], [2, -2], [-10, -4], [11, 1], [-2, 9], [6, 4], [8, -8], [12, 3], [2, -12], [0, -4], [6, -6], [-12, 2], [-8, 8], [-2, -6], [3, 3], [-19, 4], [-6, -9], [12, 3], [7, -5], [0, -6], [12, 4], [-12, -3], [0, 10], [9, 11], [-5, 2], [16, -2], [24, 2], [-6, -15], [-5, -10], [-22, -6], [0, 22], [-11, -3], [-8, 10], [1, 10], [3, 3], [0, -14], [19, 0], [6, 10], [1, -11], [-9, -3], [5, 1], [-25, 2], [-4, -19], [6, 21], [12, -6], [8, -13], [28, -6], [1, 5], [5, -4], [36, 2], [10, -10], [3, 0], [26, 4], [-24, 1], [19, -1], [6, 10], [-22, -6], [12, 18], [-10, 11], [-14, -2], [-19, 11], [-15, 12], [3, -18], [21, 1], [-1, -13], [-16, -18], [10, 7], [7, -21], [6, -26], [-18, -6], [-3, -21], [-8, -7], [6, -12], [-8, -5], [-24, 6], [14, -10], [19, 10], [14, -2], [14, 12], [0, -30], [6, -24], [-21, -6], [-6, 28], [-13, 11], [-24, 6], [9, -4], [-11, 17], [10, 11], [19, 17], [-23, 10], [-28, -8], [-14, -12], [17, 17], [-13, 4], [-3, -29], [17, 11], [-10, 14], [6, 30], [-6, 10], [-7, 6], [14, -22], [-10, -20], [-21, 12], [34, -10], [20, -24], [18, 14], [-10, -10], [12, 24], [3, 5], [-18, 15], [-4, -10], [-6, -6], [-33, -1], [20, 5], [2, 16], [-2, -29], [-27, -8], [25, 1], [-17, -5], [-32, -6], [5, 4], [14, 21], [-20, 10], [-10, 8], [0, 14], [-16, 23], [2, -25], [39, -8], [-42, -4], [23, -15], [27, -11], [-17, 16], [-38, -2], [-29, -12], [-6, -24], [-4, 25], [-4, -13], [-19, -19], [-10, -5], [3, -15], [-49, 3], [10, 30], [-18, -30], [-8, 9], [-16, -20], [-34, 18], [0, -6], [28, 12], [8, -10], [2, -30], [17, -22], [-47, 8], [5, 25], [19, -21], [-3, -3], [-34, -15], [-24, -25], [-10, -8], [-14, 16], [-30, -24], [3, -45], [-8, 11], [-36, 0], [8, -20], [38, -9], [-33, -6], [30, -8], [33, 11], [-25, 6], [11, 27], [32, -12], [-29, 19], [12, -4], [-10, -15], [30, -24], [31, 7], [-26, 11], [-51, -3], [5, -13], [-8, -2], [40, 11], [44, 8], [50, -10], [-23, -13], [-30, 6], [18, 12], [-9, 2], [32, 16], [-26, -6], [24, -21], [-2, -21], [27, -10], [12, -9], [-30, 3], [32, -7], [56, 2], [59, 5], [22, -5], [6, 30], [4, 1], [29, -17], [27, -15], [21, 24], [0, -21], [60, 6], [-42, -22], [12, -18], [6, 2], [29, -24], [2, -4], [-3, 42], [-37, -28], [14, -7], [-8, 0], [-1, -35], [-16, 1], [32, 26], [34, 16], [-32, 25], [36, 28], [-42, -15], [-27, 12], [-31, 7], [-21, 12], [16, 15], [6, 13], [-10, 42], [13, 25], [28, -16], [25, 16], [8, 11], [40, -7], [-12, 3], [12, -4], [21, 9], [-19, 15], [-12, 25], [-22, 16], [14, -16], [7, 17], [-26, 3], [-38, 11], [-30, -12], [49, 8], [20, -44], [14, 39], [76, -4], [-3, 14], [6, -48], [-12, -20], [17, -20], [2, -31], [14, -29], [-56, -3], [24, -24], [10, -4], [-12, 23], [-24, 12], [0, 37], [24, 17], [-8, 40], [2, -36], [-8, 8], [4, 30], [16, 1], [60, -8], [44, -4], [26, 26], [24, -1], [-32, 25], [15, -14], [67, -8], [0, -45], [-15, -50], [-16, 39], [36, 37], [9, 3], [-18, 38], [-8, -55], [27, -15], [36, -15], [62, -7], [77, 6], [-12, -22], [-11, 17], [34, -6], [-23, -29], [16, 40], [0, -51], [-26, 32], [34, -9], [44, 2], [-40, -6], [-22, -22], [-7, 33], [-58, -7], [24, 17], [42, -15], [-72, 0], [17, -38], [-12, 8], [2, 22], [36, -32], [-1, 16], [-32, 14], [28, 37], [28, 33], [44, 11], [-21, -40], [12, -13], [-22, 42], [25, 16], [37, 35], [-8, 47], [8, 45], [-24, -12], [-18, -29], [15, 30], [-60, 18], [-6, -7], [-66, -21], [-20, -12], [-53, 4], [66, -8], [-54, 15], [-66, -6], [19, -44], [21, 33], [-34, -16], [18, -40], [-37, 5], [71, -9], [70, -4], [3, 20], [-29, 5], [-22, -49], [-36, 22], [20, 26], [8, 26], [17, -29], [73, 8], [26, -45], [22, -40], [-17, -13], [20, -12], [-62, -23], [-62, -5], [11, -13], [39, 24], [68, -8], [-6, -17], [15, 18], [6, 19], [-59, 0], [-37, 25], [0, 6], [28, 46], [-79, 2], [-30, -34], [-16, -49], [15, 57], [30, 0], [35, 31], [14, -36], [18, 10], [-75, 6], [-27, 45], [-35, 14], [-39, 8], [-19, -33], [-36, 31], [-6, -45], [17, 22], [-52, 23], [18, 52], [7, 41], [-15, 35], [-28, -16], [-6, -7], [-10, -38], [8, 3], [-30, 6], [-13, -29], [57, 1], [15, 9], [-48, -7], [50, -8], [36, -27], [-10, -46], [71, -10], [0, -17], [57, -15], [16, 17], [-31, 28], [33, 23], [70, 20], [18, -63]];
    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_p();".
// 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_p(:prec:=2)
    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_p();".
// 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_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1155_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-2, 0, 1]>,<13,R![2, -4, 1]>,<17,R![-7, -2, 1]>],Snew);
    return Vf;
end function;