
// Make newform 3192.2.a.s in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3192_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_3192_2_a_s();".
// 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_3192_2_a_s();".
// 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 := [-3, 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_3192_a();"
function MakeCharacter_3192_a()
    N := 3192;
    order := 1;
    char_gens := [799, 1597, 2129, 913, 1009];
    v := [1, 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_3192_a_Hecke(Kf)
    return MakeCharacter_3192_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], [-1, 1], [1, 0], [-4, 0], [2, -2], [-5, 1], [1, 0], [0, -4], [-5, 1], [-2, 0], [2, -4], [-2, -4], [-2, 4], [-5, 3], [-1, 5], [-4, -4], [-6, 4], [2, 2], [-1, 3], [0, -6], [-4, 4], [3, 3], [-6, 0], [-2, 8], [-3, -1], [4, -4], [-7, -3], [-8, 2], [15, 1], [-10, 2], [9, 1], [-2, 4], [2, 10], [0, -2], [10, 2], [-10, 4], [-6, -4], [6, 2], [2, -8], [-13, -1], [-14, 4], [12, 4], [2, 4], [-6, 4], [2, 10], [-8, 0], [-2, -12], [10, -10], [-8, 6], [0, -10], [-6, -2], [-10, 12], [7, -5], [-8, 6], [6, -2], [-24, -2], [20, 0], [-14, -6], [-3, -1], [2, -6], [-14, -8], [10, 4], [5, -7], [26, -4], [-21, 1], [-2, 6], [12, -6], [2, 10], [-2, -12], [-3, -13], [16, 8], [2, -10], [10, 12], [10, 6], [18, -10], [-24, 6], [6, 0], [-9, 9], [-6, 2], [21, -7], [-20, 2], [-15, -15], [10, 8], [10, -8], [6, 6], [11, 5], [6, -10], [-15, 3], [-16, 0], [-3, -3], [-3, 13], [-8, 8], [18, -14], [12, -8], [-27, 1], [-12, 10], [-12, -14], [38, 0], [-22, 0], [24, 4], [0, -22], [18, 10], [-7, -13], [-4, 0], [-6, 12], [15, 3], [15, -3], [-13, 3], [30, -8], [-4, 12], [-34, 6], [2, 12], [-22, 2], [-14, -12], [5, -1], [-10, 6], [19, -5], [-18, -16], [1, -7], [2, 2], [30, 8], [4, -2], [-33, 3], [16, 8], [-26, 12], [22, 10], [27, -9], [-8, -16], [20, 10], [-34, -8], [-3, 5], [14, 6], [6, -12], [-9, -11], [2, 4], [22, 12], [18, -8], [-6, 12], [22, 16], [36, 0], [-24, -10], [2, 12], [-9, 15], [18, -16], [8, 20], [34, 0], [6, -8], [24, 8], [-5, -21], [6, -24], [25, -1], [-8, -12], [10, 18], [0, -20], [25, 13], [24, -16], [11, 9], [46, 4], [20, 6], [24, -8], [-17, 9], [-10, -12], [-36, 12], [3, 13], [-12, 12], [4, -20], [-50, 4], [4, 18], [33, -5], [-7, -19], [2, -14], [-6, 6], [10, 6], [-16, 8], [5, 3], [-38, 0], [-2, -20], [2, -12], [-10, 0], [-16, -8], [-44, 4], [36, -10], [6, -24], [-4, 16], [-3, -17], [-16, 6], [-34, -4], [24, 10], [1, 25], [-2, -6], [-24, 0], [6, 6], [-32, 6], [-12, -16], [-16, 10], [14, -14], [-26, 12], [-3, 19], [-23, -15], [-17, 21], [24, -24], [-42, 12], [-42, -14], [-19, -27], [3, -27], [58, 2], [-33, 7], [36, 18], [-42, -12], [-34, 14], [-41, 1], [-50, 8], [-26, 18], [24, -28], [26, -10], [-26, 12], [40, 14], [9, -3], [36, 2], [-20, -6], [8, 16], [-33, 9], [8, -16], [12, 8], [2, 40], [-8, 26], [-19, 17], [-14, -8], [-14, -2], [-42, -4], [46, 0], [-44, 4], [13, 7], [-24, 20], [-5, -1], [32, 18], [-62, -4], [22, 18], [-6, -18], [9, -15], [-28, -4], [-2, -26], [14, 32], [-60, -10], [15, -5], [-50, 6], [22, 2], [-64, 4], [-16, -8], [-50, 16], [-27, 19], [-2, -42], [30, -14], [13, -25], [-36, 4], [-26, 8], [14, 4], [-12, 10], [-26, 12], [-36, 0], [-15, -35], [-4, 2], [2, -26], [7, -11], [-70, 0], [1, 7], [21, -29], [-32, -24], [-36, 2], [-6, 8], [-8, -4], [-56, -6], [12, 12], [-10, 8], [-38, -14], [-30, 26], [10, 16], [-6, -16], [27, -1], [74, 6], [-26, -16], [-3, -23], [-26, 8], [40, -20], [30, -22], [-34, -24], [69, -5], [-2, 10], [52, 2], [-56, 10], [17, 13], [-39, 19], [56, 0], [6, -28], [39, 25], [-18, -36], [23, -23], [-6, 34], [10, -18], [14, 4], [-41, -3], [-56, 8], [35, 3], [-2, -32], [-56, -14], [-45, 11], [50, 6], [54, 10], [6, 6], [-23, 29], [28, -26], [33, -13], [38, -10], [60, -12], [62, 0], [11, -33], [5, -19], [16, 18], [2, -16], [4, 32], [6, -14], [-32, 6], [-2, -10], [-24, 10], [-2, 20], [16, 24], [0, 28], [13, 13], [34, 0], [-26, -8], [21, 19], [-58, 6], [-29, 11], [52, 0], [-27, 5], [14, 16], [-6, 28], [-56, 2], [-24, 4], [-18, -24], [-22, 20], [38, 20], [-20, 32], [-17, -3], [3, -49], [-20, -38], [12, -20], [-16, 28], [-43, -9], [12, 24], [-40, 6], [-2, 12], [28, 12], [42, 8], [-12, -26], [-57, -1], [-5, 11], [32, 2], [-5, 31], [-34, -24], [23, -3], [75, -1], [-25, -25], [30, -26], [74, -4], [27, 37], [-14, 22], [-6, -4], [-84, 0], [70, 8], [-6, 38], [-5, 9], [52, 0], [-38, -4], [12, 8], [56, -8], [-10, -12], [15, -3], [-6, -44], [4, 6], [18, 4], [-38, 4], [78, 12], [34, 0], [-34, 26], [6, 16], [-76, 10], [-50, 8], [-38, 6], [-32, -22], [2, -4], [-36, 8], [8, 12], [13, 45], [28, 26], [12, -28], [30, 12], [26, -2], [12, -42], [26, -26], [-38, -20], [-32, 0], [-8, -14], [-48, -6], [-22, 42], [14, -12], [53, -17], [12, -24], [-31, 37], [26, -8], [64, -10], [15, -9], [26, -36], [6, -32], [-15, 11], [75, 15], [-14, 4], [-35, -21], [-36, -12], [105, -1], [2, -48], [18, 14], [8, -8], [10, -38], [-14, 8], [59, 23], [-84, 14], [34, 14], [-25, -41]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3192_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3192_2_a_s();".
// 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_3192_2_a_s(:prec:=2)
    chi := MakeCharacter_3192_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_3192_2_a_s();".
// 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_3192_2_a_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3192_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-2, 2, 1]>,<11,R![4, 1]>,<17,R![22, 10, 1]>],Snew);
    return Vf;
end function;