
// Make newform 1155.2.a.q 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_q();".
// 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_q();".
// 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 := [-6, 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], [-3, 0], [-1, 0], [3, -2], [-3, 1], [2, -3], [2, 1], [0, 1], [5, -1], [-6, -1], [3, 0], [3, -1], [-7, 2], [2, 0], [0, 5], [8, -2], [-4, 3], [-9, 0], [-3, -3], [-1, -1], [6, -4], [11, 3], [6, -3], [2, -1], [9, 0], [-13, 1], [-6, 1], [12, 0], [2, -4], [6, -6], [14, 0], [5, -7], [-10, -1], [-6, 0], [-12, 4], [12, 1], [14, 4], [-12, 4], [2, 10], [12, 2], [-16, -4], [2, 2], [17, 3], [-3, -10], [-10, 3], [0, -9], [-3, 1], [-4, 6], [12, 4], [12, 1], [-12, -2], [-9, -1], [-1, 0], [-4, 6], [12, 2], [-22, 3], [3, -8], [-10, 2], [0, 2], [11, 5], [-12, 6], [17, 6], [5, -3], [-12, 10], [11, 2], [6, -6], [-9, -5], [-7, 9], [-1, 7], [11, 10], [0, 1], [6, -5], [8, 6], [-24, -3], [8, 2], [-21, -3], [5, 4], [-12, -10], [14, 10], [11, 2], [6, 0], [0, 3], [29, 1], [6, -2], [-10, 6], [-12, 10], [6, -7], [14, -2], [-9, 1], [-19, 4], [3, -12], [15, -3], [-15, 11], [20, 10], [14, -9], [-19, -3], [6, -14], [-30, 6], [-9, -11], [8, -15], [2, -8], [-24, 7], [12, 10], [6, 6], [-1, 12], [-10, -2], [2, -4], [-12, 10], [-22, -4], [-25, 6], [-42, 0], [5, 15], [-12, 2], [9, 16], [-9, -9], [-10, -5], [17, 3], [-3, 16], [12, 8], [-34, 0], [15, 3], [-1, 0], [-21, -5], [-25, 11], [38, 2], [-34, -6], [18, 14], [-7, -10], [14, -14], [-6, 4], [-37, 2], [6, -2], [8, -12], [6, 14], [-6, 6], [-4, 12], [33, -1], [26, 5], [-12, 6], [2, 18], [-3, 7], [8, -9], [-30, 0], [14, -1], [21, -8], [-25, 3], [21, -9], [20, -14], [-3, 10], [2, -9], [-24, -14], [26, 0], [-12, 2], [8, -3], [-6, 9], [3, -16], [-6, 12], [17, -13], [-15, -3], [39, -8], [-6, -10], [-13, 8], [-22, 12], [-16, 5], [-12, 7], [-21, -13], [14, -5], [-27, -9], [-43, -3], [26, 2], [18, 6], [-4, -15], [36, -8], [-22, -6], [-28, -2], [-4, 0], [-36, 2], [38, -2], [-15, -4], [-15, 4], [-21, -3], [17, -15], [-37, -3], [-10, -11], [-48, 5], [2, -20], [-18, -16], [-10, -12], [21, -17], [-12, -9], [0, -16], [20, 0], [-10, 9], [15, -8], [-30, 0], [-21, 5], [-25, 0], [-31, 3], [-52, -4], [33, -5], [24, 12], [26, 1], [42, -4], [9, -15], [2, -1], [23, -13], [39, -1], [-4, -18], [-48, -5], [-12, -4], [-10, -2], [47, -7], [18, 14], [-42, 0], [27, 18], [-28, 0], [26, -10], [-60, 5], [38, 1], [3, -4], [8, 3], [-18, 15], [-24, -1], [-28, 14], [9, -1], [-10, 9], [2, -14], [-16, 13], [-9, -15], [29, -15], [-51, 6], [-16, 15], [-24, -6], [6, 18], [-12, 14], [42, 6], [-31, -6], [50, 0], [-7, 18], [-21, -10], [6, 3], [32, -8], [-15, 1], [20, -3], [-12, 22], [38, -12], [36, 11], [-36, -12], [-22, -3], [21, -18], [39, -15], [-1, 20], [-28, 5], [30, 13], [2, 14], [-25, 11], [12, 8], [17, -6], [8, -3], [36, -15], [-40, 15], [24, 16], [-9, -11], [-1, -7], [-12, 1], [38, 0], [2, -16], [-7, -15], [-46, 3], [-34, -15], [26, 16], [57, 0], [-52, 12], [-22, 15], [24, 12], [-27, 0], [2, -12], [36, 16], [29, 18], [2, -21], [54, 5], [20, 7], [60, -4], [38, 12], [36, 17], [0, -28], [12, 1], [36, -3], [-60, 8], [14, -28], [12, 0], [8, -18], [12, 13], [-36, -8], [-4, 24], [62, 6], [48, 11], [20, 5], [27, -14], [-1, 8], [32, -7], [-15, 18], [8, 15], [24, 19], [11, -27], [-30, -10], [-12, 11], [-15, -9], [20, 27], [-42, 17], [5, -24], [-12, -2], [15, 7], [14, -6], [51, 9], [-40, 4], [-16, -1], [30, 12], [38, -15], [36, 2], [20, -18], [-34, 10], [71, -3], [-66, -3], [24, -3], [-10, -3], [36, 8], [5, 4], [36, -20], [62, -2], [-24, 8], [-25, -8], [12, -10], [32, 9], [-52, -9], [-64, 1], [39, 8], [0, -3], [38, -18], [57, -8], [51, -3], [8, -17], [-28, -5], [-36, 16], [-18, -13], [83, 0], [20, -6], [18, 11], [-34, 21], [-52, 12], [27, -6], [-6, -28], [-6, 1], [18, 10], [-21, -28], [11, -5], [-18, 8], [-18, 24], [57, 15], [-19, 27], [50, -12], [3, -18], [41, 15], [-10, -13], [0, -18], [8, 18], [-48, 2], [51, 1], [-7, -18], [-22, -15], [-42, 12], [-63, 5], [8, -8], [6, -9], [38, 9], [-15, 23], [3, -28], [-4, -8], [30, 3], [-61, 12], [54, 15], [41, -16], [89, -3], [8, 6], [24, -14], [17, -6], [-6, -10], [36, -11], [-43, -7], [42, 4], [-31, -3], [26, 28], [-18, -26], [-19, 14], [-33, 3], [29, -24], [-51, 0], [59, 9], [-48, -1], [-6, 17], [-19, -8], [8, 25], [54, -12], [17, -15], [-45, -17], [-40, 12], [18, 1], [18, -6], [20, 27], [-10, 18], [-3, -21], [27, 7], [17, -3], [-36, 13], [6, 20], [-12, 15], [26, 6], [3, 10], [0, 5], [-49, 13], [60, -7], [-39, -20], [-9, -11], [-34, -16], [78, -5]];
    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_q();".
// 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_q(: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_q();".
// 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_q( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1155_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-6, 0, 1]>,<13,R![-2, -4, 1]>,<17,R![3, 1]>],Snew);
    return Vf;
end function;