
// Make newform 3136.2.a.be in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3136_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_3136_2_a_be();".
// 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_3136_2_a_be();".
// 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_3136_a();"
function MakeCharacter_3136_a()
    N := 3136;
    order := 1;
    char_gens := [1471, 197, 1473];
    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_3136_a_Hecke(Kf)
    return MakeCharacter_3136_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, 1], [1, -2], [0, 0], [-1, -1], [0, 2], [3, -2], [-5, -1], [1, 3], [0, 2], [7, -1], [-3, -4], [4, 2], [4, 4], [9, 1], [1, 0], [-1, -7], [3, 4], [-7, 3], [-8, -4], [9, 4], [1, -5], [-4, 8], [9, 0], [4, -2], [5, 6], [7, 1], [-3, -7], [11, -2], [4, 10], [0, 4], [5, -9], [-3, 10], [-4, -8], [-9, 2], [9, -7], [15, -4], [11, -3], [2, 0], [11, 0], [7, -1], [2, -8], [-1, 7], [5, -10], [16, 2], [7, 3], [-12, 0], [8, -4], [9, 5], [-7, 2], [5, -2], [10, -8], [1, -8], [14, 12], [-13, 6], [-1, -7], [7, 4], [-9, -15], [1, -8], [-4, -6], [-7, 1], [6, 16], [-20, 4], [-23, 3], [1, 20], [21, -8], [27, 1], [12, -2], [25, 7], [8, -2], [-5, 2], [7, -13], [17, -9], [-3, 8], [-18, -12], [-7, -3], [-21, 2], [-7, 2], [5, 2], [11, -18], [-4, -4], [8, 6], [17, -3], [-20, 6], [-7, 21], [-19, 5], [4, -2], [-9, 20], [0, -18], [0, 8], [-3, 11], [1, -21], [-1, 9], [-2, 4], [11, -11], [-16, 4], [33, 6], [-7, 0], [-5, -9], [23, 2], [-6, 12], [3, -2], [7, 5], [31, 4], [-17, -1], [-39, 0], [-12, -12], [3, -6], [-9, -19], [-12, -10], [17, 13], [-13, 6], [-12, 22], [-25, 5], [-24, -4], [-17, 0], [-28, 12], [1, 19], [5, 24], [12, 16], [-25, -4], [12, -10], [1, -14], [-33, 11], [-3, -17], [-14, 0], [-3, 28], [7, 17], [40, -4], [35, -8], [23, -21], [-32, 4], [-9, -9], [-8, 10], [11, 22], [-28, 10], [5, -10], [-25, -15], [16, 22], [-1, -12], [12, 4], [-1, -10], [7, 29], [36, 4], [21, -14], [8, -8], [-32, -6], [-31, 4], [-21, 11], [-15, -13], [-9, -30], [26, 0], [4, -32], [41, -7], [-7, 23], [-8, 0], [-9, 11], [25, -4], [6, -16], [7, -32], [3, -15], [4, -22], [24, -4], [37, -1], [-43, 6], [-17, 31], [15, 21], [-17, -20], [-20, 26], [-5, 4], [1, 7], [16, 26], [25, 3], [7, 16], [15, -9], [4, -6], [18, 4], [-7, -32], [0, 28], [-7, -18], [9, 3], [36, 8], [-18, 8], [-15, 16], [-25, 1], [23, 20], [-5, 14], [-7, -15], [5, -2], [-25, 19], [17, -16], [-28, 16], [-3, 33], [9, 26], [23, -17], [19, -22], [-3, 6], [-17, -2], [36, -6], [-33, -15], [27, 18], [-32, -4], [-37, 16], [11, 22], [4, 24], [-9, 12], [-25, -27], [-19, 21], [-6, -32], [15, 1], [-11, 30], [32, 14], [16, 0], [-3, -5], [7, 7], [-21, -2], [-47, -11], [35, 6], [7, 31], [2, 32], [-9, 10], [2, -16], [-17, 28], [23, 23], [-60, 8], [-40, 14], [19, -10], [23, 25], [-15, 17], [51, -7], [25, 12], [23, 9], [-8, 48], [-11, -38], [-12, 20], [-23, 3], [3, 42], [-9, -26], [-12, -28], [-66, 0], [25, 11], [11, 15], [-23, -17], [-27, 20], [30, 0], [-25, 21], [16, 36], [9, -19], [55, -5], [6, 24], [48, 14], [33, -8], [-31, 13], [12, -18], [-1, 0], [-35, -19], [49, -4], [-15, 33], [56, 10], [-21, -10], [-9, 1], [-52, -12], [5, 34], [64, 6], [59, -2], [11, 19], [-8, -2], [20, 2], [36, 28], [27, 2], [-31, -18], [55, -5], [-13, -18], [15, -13], [-20, 30], [31, -15], [11, 25], [-7, -36], [-41, -4], [3, 39], [-9, 11], [57, 17], [40, 0], [24, -10], [-37, 7], [-57, 19], [7, 16], [16, 2], [-7, 31], [36, 30], [43, -22], [-7, -15], [15, 24], [2, 12], [32, -26], [5, -14], [-7, 9], [-16, -6], [-19, -1], [-10, -12], [17, 12], [-41, -6], [1, 5], [-20, 24], [-3, -51], [-12, -34], [9, -5], [-24, -2], [-9, -9], [7, 18], [39, -35], [25, -4], [-19, 2], [-15, 7], [-8, -32], [35, -14], [-36, -16], [-31, -3], [-28, -30], [-60, 2], [17, 29], [13, 14], [40, -18], [-38, 24], [-41, -24], [49, 20], [35, 5], [-35, -1], [65, -9], [-32, -26], [-35, -16], [-69, 2], [-16, 20], [-65, 13], [-41, -25], [20, -12], [-32, -18], [11, 22], [-26, 0], [31, -23], [43, 6], [60, 18], [40, 2], [-80, -4], [77, 4], [4, -24], [15, -4], [-43, -27], [10, -40], [-29, 0], [21, 11], [21, -46], [-24, 26], [9, -13], [37, 8], [-30, -32], [87, -3], [1, 29], [-51, 2], [8, -48], [48, 10], [-37, 2], [73, -7], [-53, 21], [-1, 13], [-3, 2], [-40, -14], [-31, 21], [-34, 16], [1, 39], [27, -21], [63, -9], [-2, -24], [15, -25], [13, -16], [-7, -63], [-48, 8], [35, 18], [49, -4], [-4, 22], [-59, 14], [20, -2], [8, -32], [7, -12], [-4, 4], [-1, -5], [-25, 41], [-41, -20], [-21, -3], [32, 24], [-14, -32], [65, -14], [-31, 23], [-11, -13], [-9, -65], [-9, -36], [-63, -13], [-20, -22], [28, 28], [-45, -26], [43, 0], [29, 18], [-25, 3], [-55, -32], [61, 2], [-25, 5], [1, 24], [-12, -42], [-15, 5], [-11, -1], [-55, 28], [-35, 24], [-60, 4], [-75, -11], [-12, -26], [-45, -20], [-17, -21], [-33, 11], [-44, 18], [-7, 1], [1, -28], [3, 44], [32, 16], [-28, 24], [20, -38], [-73, 8], [53, -7], [-44, -6], [7, -43], [15, -33]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3136_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3136_2_a_be();".
// 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_3136_2_a_be(:prec:=2)
    chi := MakeCharacter_3136_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_3136_2_a_be();".
// 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_3136_2_a_be( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3136_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-1, 2, 1]>,<5,R![-7, -2, 1]>,<11,R![-1, 2, 1]>],Snew);
    return Vf;
end function;