
// Make newform 2475.2.a.p in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2475_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_2475_2_a_p();".
// 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_2475_2_a_p();".
// 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 := [-4, -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_2475_a();"
function MakeCharacter_2475_a()
    N := 2475;
    order := 1;
    char_gens := [551, 2377, 2026];
    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_2475_a_Hecke(Kf)
    return MakeCharacter_2475_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], [0, 0], [0, 0], [-1, 0], [-1, 0], [3, -1], [-4, 1], [3, 0], [-4, -1], [0, 2], [-3, 3], [-2, 5], [0, -3], [3, -3], [-8, 1], [-4, 2], [8, 1], [-5, -1], [-1, 3], [-4, 5], [-6, -4], [-8, -3], [0, 0], [-12, -2], [3, -2], [4, -1], [4, 2], [4, 2], [5, -5], [4, 2], [-8, 5], [4, -8], [-12, 6], [8, 0], [-4, 5], [-9, -3], [5, -3], [13, -3], [0, 6], [-16, 1], [12, 1], [17, -2], [16, -7], [-15, -1], [0, -7], [-1, -5], [11, -3], [-9, -5], [0, -8], [-3, -2], [-12, -5], [4, -8], [9, -9], [-12, 0], [-8, -4], [-12, 6], [8, 8], [0, -11], [-5, 11], [-16, 5], [-27, -2], [-20, 7], [5, 7], [-24, 4], [21, 4], [-12, 2], [0, -4], [3, 3], [12, 6], [22, -6], [8, -14], [16, 4], [9, -9], [1, 5], [9, -13], [-12, -4], [12, -14], [-31, 1], [-20, 10], [-15, 9], [28, -1], [6, -9], [-32, 4], [1, -7], [-19, 12], [8, -13], [-8, -8], [2, -6], [20, -14], [12, -4], [8, -4], [-12, 6], [-11, 9], [-4, 8], [-9, 5], [-4, 8], [-12, -2], [0, -10], [1, -4], [-15, 3], [4, -3], [4, -2], [16, -2], [20, 7], [15, 9], [13, 6], [40, -5], [-12, 18], [-4, 11], [-1, 15], [4, -4], [18, -18], [-32, 4], [-21, 11], [-15, -3], [12, 12], [0, -6], [28, 5], [-28, 8], [24, -6], [-6, 5], [-26, 6], [-24, -2], [8, 5], [-8, 8], [16, -7], [1, 2], [8, -16], [7, 9], [-2, 0], [-4, -3], [-12, -14], [-4, 12], [27, -13], [36, -6], [-17, 9], [-28, -8], [-35, 12], [-48, 2], [12, 3], [-1, 0], [-20, -2], [23, -9], [-20, 4], [18, 12], [0, 8], [-3, 15], [-8, 1], [0, 22], [-8, 4], [9, -9], [-20, 4], [27, 7], [8, -14], [0, -18], [12, -27], [-5, 18], [-28, 20], [-27, -3], [32, 11], [4, 11], [-8, 5], [-44, 0], [-20, 11], [0, 10], [-4, -7], [45, -3], [10, -12], [21, -13], [-24, -12], [0, 20], [-5, 11], [-20, -4], [27, -1], [7, 15], [-44, -8], [19, -24], [4, 14], [-21, -6], [15, 3], [11, -17], [-24, 4], [-25, 0], [-12, -10], [20, 8], [0, -18], [55, -1], [9, 15], [-11, 17], [-4, -4], [-21, 27], [8, -4], [-55, 3], [36, -2], [28, -10], [20, 14], [18, -12], [30, 0], [-32, -7], [24, -12], [-40, -7], [28, -12], [-14, -9], [-42, 6], [8, 17], [4, 22], [-53, 5], [0, 24], [-56, 7], [1, 11], [9, 9], [8, -14], [-45, 5], [-12, 21], [-4, 2], [14, -23], [-5, 24], [40, -7], [24, 15], [8, -14], [-3, 23], [19, 17], [-56, -4], [-20, 0], [-8, 16], [-17, -3], [-32, 16], [32, -11], [-15, -6], [44, -10], [-1, 12], [-12, 21], [27, 16], [52, 7], [48, -2], [36, 10], [50, -3], [-32, 7], [-36, 11], [-24, 17], [12, -3], [13, -18], [53, -3], [3, 20], [0, -13], [-56, 2], [9, -7], [24, 9], [25, -33], [36, -8], [-18, 20], [48, -19], [44, -4], [9, -3], [20, 22], [24, -34], [-11, 12], [-24, 20], [-48, 2], [-50, 2], [-41, -4], [24, -18], [-22, 12], [21, 7], [-32, -4], [-16, 4], [20, 4], [24, 8], [36, -11], [-56, 1], [35, 12], [24, -6], [-54, 12], [-43, 0], [-33, 15], [-13, -11], [0, -23], [-21, -3], [-25, -3], [8, 2], [-36, 4], [-4, 18], [36, 0], [-37, -9], [-11, 3], [-8, -19], [55, -18], [-12, -15], [-12, -6], [-12, -23], [-20, -16], [0, 29], [48, -17], [24, 0], [5, -3], [-20, -2], [-39, -15], [-16, -10], [-16, 26], [-20, 3], [6, -28], [12, -9], [-3, 10], [12, -24], [16, -6], [27, -5], [24, -29], [9, -24], [44, -19], [-46, 18], [56, -2], [0, -10], [28, 1], [-45, -5], [64, -2], [-43, 27], [0, -35], [-36, 28], [43, -18], [-12, -6], [12, 1], [-15, 17], [-36, 33], [3, -3], [28, -14], [-38, 15], [-13, 21], [1, 33], [8, 2], [48, 5], [13, 27], [0, 12], [-15, 12], [60, 0], [3, 32], [36, -31], [-37, -9], [52, -10], [-7, -20], [32, -21], [33, -12], [-16, 20], [-44, 10], [39, -27], [28, -14], [16, 26], [-39, -6], [13, 3], [12, 26], [-12, -2], [11, -2], [-82, 9], [24, 0], [-19, -18], [-5, -15], [12, -3], [-40, 11], [48, -22], [-8, 25], [20, 16], [21, 9], [-12, 25], [40, -13], [-36, 8], [32, -36], [-47, 6], [-64, -13], [12, 16], [-1, 1], [20, -16], [-7, -27], [-16, -14], [32, 11], [56, -11], [63, -12], [20, 8], [0, -10], [-23, 11], [32, -38], [35, 3], [-28, 4], [44, -10], [8, -9], [8, -34], [0, -36], [-60, 9], [45, -25], [-6, 21], [36, 3], [-4, 8], [1, -34], [-8, -20], [-72, -3], [51, -15], [20, -28], [-65, -9], [17, -12], [32, -34], [25, -19], [-12, -13], [-2, 0], [64, -14], [-55, -9], [36, -30], [0, -3], [-64, 15], [-9, 31], [64, 10], [53, -9], [-28, 19], [-27, -9], [-64, 11], [12, 17], [59, 10], [-9, 11], [28, -8], [32, 14], [-11, -15], [-24, 30], [-4, -2], [60, -16], [21, -27], [-12, 37], [68, -10], [34, 15], [-12, 30], [-24, -19], [-28, 17], [-39, 9], [-52, 10]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2475_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2475_2_a_p();".
// 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_2475_2_a_p(:prec:=2)
    chi := MakeCharacter_2475_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_2475_2_a_p();".
// 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_2475_2_a_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2475_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-4, 1, 1]>,<7,R![1, 1]>,<29,R![-16, -2, 1]>],Snew);
    return Vf;
end function;