
// Make newform 2415.2.a.j in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2415_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_2415_2_a_j();".
// 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_2415_2_a_j();".
// 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_2415_a();"
function MakeCharacter_2415_a()
    N := 2415;
    order := 1;
    char_gens := [806, 967, 346, 1891];
    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_2415_a_Hecke(Kf)
    return MakeCharacter_2415_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, 1], [1, 0], [-1, 0], [-1, 0], [1, 1], [-3, -1], [-4, -2], [0, -2], [1, 0], [0, 0], [-3, 1], [-3, 1], [0, -2], [0, 4], [2, -6], [-1, 1], [-3, 3], [4, 0], [-8, -4], [-6, 0], [-5, 5], [5, 3], [-2, 0], [10, -2], [-4, 4], [4, 2], [-4, -2], [2, -2], [6, 0], [-9, 1], [-8, 0], [-9, 1], [-3, -1], [-21, -1], [4, 2], [-6, 6], [-14, -2], [-8, -4], [4, 4], [9, 5], [-2, -8], [10, -4], [21, 1], [-8, 6], [10, -2], [4, 6], [6, -6], [-2, 14], [-4, 8], [12, 4], [2, 2], [6, -4], [10, 0], [-2, 6], [-17, 3], [6, 10], [-24, -2], [-13, -9], [-4, 6], [-10, 0], [-24, -2], [-6, 12], [-6, 2], [-13, -3], [-26, -2], [-10, -10], [8, 0], [-9, -1], [-4, 0], [16, 2], [1, 5], [-7, -3], [4, 8], [7, -5], [11, -3], [-6, 8], [-12, 2], [1, -17], [-4, 14], [-8, -6], [20, 4], [6, -8], [21, -3], [8, -8], [-1, -17], [16, 10], [12, 0], [3, -1], [2, -4], [10, 12], [4, -16], [6, -18], [-2, -20], [6, 12], [-26, -6], [6, 12], [2, 4], [6, -10], [-12, -12], [-34, -6], [-14, -4], [3, -3], [12, 0], [-22, -8], [19, 5], [3, 17], [-24, -4], [-7, -19], [8, -6], [2, -20], [-6, -18], [7, 7], [-3, -25], [-16, 14], [19, -7], [12, 10], [16, -2], [18, 6], [10, -10], [-15, -11], [22, -4], [4, -14], [4, 10], [-4, 24], [-11, -15], [-6, -16], [26, -8], [-1, 1], [-8, -2], [-28, -8], [2, 10], [22, 2], [-25, -11], [-25, -5], [0, 14], [-10, 8], [-20, 14], [32, -2], [-10, 8], [14, -4], [33, -7], [-6, 16], [10, -24], [42, 2], [14, 0], [-6, -6], [25, -9], [-3, 13], [-29, -13], [16, 8], [-30, -8], [18, 8], [-30, 12], [-36, 4], [-26, -10], [11, -5], [-3, -9], [-36, -14], [-20, 12], [6, -6], [32, -2], [13, -5], [28, -12], [6, 26], [37, 7], [-6, -4], [6, 26], [5, 7], [-22, 8], [-23, 5], [-9, -5], [22, 4], [-27, -3], [-11, -15], [-1, 11], [22, 4], [-2, 18], [-30, 4], [-4, 8], [4, -28], [-14, 0], [6, 14], [-2, 12], [1, -19], [-30, -10], [50, 6], [14, -16], [-16, -24], [26, 0], [-15, -17], [-13, -23], [16, -18], [-35, -1], [-12, 26], [36, -4], [-24, 2], [14, 16], [29, 13], [-18, 20], [-48, 0], [-20, -10], [7, -1], [-37, -7], [34, 20], [14, -6], [-37, 3], [-4, 22], [20, -4], [-2, -20], [-37, -13], [20, -2], [6, 28], [-52, 0], [44, 8], [31, 5], [-12, 4], [30, -4], [-4, 30], [26, -6], [14, 26], [-62, 0], [18, 24], [-36, -4], [14, -10], [-18, -6], [26, 18], [-20, -2], [-6, -24], [-20, 14], [12, -14], [54, 4], [14, 4], [53, -1], [6, 4], [-16, 0], [-4, 4], [2, 16], [-1, -7], [-4, -14], [-45, -7], [-10, -18], [27, 23], [-32, 16], [38, -18], [-1, -5], [1, 27], [30, 26], [-2, 6], [-7, -1], [4, -20], [25, 13], [-6, 18], [-24, -12], [-40, 4], [5, 9], [12, -10], [14, 4], [8, -22], [7, 7], [35, 17], [14, 30], [60, -8], [26, 12], [-10, 26], [-9, -25], [22, 0], [-4, 10], [-42, -6], [8, 12], [-44, 0], [4, 14], [10, -34], [-34, -18], [13, -33], [-25, 17], [14, -22], [40, -8], [-50, -6], [8, -18], [-36, 8], [54, 6], [7, 33], [28, -20], [-16, 4], [22, -22], [6, 28], [-25, -21], [-65, -7], [-53, 11], [24, 30], [-18, -12], [36, -8], [0, 20], [-42, -6], [-40, 18], [-2, -40], [-6, -4], [15, -21], [27, -19], [26, 18], [-40, 20], [-21, -11], [35, 21], [-8, -4], [-1, 17], [-8, 14], [-16, 14], [16, 4], [81, 1], [-34, -4], [12, -32], [18, 20], [28, -22], [-40, -12], [56, 16], [-2, 40], [7, -19], [-28, 18], [-38, 6], [-48, 8], [-18, 0], [11, -25], [16, -26], [-14, -12], [-15, 15], [-14, -40], [73, -9], [-32, 0], [60, -12], [-25, -7], [22, 2], [-2, -30], [21, 5], [30, 10], [63, -7], [6, 2], [-60, 18], [-48, -6], [-10, 8], [20, 26], [18, 16], [17, -9], [-24, 2], [-35, -21], [33, 15], [46, 0], [-54, -8], [4, 24], [30, -10], [10, 8], [73, 9], [-56, 2], [48, 12], [-40, 8], [20, 22], [21, 41], [-14, 18], [36, -8], [22, -6], [4, 24], [61, 5], [-14, 36], [32, -20], [65, -11], [18, 14], [-6, 8], [5, -3], [38, 18], [-8, 22], [-12, 46], [41, 21], [-12, 16], [42, -20], [-14, -20], [-26, 20], [-35, 35], [41, -3], [72, -4], [-42, -18], [-29, 9], [38, 0], [-15, 35], [-2, 12], [20, -8], [-60, 2], [14, -22], [12, -24], [37, -5], [-38, -18], [32, 32], [-36, -22], [45, -3], [30, 32], [22, 26], [-7, -23], [-25, 15], [-32, 10], [-22, -24], [-65, 13], [6, 28], [84, -2], [10, 2], [8, -4], [-102, 0], [-42, 16], [-43, -27], [-49, -17], [-40, -8], [52, 2], [-11, -1], [-25, 9], [-38, -14], [-8, -28], [-5, -31], [41, -11], [-24, -6], [-18, -36], [14, -2], [-30, -32], [88, -8], [-78, -8], [-56, -16], [64, -4], [41, 27], [21, -21], [-33, -1], [-6, 6], [-40, -24], [3, 51], [23, 25]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2415_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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