
// Make newform 3630.2.a.bn in Magma, downloaded from the LMFDB on 16 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_bn();".
// 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_bn();".
// 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, -2], [-6, 1], [-3, -2], [3, 3], [-3, -2], [-5, -3], [-2, -3], [-3, 5], [-3, -1], [-6, 0], [3, -3], [-3, 3], [-3, 1], [4, 6], [3, -6], [-3, 1], [12, 2], [-9, 2], [6, 6], [5, 3], [3, -8], [-13, 0], [-12, 2], [6, -2], [0, 0], [-6, 6], [-3, 5], [3, 0], [9, 2], [6, 2], [-3, -1], [10, -3], [-7, 3], [-6, 2], [-9, -9], [3, -3], [-1, 9], [-15, 0], [-6, 2], [-6, -10], [-2, 6], [3, -8], [-1, -12], [-24, -2], [-8, -12], [-12, 8], [6, 3], [-18, 3], [-6, -6], [3, -6], [-21, 3], [18, -3], [-6, 12], [12, 4], [-3, 3], [6, -10], [-12, 0], [9, -1], [-12, 12], [7, -15], [27, -3], [-4, -3], [9, 13], [3, 10], [18, -4], [0, 12], [0, -2], [17, -6], [3, -2], [20, -9], [-6, 0], [12, 12], [-10, -3], [21, -9], [18, 8], [0, -6], [19, 3], [-12, -7], [32, 0], [-18, 0], [0, 9], [12, -6], [3, -7], [27, 8], [-4, -6], [-18, 9], [24, -5], [-17, 12], [-27, -1], [-8, -3], [9, 11], [6, 12], [9, -3], [15, 7], [-9, 1], [-6, -12], [-36, 2], [3, -10], [15, 3], [0, 2], [-20, 6], [-6, -9], [6, 0], [0, -18], [-6, -12], [18, -17], [21, -10], [-3, -24], [14, 3], [-5, 15], [6, 0], [-4, 0], [30, -6], [-39, -3], [-12, -18], [-5, -21], [-12, 4], [-15, 15], [-30, 3], [-16, 9], [3, -16], [7, -9], [12, 18], [-5, -18], [24, 4], [3, -2], [9, -21], [-23, -9], [4, 18], [-6, -2], [24, -15], [-33, 9], [-3, -19], [9, 27], [9, 17], [21, -4], [6, -6], [23, 0], [-3, 12], [29, -9], [3, 6], [21, 4], [0, -15], [20, 18], [-24, -18], [-27, 6], [-3, -9], [25, 9], [0, -4], [2, 0], [9, 6], [-9, -27], [21, -15], [18, 20], [15, 26], [36, -3], [-18, -16], [24, 14], [-42, 6], [6, 24], [-33, -3], [-2, -24], [-9, 4], [-6, 13], [-30, -12], [6, -10], [32, 6], [12, -9], [-9, -1], [41, -9], [-57, 3], [51, 4], [-36, -15], [-42, 2], [-21, 3], [-41, 0], [21, -11], [34, 0], [6, -25], [-24, 0], [-18, 15], [-51, 0], [23, 9], [12, -18], [24, 13], [-17, -3], [-21, 10], [-14, 9], [24, 21], [-33, -8], [-51, 6], [-6, 31], [-58, -3], [-54, -7], [-33, 13], [18, 4], [-33, -3], [-28, -12], [-6, -25], [-24, 0], [-24, 0], [29, 3], [9, -2], [-18, 24], [4, 21], [54, 2], [-12, 12], [16, 6], [-36, 12], [12, 21], [-11, -6], [-24, -12], [0, 24], [-12, -6], [27, 15], [-3, -7], [-18, 2], [-9, 21], [-16, -6], [-3, 12], [3, -1], [15, -24], [-33, 0], [0, -3], [30, -2], [-4, 21], [-12, 32], [-6, 0], [24, 10], [25, -27], [3, -11], [1, 12], [21, -29], [-15, -9], [3, -24], [12, 15], [-21, 22], [-20, 12], [-14, -12], [12, -13], [0, 35], [-2, 36], [-78, 0], [-33, 6], [12, 14], [18, -10], [-12, 12], [-15, 3], [10, -6], [63, -1], [39, -15], [53, 3], [21, 11], [-6, -12], [6, 6], [30, -27], [-45, -12], [-21, -17], [-9, 30], [9, -12], [22, -30], [-36, -15], [9, 21], [-30, 12], [-30, -8], [5, -9], [26, 0], [-35, -3], [3, 5], [30, -22], [-2, 0], [-36, 12], [15, -9], [-30, -17], [-12, -2], [0, 22], [13, -9], [-15, 1], [-66, 10], [-42, 16], [-48, 12], [53, -15], [39, 25], [4, 12], [-54, -4], [30, -12], [-30, 3], [0, 7], [-27, -11], [63, 4], [-6, -28], [-8, 42], [27, -9], [-36, -8], [51, 19], [6, 12], [9, 25], [-30, 6], [-12, -15], [-32, 9], [-20, -18], [12, -21], [-50, -6], [21, 36], [-3, 6], [-30, -26], [-6, -9], [42, -4], [13, 9], [21, 15], [-6, -25], [-24, 36], [-18, -3], [-26, 0], [-60, 12], [39, -22], [22, 18], [3, 8], [-11, -24], [-18, 7], [-13, 12], [-20, -3], [-26, 6], [18, -32], [9, -15], [-12, 32], [-12, 18], [27, 19], [-57, -12], [-27, 14], [30, -30], [23, 39], [18, 3], [5, 0], [-18, -31], [-70, -12], [21, 0], [18, 12], [14, 0], [-24, -18], [39, -27], [-13, 3], [-55, 9], [24, -31], [30, -18], [-36, 32], [-49, 3], [-60, -15], [36, -19], [30, 22], [6, -1], [30, -36], [-18, 22], [18, -8], [-15, -27], [51, -8], [60, 4], [9, -3], [33, -25], [-47, 27], [1, -21], [45, 17], [-12, 11], [-48, -1], [-81, 9], [-4, -27], [30, 10], [45, 6], [-6, -26], [-56, -12], [24, 12], [-24, 19], [-30, 24], [18, 14], [-3, -35], [-12, 15], [3, 18], [54, 3], [-18, 8], [-60, -6], [84, 6], [-50, -18], [-22, -3], [6, -10], [-33, -3], [-37, -36], [-18, 24], [3, 15], [19, 33], [-36, 18], [-33, -5], [9, -25], [75, -9], [-4, -45], [36, -28], [6, -26], [3, 36], [-30, -3], [12, -12], [-30, -42], [-57, 1], [-28, 21], [21, -31], [4, 12], [36, 24], [15, 15], [-36, 24], [48, 3], [48, 10], [54, 4], [48, -27], [6, 2], [8, -54], [66, 0], [-33, 13], [-36, 33], [21, -16], [21, -9], [0, -22], [29, 21], [-18, -6], [-72, 6], [12, -54], [-4, -57], [0, 29]];
    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_bn();".
// 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_bn(: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_bn();".
// 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_bn( : 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, 6, 1]>],Snew);
    return Vf;
end function;