
// Make newform 1425.2.a.r in Magma, downloaded from the LMFDB on 17 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1425_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_1425_2_a_r();".
// 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_1425_2_a_r();".
// 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 := [-1, -1, 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_1425_a();"
function MakeCharacter_1425_a()
    N := 1425;
    order := 1;
    char_gens := [476, 1027, 1351];
    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_1425_a_Hecke(Kf)
    return MakeCharacter_1425_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], [0, 0], [-1, -2], [-2, -2], [-2, 2], [-4, 4], [1, 0], [6, -4], [-7, 4], [-8, 0], [-6, -2], [-1, -4], [8, -8], [4, -2], [-1, 0], [-3, 6], [-5, 4], [0, 6], [-5, -6], [-7, 12], [-2, 4], [-4, 6], [-5, 0], [0, 6], [2, 10], [-6, 10], [1, -6], [-14, -2], [14, 0], [4, -12], [-2, -12], [8, 0], [11, -2], [10, -10], [-12, 8], [-5, -4], [-17, 2], [5, 6], [17, 4], [-9, -2], [4, -4], [-16, 16], [-14, -4], [8, -10], [-17, -6], [12, -20], [-8, 4], [5, 6], [6, 8], [4, -10], [6, -22], [14, -24], [0, 4], [-5, -4], [16, -14], [-18, 16], [9, -14], [9, -12], [22, 0], [4, 0], [-10, 8], [-2, 10], [8, -12], [-18, 24], [13, -20], [2, -20], [18, 0], [16, -6], [-19, 8], [-8, -16], [10, 10], [-8, -8], [-2, -8], [2, -14], [-3, -6], [22, 6], [-10, -4], [-10, -16], [-12, -6], [-12, 14], [12, -10], [-27, 18], [-12, 2], [-10, 0], [10, 8], [-19, 28], [11, 4], [2, 10], [-4, -4], [-6, -2], [18, -6], [-10, 26], [16, -8], [27, -14], [-6, 10], [39, -8], [-13, 20], [28, 2], [10, -16], [-6, -2], [-28, 12], [11, -14], [-27, 24], [-19, 2], [2, -28], [-16, 8], [38, 2], [0, 0], [2, 10], [10, -14], [-25, 8], [0, 26], [-29, -2], [40, 4], [-6, 16], [25, -2], [-12, 20], [-30, 18], [40, 0], [-20, 24], [2, 14], [-5, -24], [-7, 2], [-8, 20], [-14, -8], [7, 16], [12, -4], [-1, -22], [-5, 8], [-23, 26], [-9, 26], [-16, 26], [-49, 4], [4, -14], [-13, -4], [1, -24], [42, -18], [-19, 4], [-8, 26], [-12, -2], [2, 0], [41, 6], [-36, 8], [24, -18], [-21, 22], [-51, 0], [-7, 0], [19, -18], [1, -34], [6, 14], [2, 30], [-7, 22], [8, 0], [-16, 8], [-23, 10], [-27, -6], [-26, 12], [-13, 32], [-10, 4], [-36, 28], [-29, -4], [1, -26], [-11, -14], [50, -4], [-16, 0], [12, -10], [6, -36], [14, 22], [8, 22], [13, -26], [-28, 0], [-38, 20], [-2, -28], [-18, 6], [44, -8], [-3, 10], [22, -30], [-24, 36], [23, 24], [-48, 12], [13, -42], [-24, -14], [39, -12], [-36, 20], [4, -18], [-8, 12], [50, -12], [2, 26], [-38, -10], [28, -28], [38, 12], [-40, 14], [-6, 16], [58, -10], [6, -24], [25, -36], [-17, -8], [52, -18], [-50, -2], [-30, 40], [46, -18], [0, 16], [-32, 34], [54, 2], [28, -20], [-16, -28], [-41, 30], [16, -12], [10, -6], [-7, -20], [32, -20], [7, -26], [-57, 10], [-11, 2], [-20, 14], [13, 10], [66, -8], [-12, -20], [10, 8], [-18, 30], [-30, 60], [50, 0], [7, -26], [12, -8], [31, 8], [-25, 48], [-23, 46], [50, -14], [12, 10], [15, 8], [10, 10], [-16, -4], [-9, -8], [37, 14], [-26, -12], [47, -24], [42, -6], [-10, -20], [17, -10], [45, -22], [55, 14], [-12, 12], [-48, -4], [-14, 16], [-28, -14], [-3, 22], [-56, 16], [22, -14], [-24, -14], [-17, 20], [-18, 10], [60, -4], [-2, -26], [-24, 26], [64, -8], [27, -60], [14, 8], [27, -8], [-58, 12], [12, -6], [-25, -14], [65, -20], [2, -16], [-34, 4], [14, -28], [-35, 0], [40, -36], [-20, 48], [28, -18], [-32, 18], [-48, -18], [-22, 12], [-15, 10], [72, 2], [12, 24], [4, -52], [-58, 6], [-38, 30], [0, 44], [19, -30], [-15, -6], [26, 24], [-68, 0], [-27, -30], [-38, 20], [-2, -8], [22, -8], [-5, -30], [-43, -4], [-22, -22], [-38, 22], [-9, -4], [-3, -50], [-26, 20], [-6, 12], [12, -50], [30, -42], [-40, 0], [-36, 68], [27, -16], [-10, -24], [-24, 8], [33, 2], [4, 16], [-4, -6], [16, 24], [2, -44], [-54, -2], [-26, 20], [-30, -32], [-50, 0], [11, -48], [18, -28], [8, 0], [-16, 22], [2, 16], [-35, -6], [-6, 0], [-46, 22], [-22, 28], [-5, -4], [-39, 12], [58, -48], [14, -20], [2, 0], [-54, 18], [22, -26], [8, -40], [24, 20], [-18, 20], [23, 20], [-5, 10], [42, -6], [29, 6], [-30, -14], [18, -26], [61, -44], [-31, 56], [-49, 74], [-44, -4], [-30, -14], [-71, 32], [-2, 18], [31, 36], [47, 6], [-11, -24], [2, 2], [-48, 0], [8, 50], [26, -38], [-26, -32], [-52, 68], [-22, 2], [20, 20], [-54, 36], [42, -24], [60, -26], [-2, 10], [-72, -8], [3, 20], [-36, 36], [27, -18], [36, 8], [48, 20], [-20, -12], [-32, 50], [-28, 24], [4, -24], [-62, -2], [14, -28], [6, 36], [5, 0], [-68, 20], [-54, 24], [7, -54], [62, 0], [41, 16], [-6, -28], [20, -44], [37, -60], [30, -2], [43, -30], [6, -16], [0, 50], [-32, 72], [-60, -16], [33, -40], [27, -46], [1, -46], [-38, 46], [2, 4], [12, -54], [23, -10], [39, -34], [-64, -14], [-48, 16], [-63, -4], [-16, 36], [46, 2], [32, 16], [46, -74], [22, -28], [3, 0], [-17, -16], [-28, 80], [-34, 64], [-11, -24], [-38, 14], [-2, 14], [-46, 50], [-4, 24], [-52, 72], [-25, 74], [41, 4], [-64, 42], [9, 22], [38, -60], [14, -12], [-47, 62], [25, -40], [78, -10], [-10, -34], [21, -2], [8, -48], [-47, 40], [55, 18], [-50, 30], [-41, 6], [26, -52]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1425_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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