
// Make newform 1176.2.a.l in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1176_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_1176_2_a_l();".
// 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_1176_2_a_l();".
// 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_1176_a();"
function MakeCharacter_1176_a()
    N := 1176;
    order := 1;
    char_gens := [295, 589, 785, 1081];
    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_1176_a_Hecke(Kf)
    return MakeCharacter_1176_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, 0], [-1, 0], [2, 1], [0, 0], [-2, 2], [0, -3], [6, 1], [4, 2], [-2, -2], [0, 2], [0, -2], [4, -4], [6, 3], [0, -8], [4, -6], [-2, 0], [0, 6], [4, 5], [0, 8], [-2, -6], [12, -3], [8, 4], [-4, 0], [10, -3], [4, -3], [2, -9], [0, 10], [10, 2], [8, -8], [-10, 0], [20, 0], [-4, 0], [-12, 2], [-4, -12], [-10, 8], [-4, -4], [-4, 3], [0, 4], [-12, -2], [-18, 1], [2, -6], [0, -5], [-2, 10], [2, 0], [-14, 8], [0, -4], [-4, 4], [8, 4], [-8, 2], [-24, -1], [-12, -2], [-10, -2], [4, 7], [8, -10], [-2, -1], [-6, -10], [-10, 7], [-8, 10], [-6, -16], [4, -2], [-12, -10], [-6, 3], [-20, 6], [4, 14], [16, 9], [-22, 0], [-4, 8], [16, -4], [6, -6], [12, -1], [2, -21], [26, 2], [16, -8], [-6, 8], [-12, -8], [8, -12], [-16, -14], [-12, -3], [4, -2], [-4, -3], [16, -6], [-14, -8], [6, -10], [8, -5], [24, -8], [-14, 2], [6, -16], [-2, -16], [-2, 13], [-4, 4], [-16, -2], [20, 2], [-12, 12], [22, -2], [-8, -12], [-8, -8], [-18, -13], [10, 3], [12, -12], [-18, 0], [-20, 12], [10, 16], [16, -10], [-20, 10], [-36, -4], [-8, 15], [-16, -14], [46, 1], [-2, 18], [-8, -3], [8, 12], [-16, 4], [4, -6], [28, 4], [-20, 12], [4, 22], [12, 14], [-20, 14], [32, 10], [30, -6], [12, -5], [-12, -8], [-2, 21], [18, -14], [20, -8], [8, -10], [-16, 16], [16, -16], [-24, 10], [16, -17], [16, 12], [-2, -2], [-8, 20], [8, 24], [-22, -7], [8, 19], [-2, 25], [4, 8], [-38, -1], [18, -16], [20, 4], [-22, 8], [-8, -12], [26, 10], [16, 13], [4, 14], [12, -5], [10, -15], [28, -18], [6, 34], [0, -20], [6, 17], [-16, 4], [-20, -14], [48, 4], [-2, 6], [20, 8], [-6, -7], [16, 25], [-2, -9], [-22, -26], [2, 0], [-20, -8], [-20, 0], [12, -14], [24, -16], [4, -16], [-36, -13], [-10, 16], [10, 15], [-30, -6], [36, 5], [-50, -6], [-20, -4], [-32, 16], [26, -21], [-4, -8], [8, -2], [-48, -2], [12, 31], [40, 8], [-52, 0], [12, 0], [-46, -5], [14, -26], [6, -15], [10, 8], [-20, 4], [4, 44], [-16, 24], [-28, 19], [14, -18], [-12, -12], [26, -13], [-14, 2], [-18, 29], [-12, -24], [-4, -16], [-6, 5], [-12, -30], [22, -32], [8, -28], [24, -7], [12, -9], [36, -4], [22, 25], [56, 0], [14, 18], [-42, 16], [4, 42], [0, -8], [-10, -5], [44, 12], [-28, 28], [-20, -14], [16, 27], [-4, 16], [-30, -13], [-18, -30], [-16, -14], [40, 16], [32, -6], [2, 24], [0, 12], [-36, 4], [20, 4], [18, -15], [-14, 2], [-48, -10], [-14, 22], [16, 24], [-20, 2], [-28, -32], [46, 16], [12, 18], [16, -36], [-36, 3], [-2, -16], [6, -42], [-8, 44], [-34, 18], [4, 8], [-16, 8], [-18, -16], [22, 15], [28, 10], [-56, 14], [48, -10], [-12, 12], [-14, -10], [-6, 0], [10, -25], [-10, 34], [36, 3], [26, -21], [-6, -22], [-28, 8], [-20, -34], [-14, -37], [32, 11], [48, 0], [6, 18], [8, -35], [-20, -13], [-26, -3], [4, 16], [-26, -16], [-2, -7], [-28, -16], [-24, 38], [20, 35], [36, 8], [-12, 3], [16, 36], [-36, 19], [-8, 14], [-6, -2], [-38, 24], [10, 0], [0, 2], [-48, 8], [-12, 28], [24, 36], [4, -51], [44, 4], [-2, 6], [10, 32], [-6, -32], [72, -6], [-6, 33], [38, 16], [20, 44], [44, 10], [64, -2], [-2, -24], [-22, -1], [8, -16], [-22, -3], [32, 18], [-28, 24], [-8, -3], [48, -26], [-36, -20], [-10, 34], [-4, 20], [-24, 4], [-2, -6], [-8, 17], [-6, -54], [2, 8], [32, 24], [-56, -18], [-44, -10], [-8, -32], [-66, 10], [-52, -11], [36, -12], [-26, -22], [28, -39], [12, -2], [20, -18], [4, 0], [14, 25], [4, 8], [-22, 8], [-44, 9], [48, -12], [60, -6], [-42, 22], [24, 2], [-26, 8], [48, 26], [32, 30], [-16, -2], [-32, 16], [0, 14], [32, 12], [-22, -15], [-52, 3], [-40, 14], [6, 24], [20, 22], [26, -27], [-16, 8], [-24, -10], [42, -2], [-8, 5], [8, 24], [-8, 40], [-10, 41], [-20, 30], [50, -24], [30, -40], [-40, 24], [54, 16], [-6, -29], [16, -12], [-36, -4], [22, 32], [-26, 38], [42, 8], [-34, 23], [22, -10], [-58, -2], [-12, 28], [84, 0], [-54, -31], [-48, -32], [-22, 32], [14, -50], [-4, -38], [26, -10], [-34, -8], [40, 6], [6, 8], [-36, -24], [-6, -30], [56, 9], [-34, -11], [12, 49], [22, -47], [-70, 0], [16, 48], [22, -8], [-68, -12], [-24, 16], [12, -24], [48, -5], [-36, 32], [-12, -54], [-20, -28], [22, 23], [38, 30], [-68, -18], [38, 30], [80, -12], [56, 8], [26, 15], [-60, -8], [-24, 14], [4, -25], [-50, -24], [-4, -4], [38, 43], [-30, 37], [8, 28], [-54, 8], [-18, -56], [-12, 8], [16, -6], [56, -13], [0, -22], [6, -46], [-24, -4], [44, 4], [46, -1], [38, -22], [-48, 22], [70, -3], [-44, 6], [-64, -10], [-28, -17], [-54, -34], [12, 8], [40, 11], [34, -17], [38, -22], [-44, -6], [-20, 40], [-68, 10]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1176_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1176_2_a_l();".
// 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_1176_2_a_l(:prec:=2)
    chi := MakeCharacter_1176_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_1176_2_a_l();".
// 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_1176_2_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1176_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![2, -4, 1]>,<11,R![-4, 4, 1]>,<13,R![-18, 0, 1]>],Snew);
    return Vf;
end function;