
// Make newform 4275.2.a.be in Magma, downloaded from the LMFDB on 08 June 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_be();".
// 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_be();".
// 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, -6, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-4, -1, 1]];
    Rf_basisdens := [1, 1, 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_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]];
    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], [0, 0, 0], [0, 0, -1], [1, 0, 1], [-2, 2, 0], [0, 0, 0], [1, 0, 0], [-1, -2, -1], [-3, 0, 0], [3, 2, 1], [-4, -2, -2], [0, -2, 3], [-8, 0, 0], [-2, 2, -2], [3, 4, 0], [-8, 0, 1], [-3, 0, -2], [-3, -4, -1], [-2, 4, 1], [1, 4, 0], [5, 2, -3], [-5, 0, 1], [1, 0, -2], [4, -6, 0], [-2, -2, 4], [3, 0, -1], [-6, 0, 3], [0, -2, -2], [-11, 2, 1], [3, 2, 5], [-15, -2, -3], [8, 4, 8], [-2, -4, 5], [2, -2, -4], [4, -4, -4], [-8, -6, 3], [-6, 0, 5], [2, 4, -1], [1, 8, 4], [-4, 4, -1], [-8, -4, -4], [5, -2, -1], [14, 0, 4], [10, -2, -2], [6, 0, 1], [-5, 10, 5], [9, -2, -1], [2, -4, -1], [3, 6, -5], [-14, 2, -2], [-14, -2, 4], [16, 0, 2], [8, 0, 8], [5, -4, 2], [1, 4, 7], [2, 8, -4], [10, -4, -1], [-9, 8, 2], [5, -6, -7], [0, 8, -4], [-21, -2, 3], [-3, -4, 5], [-12, 4, 0], [-13, -2, -5], [5, -8, -4], [-11, -2, -7], [-12, 4, 2], [-14, -6, -2], [-5, -4, 2], [-8, -8, 4], [-14, 6, 4], [-6, -4, -10], [0, 8, 2], [2, -2, 0], [10, 8, 7], [-4, -6, 2], [-1, -6, 7], [-1, -2, -1], [16, -10, -4], [-6, 2, 6], [0, -2, 4], [-6, -8, -9], [12, 2, 8], [5, -2, 9], [1, -6, -11], [-9, -4, -6], [-16, -6, -5], [14, -10, -4], [0, -12, -4], [1, -4, 1], [7, -12, -5], [-18, 2, -4], [8, 12, -4], [4, 12, -1], [-14, 2, 4], [-9, -4, -12], [1, -4, -2], [10, 10, -6], [5, -14, -3], [23, 0, -5], [-24, 4, 0], [22, -4, 1], [8, -18, -7], [-10, 4, -9], [-17, 18, 3], [-11, 2, -5], [18, -6, 0], [0, 8, 0], [-12, -2, -2], [25, 0, -3], [0, 14, -1], [-12, 10, 0], [-8, -8, 11], [32, -4, 0], [2, 8, 8], [-22, -8, 7], [1, -6, -5], [-2, -6, -8], [8, 0, 8], [-12, 4, -8], [-6, -2, -4], [3, -4, -12], [22, 8, 7], [18, -8, -2], [16, 8, -2], [-15, 4, -2], [-7, -14, -13], [6, 0, -7], [-19, 4, -2], [-8, 0, -7], [20, -16, -1], [18, -2, -2], [1, -8, 6], [12, 6, -12], [7, -12, -4], [-4, -10, -7], [11, 8, -5], [-12, -6, -3], [2, 14, 14], [27, -8, 1], [6, 4, -12], [-26, 0, 3], [-4, -8, -16], [-28, -2, 0], [-40, -4, -1], [-4, -14, 1], [-20, 14, 1], [-22, 12, 9], [8, -16, 5], [-4, -6, -2], [-6, 14, 0], [-2, 0, 3], [-16, -16, 8], [-4, 4, 4], [-14, -16, -5], [-2, 4, -1], [8, -4, 2], [12, -2, -1], [-11, -2, 1], [0, 4, 12], [-15, 20, 6], [14, -16, -5], [-16, -12, -7], [-10, 12, -4], [10, 12, -2], [27, 0, 1], [7, -6, -9], [-24, 10, 10], [8, 10, -4], [16, 8, 1], [-28, 4, 0], [36, 0, -6], [17, 6, -11], [13, -8, -7], [-10, 8, -10], [16, 0, 5], [24, -10, 6], [-16, 0, -8], [-3, 4, 10], [-6, 8, 14], [26, -12, -1], [-4, -10, -8], [17, 4, 2], [-11, 2, -5], [22, 14, 10], [-20, 0, 0], [-23, -14, 9], [-6, -14, 4], [-7, 0, -7], [4, 12, 0], [7, -10, -5], [-9, 20, 13], [27, -2, -9], [2, 2, 8], [2, -24, -4], [-19, 12, 12], [33, 4, 14], [-32, -2, -8], [-17, 8, -5], [-17, 6, -5], [10, 14, 8], [0, 12, 8], [6, 14, -14], [-9, 12, 15], [-40, -12, 8], [-18, 16, 10], [52, 4, 7], [46, 0, -2], [18, -6, 4], [1, 4, 0], [30, 8, 6], [52, 0, 3], [-34, 4, 5], [-4, 20, 5], [-4, 2, 12], [-2, -12, -9], [-25, -10, 11], [-18, 0, -18], [-14, -4, -8], [-20, 2, -10], [23, 2, -9], [10, -16, -8], [-10, 12, 1], [10, 4, 10], [-20, -2, 11], [-51, 0, 6], [-30, 20, 3], [10, 6, 12], [-9, 16, -3], [4, -26, 3], [-23, 24, 5], [3, 22, 13], [-7, 8, 2], [-6, -16, -13], [16, 8, -14], [4, 6, -13], [-4, -10, 14], [40, 4, -2], [18, 12, 3], [-12, 4, -3], [36, 16, -5], [-10, -16, -2], [-14, -16, 2], [-14, 16, 16], [-27, -12, -9], [-12, -4, 17], [-2, -4, 10], [-5, 0, -13], [19, 12, 1], [1, 0, -18], [4, -14, -2], [-37, 6, -7], [0, -26, -2], [-54, -6, -6], [13, 18, -5], [24, 2, -5], [37, 2, 9], [20, 18, -13], [10, -4, -12], [13, -12, 15], [-24, 16, 3], [-25, -16, 18], [-18, -12, 8], [14, -4, -16], [1, -18, -7], [-12, -2, -3], [-8, 0, -8], [-11, 10, 15], [-30, -10, 6], [-2, 10, 14], [21, 8, 11], [19, 18, 15], [30, 4, -5], [18, 18, 2], [24, -8, -4], [-27, 22, 3], [26, 2, 0], [-38, 10, -4], [7, 6, 1], [-8, -8, -17], [-32, 8, -7], [-4, 20, 14], [2, 12, 18], [-12, -16, -7], [-4, 24, 2], [-7, 2, -11], [-1, 14, -1], [48, -4, -5], [-1, 20, 2], [-20, -6, 10], [7, 0, -5], [-4, -2, -1], [-22, 4, -1], [8, 0, -2], [-22, 16, -4], [54, -2, -2], [-50, 6, 4], [26, 4, -10], [30, 16, 14], [-9, 8, -4], [-15, -6, 21], [2, -12, 6], [-8, -20, -11], [-26, 20, 14], [-42, 14, 2], [-4, 16, 20], [52, 4, -10], [17, 16, -19], [-3, -2, -7], [29, 6, 5], [18, 8, 0], [-23, 0, -2], [-15, 14, -7], [-16, 8, 8], [42, -14, -2], [-33, -14, 15], [14, 0, -13], [14, 0, 4], [40, 2, 10], [-12, -28, -2], [8, 26, 19], [-36, -14, 9], [0, -8, -10], [-12, -12, 6], [6, 4, -20], [-18, -10, -8], [6, -26, 8], [68, 0, -4], [-18, 16, 6], [37, 14, -7], [-45, -8, 0], [12, -20, -17], [15, -8, 3], [30, -8, -17], [37, -20, 1], [24, -10, -14], [3, -12, 6], [-39, -8, 16], [-20, 12, 3], [-48, 20, 8], [0, 2, -18], [-15, -12, 12], [31, 20, -13], [19, 16, -8], [14, 0, 5], [-17, -4, -10], [27, 20, -13], [0, 0, 0], [-10, -6, 26], [-37, -20, 3], [-4, 12, 22], [-16, 0, -16], [43, 12, 15], [60, 4, 4], [9, -2, -15], [-43, 6, 5], [-5, 28, -11], [-4, 30, 2], [12, -24, 12], [21, 8, 14], [-32, 0, 4], [-6, 0, 21], [-2, -20, -2], [-20, 12, 12], [-8, 0, 12], [52, 14, -8], [8, -24, -8], [-12, 20, 4], [15, -12, -21], [-13, 2, 3], [-44, -12, -2], [9, -28, 0], [16, 4, -4], [18, 8, -16], [2, -12, -7], [25, 26, -11], [1, 0, 0], [36, -24, -6], [-22, -12, -2], [-52, 2, 5], [-64, -2, -10], [0, -4, 11], [36, 4, -6], [29, 4, -9], [-36, -8, -12], [-20, 0, -16], [-36, 2, -19], [-32, 12, 3], [50, -8, 11], [-10, -26, 12], [1, 22, 1], [-3, 4, -9], [14, -28, -23], [-38, -16, -23], [20, -14, -20], [-12, 12, 4], [35, 12, -22], [-37, -6, -3], [54, -14, -12], [42, 8, 10], [-8, 14, 10], [20, 16, -2], [37, -8, 10], [-37, 12, 8], [18, -12, 10], [-15, 26, 5], [-21, -16, 6], [9, -4, -7], [-5, -16, -17], [-2, 2, 24], [-30, 8, -6], [48, 0, -12], [-16, 12, -9], [25, -12, 0], [20, 2, 8], [-12, -8, -15], [9, -10, -7], [-36, -16, -18], [-14, -4, 19], [-52, 6, -7], [8, 10, -14], [33, 0, -15], [-18, 44, 3], [12, -8, 8], [4, -34, -23], [28, -8, -17], [10, 18, 16], [4, 16, 11], [-33, -18, 15]];
    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_be();".
// 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_be(:prec:=3)
    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_be();".
// 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_be( : 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, -6, 0, 1]>,<7,R![-4, -9, 0, 1]>,<11,R![12, -6, -3, 1]>],Snew);
    return Vf;
end function;