
// Make newform 1815.2.a.v in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1815_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_1815_2_a_v();".
// 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_1815_2_a_v();".
// 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 := [11, 6, -8, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [1, -5, 0, 1], [-4, 0, 1, 0]];
    Rf_basisdens := [1, 1, 3, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_1815_a();"
function MakeCharacter_1815_a()
    N := 1815;
    order := 1;
    char_gens := [1211, 727, 1696];
    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_1815_a_Hecke(Kf)
    return MakeCharacter_1815_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, 0, 0], [-1, 0, 0, 0], [-2, -1, 0, 1], [0, 0, 0, 0], [-4, 1, 0, 0], [-1, 2, -2, 0], [-1, 0, 1, 1], [1, 1, -2, -2], [6, 0, -4, 1], [3, 2, 0, 1], [-3, -1, 6, 0], [-4, -1, 2, 1], [-4, 1, 1, -1], [2, 3, 2, -1], [-1, -1, 2, 3], [-1, 1, -3, -2], [2, 0, -2, -3], [4, 1, -6, 0], [-3, 2, 2, 3], [-12, -1, 3, -2], [3, -2, -3, -4], [5, 2, -4, 1], [-1, -2, 3, 2], [-7, 1, 0, 1], [-1, -3, -1, 2], [-3, 0, -5, -1], [7, 2, -9, -3], [3, 3, -3, -5], [1, -4, 4, -1], [-3, 3, -11, -3], [0, 0, 11, 1], [-4, -5, 2, 4], [-2, -3, 3, 3], [0, 1, -1, -4], [-10, 4, 7, 4], [0, -2, -10, -1], [5, -4, -1, 2], [4, -6, -2, -4], [-2, -1, -1, -4], [5, -2, 9, 1], [-12, 0, 11, 5], [-6, -2, 2, -3], [-9, -4, -2, 6], [-2, -1, -3, 5], [0, -6, 9, -1], [2, -1, 8, 3], [-4, -2, 9, 2], [5, 7, 3, -4], [5, -9, 9, 3], [-7, 3, 8, 0], [-10, 1, 8, 1], [-1, 4, -6, 0], [11, -2, -12, -2], [3, -2, -5, 7], [2, -5, -3, 5], [-11, -1, -1, -1], [7, -5, -9, 2], [-1, 2, -12, -1], [1, 0, -2, -6], [3, 3, -7, -10], [-14, 2, 3, 7], [-9, -3, 10, -5], [-11, -1, 8, 1], [5, 10, -9, -2], [6, 6, -20, -2], [-4, 1, -6, 5], [-1, 6, -9, -1], [11, -3, -4, 0], [-11, 2, 4, 5], [-7, 0, 11, 0], [-12, 1, 16, 3], [8, 5, -12, 3], [-3, -10, 6, -3], [-18, -3, 11, 5], [7, -7, 4, -1], [9, -3, -4, 3], [-15, 11, 9, 4], [8, -1, -8, -2], [2, 8, -24, -4], [14, 3, -2, 5], [7, 13, -12, -1], [5, 10, 3, -2], [-3, 6, 8, -5], [2, -1, 0, -10], [11, 0, -23, 0], [2, 4, -1, -9], [-21, -2, 20, 3], [0, 0, 7, 0], [1, 0, -3, 4], [-10, -1, 13, 0], [1, -6, 13, 1], [21, -8, 9, 2], [4, 5, -9, -3], [-12, 0, -6, -7], [-7, -2, 12, 10], [2, -1, -4, -4], [-12, -9, 3, 6], [-12, -8, 8, -7], [7, 1, -12, 4], [-8, -8, 9, 6], [-12, -3, 18, -3], [-11, -7, -6, 7], [-5, 8, -23, -7], [-11, -4, 15, 11], [-19, -2, -5, -1], [-8, -3, 10, 3], [-22, 4, -7, -2], [-12, 2, -1, -8], [-18, 3, 5, -2], [-13, 7, 3, -6], [-23, 11, -6, 0], [-9, 4, 16, -1], [-19, -2, 8, 2], [7, 7, -17, -6], [-3, -1, 11, 11], [4, -4, -1, -4], [20, 8, -11, -7], [34, 2, 1, 0], [21, 2, 14, 0], [-3, 12, -30, -8], [-24, -6, 7, -1], [0, -5, -5, -9], [2, -14, -3, -2], [-7, 13, -12, -6], [5, -1, 1, 2], [9, -10, 1, 4], [1, 13, -11, 3], [30, -2, -10, -8], [12, 6, -24, -9], [-7, -9, 6, 9], [8, 14, -1, -11], [-5, -7, 13, 14], [2, 8, 8, 2], [-21, -4, -10, -1], [-19, -4, 18, 2], [8, -10, 1, -7], [-4, -10, 11, 15], [2, 4, -3, 1], [7, 0, -17, -5], [-18, 11, -3, 0], [20, 7, -12, -8], [-6, -7, 13, -6], [12, 0, 13, 1], [29, -8, -8, -9], [-3, -6, 4, 0], [-8, 3, -3, -10], [-16, -7, -8, 7], [-14, -7, -3, 0], [7, 9, -4, 8], [16, 4, -6, -11], [17, -12, -8, -5], [-25, 4, 15, 4], [23, 1, -19, 0], [1, 2, -30, 0], [-10, 14, -25, -2], [13, -8, -9, -1], [-4, -12, 13, 3], [-7, 11, -15, 4], [-13, -8, 12, 4], [16, 3, -41, 1], [-16, -13, 8, -2], [4, 5, -14, 6], [-24, -6, 22, 0], [7, 5, -3, -1], [-16, -5, 12, 13], [-2, -10, -11, 3], [18, -2, 0, -2], [4, -4, 15, -1], [2, -5, 18, 3], [33, 1, -16, -10], [-9, -3, 24, 3], [-8, -6, 7, -13], [-16, -4, 17, 2], [-12, -21, 6, 3], [15, 4, -17, -10], [5, -2, -10, -4], [-20, -2, 5, -10], [-38, -3, 18, -2], [22, -9, 0, -3], [-14, 5, 6, -3], [-24, 0, 25, 0], [40, 7, -6, -2], [-9, 0, 0, -8], [-56, -1, 9, 0], [-16, -3, 14, 11], [0, -9, 13, 17], [-12, 5, -6, 10], [24, -2, -24, 2], [-16, 7, -22, -8], [-19, 12, -20, -3], [10, 14, -6, 5], [-22, 1, 8, -6], [11, 2, -2, -15], [-9, -5, 35, 9], [1, 1, 11, -5], [-37, 1, 20, 11], [33, 8, 3, -1], [-31, 3, 2, 3], [-6, -5, 38, 0], [10, 1, 17, -10], [12, -1, 6, -11], [17, 0, 6, -7], [-12, -2, 5, 3], [18, 13, 1, 3], [0, 17, -4, -4], [4, 5, -3, 7], [-1, -14, 35, 14], [-21, -9, -10, 3], [-13, -11, 18, 5], [-2, 8, -9, -1], [5, -15, 5, 11], [-23, 4, 48, -1], [8, -7, 2, -6], [10, -1, -29, -8], [-21, -1, 24, 18], [-3, 1, -12, -10], [-41, 2, -6, -8], [6, 18, -5, -5], [21, 6, 16, -1], [-9, 13, 26, -4], [3, 16, -4, 8], [-2, 11, -3, -9], [-34, -11, 19, -12], [-3, 4, -17, -2], [7, 10, -15, 3], [-29, 5, 1, -10], [41, -5, 4, 2], [8, 3, -12, 11], [8, -16, -5, -8], [-14, -6, 20, -5], [36, 1, 15, -2], [-26, -1, 27, 8], [-12, -12, 42, 4], [12, 4, -33, 9], [-17, -2, 35, 14], [-24, -4, 30, 6], [1, -19, 21, 13], [-12, 11, -8, 9], [41, 0, -4, -5], [16, -8, 2, -1], [-13, -29, 11, 5], [46, -11, -24, -16], [-2, 2, 17, -6], [14, -12, 5, 0], [32, 9, -37, 10], [25, -7, 11, 3], [0, -5, -5, 7], [22, 17, -18, 9], [47, -8, -3, -1], [11, 8, 15, -4], [-2, -1, 21, -5], [2, -6, -1, 3], [-2, 3, -34, -9], [-35, 7, -7, -4], [21, 4, -2, 3], [-27, -8, 21, 9], [2, -6, 24, 9], [-18, -17, 35, 11], [-19, -19, 6, 9], [-15, 11, 3, 3], [49, -6, -8, -8], [18, -6, 21, 6], [-9, -13, 12, 16], [36, 6, -8, -13], [-1, 24, -3, 5], [16, -4, -30, -4], [-4, -1, -11, 18], [11, -6, 4, 2], [-4, -12, 38, 6], [8, 10, -13, -25], [-35, -14, 25, -13], [18, -21, 21, 1], [6, -23, 54, 18], [-53, -1, 15, -7], [36, 3, -32, 3], [16, -7, -15, 9], [34, 11, -16, 10], [24, 0, -13, -18], [-24, 8, 20, 1], [40, -8, -17, -16], [44, 2, 2, 2], [-12, 8, 35, -2], [-5, -25, 12, 7], [-11, -4, -12, 6], [-32, 2, 21, -8], [-32, -16, 11, 13], [45, 14, -13, -4], [0, -5, 9, 9], [-34, 10, 24, 9], [-22, 19, -12, 3], [-50, 2, 26, -1], [-24, 5, -4, -10], [-14, 22, -23, -15], [26, 4, 11, -5], [59, -5, -24, -7], [-35, 3, 29, 11], [-35, -4, 15, 13], [36, 2, -41, 0], [-17, -3, 30, 10], [3, 3, 10, 2], [11, -8, -15, -4], [-20, 20, 0, -4], [-56, -5, 17, -4], [6, 4, 15, -18], [33, -11, 5, -9], [-18, -19, 47, -2], [-38, -2, 18, -3], [33, -7, -40, 2], [-3, 10, -7, 15], [-38, 9, 16, 12], [-36, -6, 20, -7], [52, -4, -61, -12], [55, 2, -14, -13], [4, 14, 18, -9], [5, 13, -21, -14], [-10, -14, 15, 4], [-1, 1, -27, 11], [-24, -25, 22, -3], [-49, -7, 8, 18], [-26, -2, 1, 12], [-9, -22, -20, 14], [18, -14, -1, 17], [-19, -20, 15, 31], [-4, 4, -30, -3], [28, 13, -48, 6], [74, -4, 0, -1], [25, 17, -24, -13], [-2, -21, 26, -7], [-26, 7, -20, 2], [-27, 3, 9, 12], [28, -1, -46, 7], [13, -20, -14, 2], [-17, 1, 14, -3], [-35, 12, -3, 9], [2, -8, -44, 5], [-13, 0, 25, 2], [-35, -12, 10, -2], [4, -18, 24, -7], [-25, -21, 43, 8], [-16, -17, 9, 22], [18, 1, -38, -12], [-18, 7, 13, -20], [13, 29, -36, -4], [4, 11, 6, -17], [23, -13, -19, -1], [-40, -14, 29, 15], [-31, -15, 9, -13], [26, 3, -50, -6], [-30, 14, -4, 14], [-22, 2, 18, -16], [-7, -36, 21, 6], [-2, 17, -38, -27], [-36, -3, 3, -9], [16, 3, -4, 6], [9, 7, 22, 5], [29, 18, -16, -7], [-37, -3, 41, -9], [24, 18, -18, 18], [-13, -12, 8, 23], [-20, 3, 30, 7], [-15, 3, -3, 4], [18, 7, -10, -2], [16, 22, -13, 9], [-11, -10, 46, 20], [-6, -2, -13, 14], [-39, -20, 22, 8], [2, -7, 0, -1], [53, -6, -15, -7], [13, 4, -19, -13], [-21, 18, 9, -13], [8, 10, -30, -2], [-22, -10, 26, 24], [2, 16, -52, -11], [-26, -6, 21, 16], [16, 16, -61, -21], [-37, -15, 2, 7], [3, 6, -13, 1], [-29, 0, -11, -4], [37, -9, -51, 3], [-16, -3, 41, 6], [-13, -2, 43, -1], [13, -7, -18, 6], [-5, -26, 11, 20], [6, -15, -22, 4], [9, -1, 4, 25], [7, 9, -30, 12], [34, 5, -38, -18], [-12, -9, 0, -16], [26, 6, -38, -11], [3, 18, -27, 3], [-48, 1, 43, 13], [-11, 18, 7, -19], [9, 17, -5, -9], [-34, -5, 53, 3], [57, -8, 6, 2], [60, -1, -21, 0], [-28, -2, 11, 3], [-21, 18, -18, -15], [18, 6, -28, -13], [13, 2, -24, 6], [-19, 7, 27, 11], [13, -4, -30, -14], [13, 15, 4, -22], [-20, 3, 7, 1], [-21, -16, 18, 25], [31, -9, -12, 4], [-9, -2, 2, -10], [54, 0, -11, 2], [41, 2, -2, -19], [1, 9, 18, 8], [25, 11, 6, -19], [11, 32, -8, -10], [10, 24, -45, -15], [-1, 13, -5, 10], [19, 2, 15, 16], [3, -10, -7, -4], [-1, -20, 20, 1], [6, 7, 2, -28], [-40, -14, 36, 9], [13, 5, -18, 5], [48, 18, -47, 11], [19, 0, -25, 27], [-11, 5, -39, -15], [7, -2, 33, -2], [27, 14, -14, -11], [16, 11, -16, 12], [-51, 3, 36, 26], [2, -11, -13, -6], [3, -3, 9, -6]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1815_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1815_2_a_v();".
// 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_1815_2_a_v(:prec:=4)
    chi := MakeCharacter_1815_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_1815_2_a_v();".
// 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_1815_2_a_v( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1815_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![11, 6, -8, -1, 1]>,<7,R![-99, -57, 8, 8, 1]>],Snew);
    return Vf;
end function;