
// Make newform 3630.2.a.bk in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3630_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_3630_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_3630_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 := [-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_3630_a();"
function MakeCharacter_3630_a()
    N := 3630;
    order := 1;
    char_gens := [1211, 727, 3511];
    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_3630_a_Hecke(Kf)
    return MakeCharacter_3630_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 := [[1, 0], [-1, 0], [-1, 0], [0, 1], [0, 0], [-3, 0], [0, 1], [3, 0], [-3, 3], [3, -2], [1, -3], [4, 3], [9, -1], [-3, -3], [6, 0], [-3, -3], [9, -3], [3, 5], [4, 6], [3, 0], [-3, -1], [0, -6], [3, 2], [-6, 6], [5, -3], [9, 4], [5, 0], [0, 2], [6, -2], [0, 0], [6, -2], [9, -1], [-3, -6], [3, 8], [18, 2], [3, -5], [4, -9], [5, -3], [6, -10], [9, 3], [3, 3], [-7, 9], [-3, 6], [6, -2], [6, 2], [-2, -6], [-15, -2], [-7, -12], [0, 10], [4, 12], [0, -4], [24, -3], [6, -11], [-6, -6], [9, 12], [-3, 3], [6, -3], [-6, 12], [0, 0], [-3, 9], [18, 6], [24, 0], [21, 1], [0, 0], [-17, 3], [-3, -15], [-10, 9], [-15, 7], [-9, -14], [6, -12], [-36, 0], [24, -2], [-1, 18], [-21, 4], [-10, 15], [-6, -12], [-12, -12], [8, -9], [-3, -3], [6, -4], [12, -6], [-35, 3], [18, 11], [-16, -12], [6, 12], [0, 15], [-24, -6], [-21, -1], [-15, -4], [-4, -6], [-6, -21], [-6, 1], [-11, 0], [21, -7], [10, -15], [3, -1], [18, 12], [-27, 3], [3, -7], [-27, 9], [-42, 0], [-24, -10], [15, -10], [15, -3], [-36, 2], [-20, -6], [30, -3], [6, -24], [24, 6], [-6, 4], [6, -17], [21, -8], [-9, 18], [32, 3], [-11, -21], [-18, 12], [-4, 12], [30, -6], [3, -3], [-12, -6], [13, 15], [0, 24], [-33, 3], [6, -15], [-10, 9], [-3, -16], [37, 3], [12, -6], [-23, -6], [12, -8], [-3, -12], [-9, 15], [7, 15], [-32, 6], [18, 10], [-12, 19], [-15, 9], [-15, 7], [27, -9], [-15, 11], [27, 2], [6, 6], [5, 12], [-3, 12], [-1, -9], [27, 12], [9, -22], [-18, -15], [-4, -18], [-12, 6], [-27, -8], [21, -15], [-11, 3], [-24, -4], [-10, -24], [33, 0], [-15, -3], [-3, 15], [18, 8], [9, 2], [36, 3], [-6, -4], [24, -2], [18, -6], [6, 0], [33, -15], [-38, 0], [-9, -22], [6, -1], [-30, -12], [18, 2], [-4, -6], [-6, 33], [27, -3], [-1, 15], [-9, -15], [-27, -2], [36, 9], [30, -18], [33, -1], [13, -12], [9, 19], [-38, 12], [-36, 11], [12, 0], [-42, 3], [9, 6], [23, 3], [24, -10], [-6, -29], [19, 3], [3, 22], [-20, -3], [24, -3], [-9, -8], [-33, -12], [-18, 13], [8, -9], [12, -19], [9, 13], [6, -20], [-27, 17], [32, 0], [-6, -23], [36, 12], [0, 12], [23, -9], [-3, 22], [-18, 24], [10, -27], [6, 14], [12, -12], [-20, -6], [48, 0], [-6, 15], [25, 18], [12, 16], [36, 12], [-12, 6], [21, -9], [3, -31], [6, -2], [15, -9], [32, -6], [33, 0], [21, 15], [-39, -6], [-9, 6], [-12, -23], [54, -2], [26, 15], [48, 12], [30, 16], [12, -2], [1, 3], [-63, 1], [-59, 0], [-9, -29], [-3, -27], [-21, 6], [-12, -15], [-27, -28], [-20, 12], [-14, -24], [-30, -1], [-6, -7], [-26, 24], [42, 0], [9, 4], [-12, -22], [18, 34], [24, 0], [51, 15], [-26, -6], [-15, -1], [3, 3], [-1, -33], [33, 5], [-54, 12], [30, -22], [6, -7], [27, -12], [33, -1], [27, 8], [39, -6], [-26, -18], [-60, 9], [-3, 27], [-6, -16], [30, 4], [-1, 3], [2, 0], [-11, 15], [9, 13], [18, 2], [-38, 0], [0, 24], [-27, 11], [54, 13], [-24, 10], [24, 10], [-17, -9], [-9, -11], [-54, 2], [-18, -28], [-36, 0], [-19, 3], [-63, 1], [40, -12], [30, -28], [30, 24], [18, -27], [-30, -17], [-3, -29], [-33, -22], [-66, -4], [28, 18], [-63, -9], [24, -8], [27, 21], [-18, 16], [15, 13], [42, -10], [36, 15], [-14, -27], [-56, 6], [-36, -27], [58, 18], [9, -6], [45, 16], [-6, 10], [42, 3], [18, -4], [-11, -21], [39, 3], [-6, 17], [24, 0], [0, 15], [34, 0], [12, -24], [-15, 16], [-2, -6], [-3, 8], [7, -12], [-12, 19], [-25, 0], [34, -3], [-26, 18], [-30, 16], [-45, 21], [-36, 4], [12, -18], [-3, 15], [15, -12], [51, -8], [-42, 6], [41, -21], [-36, -21], [5, -24], [18, -23], [26, -24], [3, -18], [-18, 36], [-22, 36], [-24, 6], [-33, -33], [41, 15], [17, 39], [-18, 35], [6, -18], [0, 36], [11, -39], [48, -3], [-12, 37], [-18, 2], [0, 47], [18, -12], [-30, -14], [6, 4], [39, -27], [3, 6], [12, -32], [15, 33], [-63, 5], [-35, 9], [61, -15], [-33, 5], [0, 23], [24, 41], [-21, -21], [2, 21], [-54, -14], [-45, -18], [18, 22], [52, 0], [24, 0], [-18, -11], [-30, 16], [66, 2], [57, -13], [36, -33], [33, 12], [66, -5], [-6, -4], [36, -34], [-24, -6], [-14, -6], [32, -21], [-54, -22], [21, 21], [-1, -48], [-30, -12], [-69, -15], [-53, -9], [0, -18], [15, -19], [51, -25], [-45, -3], [-22, 39], [12, -28], [30, 10], [-39, -30], [-18, 5], [-36, 12], [-30, 42], [-15, 13], [38, 27], [33, -1], [40, -12], [-48, 0], [-45, 17], [-36, 24], [-12, 9], [0, -10], [18, 24], [12, -15], [-54, -22], [-52, 6], [-6, -48], [9, 25], [24, -3], [21, 2], [51, -21], [-60, -10], [5, 39], [18, 42], [0, -6], [48, -6], [-58, -9], [-78, -13]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3630_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3630_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_3630_2_a_bk(:prec:=2)
    chi := MakeCharacter_3630_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_3630_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_3630_2_a_bk( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3630_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-3, 0, 1]>,<13,R![3, 1]>],Snew);
    return Vf;
end function;