
// Make newform 3648.2.a.bk in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3648_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_3648_2_a_bk();".
// 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_3648_2_a_bk();".
// 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 := [-8, -1, 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_3648_a();"
function MakeCharacter_3648_a()
    N := 3648;
    order := 1;
    char_gens := [2623, 2053, 1217, 1921];
    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_3648_a_Hecke(Kf)
    return MakeCharacter_3648_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, -1], [1, 1], [-2, 0], [-1, -1], [-1, 0], [-4, 2], [2, 2], [-2, 2], [0, 2], [0, 0], [-1, 1], [-11, 1], [-2, -2], [0, 0], [5, 1], [0, -4], [-12, 0], [-3, 1], [8, 0], [-4, 2], [10, -2], [14, 0], [-2, 4], [-6, -2], [-10, 2], [4, -6], [10, -2], [2, 6], [7, -5], [-1, -1], [-13, 1], [1, 1], [8, 0], [2, 4], [0, -4], [6, -6], [-14, -2], [-10, 2], [22, 0], [-13, -1], [12, -2], [2, -4], [-7, 3], [4, 0], [4, -4], [-6, -6], [3, -1], [1, 1], [7, -5], [4, 2], [-1, -1], [-8, 4], [-19, 5], [-10, 2], [-4, 0], [-17, 3], [-22, 2], [19, -3], [-20, 4], [-20, 0], [-7, 5], [14, 0], [-20, 4], [4, 0], [10, -4], [-9, 3], [-21, -1], [30, 0], [-17, -5], [16, -4], [16, -6], [2, 10], [-6, -6], [23, -1], [-13, 7], [-4, -4], [2, -12], [-4, -10], [-2, 0], [2, 2], [-2, -4], [-10, -6], [11, -1], [-4, 8], [3, -5], [9, 9], [-13, 9], [3, 3], [24, -6], [8, 0], [32, 2], [13, -9], [8, 2], [10, -2], [-4, -4], [14, -2], [-15, 5], [14, -2], [5, 5], [-28, 8], [-26, -2], [0, 8], [11, 3], [-17, 7], [10, -8], [24, 0], [-8, 2], [-26, 2], [19, 3], [-21, 3], [20, -8], [21, -5], [-6, 6], [7, 9], [-5, -5], [-7, -7], [2, 2], [4, 6], [-16, -6], [-2, -2], [-14, -2], [1, -9], [-26, 4], [10, 12], [-21, 3], [11, -15], [-2, 0], [-21, -7], [0, 12], [24, -8], [5, -11], [-9, 15], [11, 3], [-28, -4], [8, 4], [20, -4], [-23, 1], [-14, -6], [9, -15], [-7, -9], [4, 4], [28, -6], [2, 2], [-18, -4], [-16, 8], [-21, -7], [28, -8], [30, -4], [-13, -13], [-29, 9], [-28, -4], [-26, 6], [-18, -6], [32, 0], [-2, 4], [-27, 13], [-34, 2], [20, -10], [-24, 12], [-24, -8], [28, -8], [-26, 10], [-20, 4], [16, -16], [-29, 3], [-28, -6], [-23, 1], [-12, -12], [-38, 0], [-8, -2], [-42, 4], [2, 6], [-3, -3], [-28, -8], [1, 1], [20, 12], [-15, -7], [-25, -3], [-14, 10], [22, 0], [0, -12], [-9, 15], [1, 1], [-26, 0], [12, 8], [14, 0], [16, -2], [26, 12], [-23, 1], [-18, -10], [16, -20], [12, -18], [14, 2], [29, -3], [-2, 0], [-14, -8], [-27, -3], [8, -4], [-40, 0], [-8, 6], [-50, 8], [-44, -2], [1, 1], [-1, -3], [40, -8], [51, 3], [42, 2], [-18, -8], [-14, 4], [-15, -5], [4, 4], [-22, 2], [24, 10], [-16, -12], [32, 8], [-26, -2], [19, -5], [-8, 6], [-16, 0], [50, -10], [-21, -11], [0, -12], [49, -3], [-20, 16], [-28, 8], [-40, 0], [-11, -11], [-19, -11], [-42, 14], [-22, 6], [12, 12], [25, 3], [7, 7], [29, 9], [-41, 7], [-12, 6], [-36, 0], [18, 6], [-11, 3], [4, 8], [24, 2], [46, -2], [9, -15], [-13, -3], [28, -8], [8, -20], [-15, -3], [22, -12], [5, -19], [-12, -6], [-40, 6], [31, 7], [20, 14], [-33, -1], [-6, 2], [-12, 24], [18, 4], [8, 0], [-24, 12], [-27, -7], [26, -8], [33, 9], [-6, 26], [34, -14], [1, 1], [-64, 4], [51, 3], [-10, 4], [-8, 12], [29, -3], [17, -9], [0, -2], [-24, 16], [-23, -11], [30, -4], [12, -2], [5, 17], [36, 0], [32, 0], [-31, -7], [-12, -10], [-5, -3], [43, -5], [-37, 15], [18, 6], [-35, 11], [-42, 6], [22, 4], [1, 13], [42, -6], [28, 4], [16, 18], [-30, -12], [-4, -12], [71, -1], [-46, 2], [-71, 3], [17, -3], [34, 10], [25, 11], [10, -2], [65, -5], [54, -8], [8, -4], [-10, -8], [-53, -5], [-50, 12], [15, 3], [74, -4], [32, -16], [-32, -12], [32, 14], [-46, 12], [39, -21], [14, 2], [-53, 11], [27, 3], [56, 4], [5, -3], [30, -18], [22, 2], [30, 0], [-44, 2], [-38, 18], [-68, 0], [64, 4], [-19, 5], [17, 1], [-14, -14], [32, 0], [9, -15], [55, -15], [-65, 7], [-66, -4], [2, 14], [7, 11], [-16, 12], [16, -6], [-33, -9], [-14, -14], [56, 0], [-4, 8], [-70, 2], [-50, -12], [-62, -6], [-18, 18], [-27, -3], [-18, 14], [44, -6], [-73, -1], [14, 18], [16, 18], [66, 6], [32, 2], [-20, 10], [-1, -1], [-2, 22], [-65, 3], [-6, -12], [4, -8], [20, -28], [13, 15], [2, 0], [-26, 28], [26, -18], [26, -24], [20, 2], [62, -2], [-43, -7], [-56, 4], [-55, 3], [-29, 3], [2, -22], [40, -2], [-25, 3], [21, -3], [-24, 22], [46, -2], [-55, -7], [-37, -15], [37, -11], [46, -18], [18, -6], [32, 12], [22, -12], [25, -21], [2, -10], [4, 2], [-22, 2], [24, -6], [-3, -1], [-24, 12], [14, 24], [-72, -8], [10, -14], [42, 2], [18, -12], [24, 2], [-39, -15], [-34, -6], [46, -2], [-60, 12], [-29, -7], [-29, 3], [-48, 12], [-2, 6], [-61, -1], [-14, 8], [-45, 3], [38, 14], [5, -5], [2, -12], [6, 12], [38, -22], [32, 0], [-14, 4], [38, -10], [24, -12], [2, 16], [17, 5], [78, 6], [-24, -14], [2, -10], [-34, 2], [73, 1], [55, -3], [65, 5]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3648_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3648_2_a_bk();".
// 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_3648_2_a_bk(:prec:=2)
    chi := MakeCharacter_3648_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_3648_2_a_bk();".
// 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_3648_2_a_bk( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3648_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-6, 3, 1]>,<7,R![-8, -1, 1]>,<11,R![-6, -3, 1]>,<23,R![-24, 6, 1]>,<31,R![-32, 2, 1]>],Snew);
    return Vf;
end function;