
// Make newform 2415.2.a.g in Magma, downloaded from the LMFDB on 24 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_g();".
// 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_g();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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], [1], [3], [-4], [-6], [-1], [-1], [6], [8], [-10], [-3], [-10], [-3], [-9], [-3], [11], [-10], [0], [2], [-10], [0], [0], [2], [-3], [-1], [-12], [-10], [-6], [-13], [15], [3], [-16], [3], [-19], [17], [11], [-15], [6], [12], [-10], [-15], [-25], [12], [-13], [5], [-16], [24], [-13], [6], [-30], [17], [-24], [3], [21], [18], [26], [-19], [18], [32], [-12], [32], [33], [-19], [30], [-7], [8], [-6], [8], [-18], [0], [-19], [26], [-34], [36], [18], [8], [15], [20], [-24], [14], [27], [-25], [8], [18], [-6], [-28], [18], [-25], [30], [12], [8], [0], [-16], [18], [-27], [24], [-31], [-13], [-28], [-6], [0], [15], [-16], [-4], [-27], [18], [36], [-10], [38], [8], [-18], [-28], [-16], [3], [-1], [-12], [36], [36], [-13], [23], [-12], [24], [-28], [-51], [8], [-24], [47], [-10], [32], [33], [-4], [8], [-45], [-34], [36], [-25], [-24], [-36], [-16], [-18], [-7], [-3], [38], [-24], [44], [3], [14], [24], [5], [-48], [-28], [36], [-28], [-12], [-4], [-6], [23], [-24], [-42], [-21], [8], [-12], [-21], [-42], [41], [2], [44], [15], [3], [-22], [-57], [2], [-22], [-54], [-37], [6], [41], [-10], [53], [-42], [-25], [-9], [-39], [-42], [-13], [-40], [41], [-24], [38], [-48], [2], [57], [33], [-66], [56], [14], [42], [-3], [9], [-10], [-52], [-13], [18], [-51], [20], [54], [12], [50], [-49], [15], [20], [18], [0], [-10], [-7], [-6], [60], [36], [23], [-49], [-36], [-52], [33], [41], [66], [-30], [8], [-48], [-13], [44], [50], [-60], [-37], [54], [-7], [54], [18], [-48], [-21], [2], [50], [-1], [-69], [57], [-16], [-12], [8], [-9], [50], [12], [-33], [-73], [78], [-66], [-46], [-25], [21], [-46], [-28], [57], [38], [29], [-15], [-1], [-39], [60], [-46], [6], [38], [38], [26], [20], [38], [8], [66], [59], [-52], [-42], [21], [-52], [6], [2], [62], [6], [-34], [27], [14], [-42], [27], [12], [-36], [0], [14], [72], [8], [-15], [-75], [-46], [-22], [-42], [56], [66], [86], [-31], [72], [5], [-9], [-82], [39], [54], [-15], [-16], [-75], [-43], [9], [-30], [-1], [-30], [17], [20], [-27], [29], [-45], [-43], [38], [-28], [45], [-87], [-82], [0], [-16], [21], [-58], [87], [74], [-90], [-40], [32], [-10], [57], [-45], [-64], [-45], [78], [20], [-7], [-78], [30], [-40], [17], [-24], [-37], [-10], [-69], [18], [-6], [78], [72], [80], [-21], [6], [33], [20], [-91], [-15], [56], [-22], [78], [8], [6], [63], [-7], [-34], [24], [21], [11], [-30], [44], [0], [6], [-43], [-78], [44], [-69], [-73], [-40], [50], [90], [26], [-33], [-24], [-22], [-39], [86], [-25], [-24], [62], [-96], [62], [0], [20], [78], [15], [20], [2], [6], [-76], [-12], [20], [-60], [45], [-10], [-52], [30], [72], [-106], [-84], [-24], [66], [83], [-30], [48], [14], [3], [-105], [-78], [20], [45]];
    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_g();".
// 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_g(:prec:=1)
    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_g();".
// 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_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2415_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![0, 1]>,<11,R![-3, 1]>,<13,R![4, 1]>],Snew);
    return Vf;
end function;