
// Make newform 4275.2.a.t in Magma, downloaded from the LMFDB on 30 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4275_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_4275_2_a_t();".
// 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_4275_2_a_t();".
// 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_4275_a();"
function MakeCharacter_4275_a()
    N := 4275;
    order := 1;
    char_gens := [1901, 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_4275_a_Hecke(Kf)
    return MakeCharacter_4275_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, -1], [-3, 1], [1, 1], [0, 0], [1, 0], [0, -2], [-3, 3], [2, -4], [1, -3], [-3, -1], [1, 3], [0, 2], [-6, 2], [-6, -2], [-10, -2], [-8, 0], [-6, -6], [10, -4], [-4, 4], [-6, 4], [-9, 1], [1, -3], [0, -6], [4, 8], [0, 0], [-4, 6], [12, -4], [4, 0], [-3, -7], [6, -8], [2, 6], [6, -8], [14, 0], [4, 6], [-11, -1], [0, -2], [0, -4], [-6, 10], [8, 6], [-9, -5], [-5, 7], [-24, 0], [2, 10], [8, 4], [4, -8], [0, -6], [-22, -2], [6, 8], [15, 3], [-10, -4], [-9, 11], [-24, 0], [6, 0], [15, 9], [-10, -6], [-2, 0], [-3, -1], [1, 15], [0, -16], [22, -6], [-3, 17], [4, 6], [6, 10], [2, 16], [7, 7], [6, 4], [-22, 0], [6, 12], [-9, -5], [-11, 3], [1, -3], [14, -4], [-24, -4], [6, 8], [-2, 4], [15, -11], [-16, 6], [9, -11], [2, 12], [-6, -10], [-5, -9], [20, -4], [12, 10], [-3, -5], [-8, -2], [-6, 0], [13, -13], [24, 2], [-3, 13], [22, -6], [3, 11], [14, 2], [-30, -4], [-9, -11], [-39, -1], [-26, -10], [14, -16], [-26, 10], [-6, -4], [-24, 2], [-3, 11], [-10, 14], [16, 18], [0, 2], [-18, 12], [0, -8], [-16, 18], [22, 6], [-32, 6], [0, -16], [2, 10], [-28, 4], [-33, 9], [7, -3], [-18, -8], [24, 4], [-12, -4], [8, -18], [-5, 7], [18, 10], [-12, -4], [2, -6], [6, -16], [2, 18], [3, -5], [-17, 5], [-2, -12], [20, 8], [-24, -12], [26, 0], [-8, 14], [-6, 0], [14, 20], [6, 18], [-26, -10], [24, -12], [6, 12], [-4, -24], [36, 2], [13, 15], [12, 10], [-4, -22], [30, 6], [4, 18], [-18, 14], [32, 0], [-12, 0], [-41, 7], [-12, -2], [-11, 15], [-24, 0], [22, -6], [48, -4], [-4, -32], [12, 6], [-8, -14], [15, 9], [42, 8], [24, -8], [-17, -7], [0, -16], [6, 26], [-24, 10], [20, 4], [28, 6], [14, -24], [-18, 16], [30, 2], [26, -4], [-33, 15], [10, -20], [-28, 4], [-36, 6], [-46, 2], [-12, -14], [34, -14], [2, 24], [7, -15], [-12, -4], [19, -1], [12, -8], [-24, -22], [30, -4], [-11, -27], [-14, -22], [-28, -18], [9, 5], [25, 21], [0, -22], [-28, -16], [-9, -19], [24, -6], [60, -4], [-22, -6], [-50, -8], [-12, -24], [24, 14], [3, 25], [-4, 12], [-41, -13], [-22, 8], [9, 21], [36, -4], [-4, 36], [0, -18], [-12, -14], [-4, -8], [-8, -10], [0, -14], [37, 3], [60, -2], [18, -6], [-4, -2], [-23, 15], [21, 27], [0, 6], [12, -16], [2, 0], [2, -8], [-9, -7], [-29, -23], [0, -6], [2, -32], [12, 0], [-30, -2], [64, 0], [9, -19], [16, 2], [2, 20], [44, -12], [-9, -15], [7, -27], [0, 2], [-22, 14], [6, -12], [-39, -3], [-18, 6], [-12, 20], [-40, 12], [1, -13], [8, -18], [-18, -18], [-39, 9], [31, 21], [0, -4], [-22, -28], [54, -8], [-68, -6], [-6, -12], [6, -4], [-52, 6], [-24, 12], [-9, -17], [-10, 2], [-20, 4], [18, -10], [22, 4], [-8, 12], [24, -28], [2, -8], [-29, -13], [-60, 0], [26, -28], [-69, -7], [-48, 10], [16, 20], [-24, -20], [-10, 16], [-32, 0], [-8, 18], [26, -30], [-5, 11], [19, -11], [-18, -16], [32, 10], [32, 22], [51, 7], [0, -12], [20, 24], [0, 30], [26, 12], [19, -27], [-63, 5], [22, -16], [-6, -6], [68, -4], [-3, 3], [-12, 34], [18, 4], [18, -2], [42, -2], [-35, 1], [-48, 10], [20, -12], [48, -8], [12, 4], [-5, -23], [10, -12], [54, 6], [-16, -12], [0, 30], [-34, 18], [-41, 15], [24, 28], [-10, -20], [-3, 1], [-8, -26], [-24, -10], [6, 4], [51, 1], [10, -42], [-30, -12], [50, 0], [-63, 5], [12, 20], [64, -2], [-18, 20], [-22, -4], [-8, -10], [3, -31], [-26, -14], [48, 0], [14, 12], [44, -16], [58, 10], [12, -34], [-24, 8], [50, -24], [-54, -22], [-34, -6], [6, -4], [14, -30], [30, -24], [-46, 8], [78, -6], [26, -6], [-11, 15], [7, 39], [-54, 16], [3, -3], [86, 0], [-30, -6], [-36, -16], [-46, 18], [-20, 24], [-48, 24], [-18, -28], [-46, -16], [7, 31], [12, 14], [10, -30], [-28, -30], [30, 26], [57, -7], [21, -3], [-12, 32], [84, 0], [34, -24], [6, 16], [0, 12], [18, -6], [-11, 15], [-35, -27], [-18, 8], [34, -2], [-64, 2], [-39, -15], [8, -20], [6, 16], [39, -23], [44, -32], [4, -30], [12, -4], [-39, -19], [34, 36], [0, -6], [19, 19], [3, 45], [36, -8], [31, 21], [-66, -16], [-10, 8], [12, 26], [-46, 26], [-26, 0], [-65, -15], [36, -14], [-52, -10], [-30, -6], [57, 5], [43, 29], [-42, 2], [25, 21], [38, -8], [-39, -37], [14, -12], [-66, -16], [38, 20], [-12, 32], [-38, -30], [0, 0], [45, -1], [20, -8], [-20, 6], [57, 7], [10, 30], [57, -19], [-47, -23], [-36, -20], [72, 12], [26, -30], [22, -48], [-30, -12], [48, -4], [16, 0], [-30, -32], [-24, 20], [-39, 11], [19, 3], [12, -6], [0, 16], [-53, -17], [-24, -4], [24, -24], [-18, 16], [-22, -14], [-39, 21]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4275_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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