
// Make newform 1875.2.a.h in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1875_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_1875_2_a_h();".
// 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_1875_2_a_h();".
// 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, 7, -6, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-4, -1, 1, 0], [0, -4, -1, 1]];
    Rf_basisdens := [1, 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_1875_a();"
function MakeCharacter_1875_a()
    N := 1875;
    order := 1;
    char_gens := [626, 1252];
    v := [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_1875_a_Hecke(Kf)
    return MakeCharacter_1875_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], [1, 0, 0, 0], [0, 0, 0, 0], [-1, 1, -2, 0], [-3, 0, -3, 1], [1, 0, 2, -1], [1, -1, 0, 0], [0, 2, 0, -1], [0, -1, -2, 1], [-5, -1, -1, 0], [5, 0, -2, 1], [1, -1, -1, 2], [-1, 0, 4, 0], [4, 0, -1, 2], [1, -1, 1, -2], [-1, -1, 0, -2], [-6, 0, -3, -3], [1, 0, 4, -2], [2, -2, 1, 0], [0, 3, 2, 4], [5, -4, -1, -2], [9, -3, -1, -3], [5, 0, 0, 4], [-7, 0, 4, -1], [3, 0, -2, 4], [-4, -1, -4, 2], [3, -4, -2, -3], [2, -2, -3, -2], [5, 1, 1, 5], [-2, 2, 0, 5], [-7, 1, -1, 4], [3, -3, -4, 1], [8, -4, -1, -1], [8, -6, 0, 0], [7, -5, -3, -1], [-11, 0, -7, 2], [13, 1, 9, -1], [13, -1, 8, -2], [-10, 5, -10, -2], [14, 1, 1, 0], [2, 2, -3, 3], [5, 0, 14, -1], [5, 2, 10, 1], [9, 4, 6, 1], [-6, 6, 3, 0], [0, 0, -9, 3], [0, -2, 1, 1], [-5, 2, 8, -3], [-1, 3, -9, -2], [-4, -6, 1, -5], [6, -3, 6, -5], [4, -3, 7, -4], [14, -9, 2, 1], [0, 1, -1, -4], [7, -2, 7, -7], [-1, 4, -9, 6], [0, -6, 6, -4], [3, -11, 3, 1], [16, 0, -4, 5], [2, 4, 15, 3], [3, 0, 8, 5], [8, -4, 8, 2], [-19, 1, -11, 1], [-16, 6, -5, 0], [-7, 6, 3, 2], [13, 3, -3, 2], [0, 3, -15, 3], [0, 9, -3, -3], [-4, -5, -9, 0], [9, -7, 1, 0], [5, 5, 19, 1], [8, -4, 8, -7], [8, -4, 9, -1], [-2, -3, 7, 1], [7, 3, -5, -1], [-4, 0, 3, 2], [-7, 5, -1, 4], [2, 2, -6, -3], [-17, 8, 5, 5], [-13, 15, -5, -2], [2, -1, 12, -8], [-8, 11, -10, 7], [7, 4, 10, -7], [-17, -3, -6, -3], [-2, -6, 1, -2], [3, 2, 7, -4], [-8, 11, -10, 0], [-15, 4, 0, 1], [3, -4, 7, 2], [-15, 6, -10, -4], [-1, 1, -2, 0], [9, 2, 13, -6], [6, 6, 1, 7], [-22, 5, -13, -5], [-8, 6, -20, 10], [22, 2, 15, -4], [-10, -2, -11, 13], [8, -3, 2, -11], [14, 9, 1, 1], [-1, 0, -7, 2], [15, 6, 17, -4], [-5, 6, -6, 7], [2, -10, 15, -8], [-22, 2, -21, -2], [7, 0, 2, 11], [-2, 10, 18, -1], [-9, 2, -14, -6], [-9, -4, 1, -7], [-21, -3, -8, 6], [6, -12, -9, 0], [21, 10, -4, 0], [14, -6, 5, -7], [17, -15, 4, 3], [-1, 8, 7, 8], [13, 6, 3, -5], [5, 9, 7, -4], [10, -15, 13, -2], [-13, 4, -18, -5], [27, -5, -1, -1], [-12, 6, -4, 7], [-4, -4, 8, -8], [27, -1, 2, -4], [-7, -3, -6, -14], [21, 11, 16, -7], [8, -3, 7, -11], [-16, 10, 0, -12], [25, 10, 7, -4], [17, -10, 2, 4], [-16, -3, -1, -10], [5, 9, -3, 3], [-8, -3, -4, -10], [-22, -6, -29, 12], [10, -3, 3, -5], [8, -2, -13, 12], [-14, 3, 13, 6], [1, 9, -16, -1], [6, 7, -1, -1], [-2, -8, -1, -14], [6, 1, 11, 7], [8, -8, 12, -8], [25, 0, 18, -9], [35, -7, 14, 10], [-20, 12, -5, -2], [-15, 5, -16, 5], [19, 0, 10, 1], [-3, 5, -5, 3], [10, -11, -7, 11], [-18, 0, 9, 3], [2, -3, -2, 1], [-27, -3, 9, -3], [16, -2, -23, -1], [-16, 8, 14, -4], [-8, -7, -4, -14], [26, -7, 20, -7], [-10, -4, 18, -1], [5, -11, 10, 0], [14, -4, -9, 6], [-17, 3, -33, -1], [7, 3, 29, -1], [-1, 7, 3, -14], [-30, 4, 10, 1], [14, -6, -8, -6], [-17, -7, -20, 11], [-17, -3, 8, -3], [31, 4, 22, 1], [3, -7, 2, -7], [-10, -8, 31, -6], [17, -8, 1, -12], [1, 2, -7, 12], [2, -5, -19, -10], [-3, 11, 19, 7], [15, 8, 11, -4], [-1, -23, -11, 9], [-9, -4, -20, 0], [30, -1, 9, 5], [55, -4, 10, 7], [23, 3, 2, 11], [-6, 2, 10, -18], [26, -3, 13, 1], [22, -8, 24, -1], [-10, -7, -30, 4], [-13, -5, 10, 0], [-11, 14, -1, -5], [22, -2, 30, 2], [18, 0, -12, 10], [-3, 4, -27, 0], [30, -2, 35, -6], [-20, -3, -19, -4], [-38, 4, -16, 8], [7, 16, 10, 2], [-28, 16, 7, 5], [-31, 10, 10, 0], [-15, 0, 1, -5], [17, -7, -2, -5], [-3, 13, 14, 4], [-12, -6, -24, 7], [-3, -2, 6, 14], [13, 7, -3, -9], [20, -5, 11, -19], [19, 2, 9, -4], [-14, -7, 3, -6], [5, 6, 5, 14], [-1, -6, 3, 6], [-19, 14, -5, 2], [-23, 2, -21, -1], [24, 7, -4, 11], [37, 6, 8, -1], [11, -11, -24, 4], [-11, 2, -21, 2], [1, 3, -5, 7], [16, -15, -2, -14], [4, 6, 2, 16], [9, -12, 3, -15], [-32, 19, 1, -4], [-8, 0, -16, 0], [-15, -11, -28, 6], [5, -5, 22, -6], [8, 12, 16, 11], [-12, 4, 2, -21], [21, -3, 30, -3], [-53, 1, -6, 4], [-11, -6, 18, -12], [22, 5, 27, -21], [23, -16, 1, 7], [-12, -13, -16, -4], [-26, -3, -8, 1], [-11, -4, 21, 5], [-13, 1, -30, 0], [1, 0, 25, 7], [-14, -6, 0, -16], [17, -8, 16, -21], [-25, 4, -14, 6], [9, -6, 14, -22], [-23, -2, -2, -5], [-9, -12, 15, -6], [2, -5, 25, -14], [-14, -7, -19, -2], [11, 3, 19, -4], [-18, 4, 5, -4], [19, -15, -1, 0], [-35, -1, 15, 2], [30, -10, 18, 1], [-5, 3, -5, 20], [11, 6, 34, -2], [-30, -4, -11, 8], [-2, -19, -5, 4], [-19, -9, -35, 4], [3, -14, 21, -6], [-14, 8, 32, 1], [-3, 2, 16, -11], [20, 14, 8, -5], [34, -12, -1, -9], [26, 4, 40, 0], [-2, -19, 44, -14], [6, 12, -21, 9], [13, -24, -8, 0], [21, 1, -5, 3], [2, -13, -7, 19], [-28, -3, -22, 9], [34, -17, -4, -2], [-5, -6, -20, 7], [29, -2, 0, 15], [-15, -11, 6, -14], [-30, -1, -3, -2], [8, 6, 28, -9], [16, -9, 4, -12], [30, 0, 6, 8], [-3, 2, -29, 12], [13, 6, -8, 4], [23, -1, 0, -11], [-19, -1, -56, 1], [-4, -4, -6, -14], [1, -15, -20, -2], [-8, -5, -6, 10], [-22, 5, 7, -4], [-33, 13, 1, 6], [8, -12, -6, 13], [-7, 16, -11, 21], [30, -8, 33, -5], [-14, 3, -30, 2], [-17, -14, 31, -14], [-17, 4, -15, 7], [-21, -6, -21, 9], [16, -11, 7, 5], [-16, 3, -6, -18], [-20, -5, -29, 10], [-9, -3, -1, -21], [21, 4, 2, 1], [31, -6, -9, 0], [4, -11, 21, 2], [15, -21, 45, -5], [-8, 1, -5, 13], [0, -17, -22, 14], [-7, -14, 9, -17], [32, -5, 37, -7], [-31, -14, 18, -8], [49, -12, 19, 11], [-15, 0, -58, 0], [1, -17, 19, 2], [-1, -22, -21, 7], [16, 1, -21, -3], [-3, 17, -23, 6], [-29, -10, -23, 0], [17, -29, 6, -8], [-36, -12, -19, 2], [4, -14, -18, 17], [13, -6, -17, -3], [-13, 0, 24, 0], [-20, -12, 6, -16], [4, -1, 17, 9], [22, 4, 33, -6], [-36, 1, -25, -2], [17, 6, 9, 19], [-51, 18, -22, -15], [8, 18, 12, 7], [20, 0, 8, 9], [14, -21, 19, -4], [3, 1, 27, -3], [-27, 9, -7, -12], [26, -18, 22, 9], [22, -11, -15, 8], [16, -9, 1, -8], [-6, -5, -22, 22], [-9, 15, 40, 3], [24, 5, 19, 7], [-19, -9, -32, 7], [-39, -7, -5, 0], [11, -15, 24, -15], [-6, 19, 8, -4], [71, 5, -7, 2], [23, -10, -3, -10], [-21, 8, -38, 11], [5, 12, -5, -11], [32, 15, -11, 9], [33, -7, 30, -20], [-12, 5, 4, -13], [10, 18, 9, 3], [-2, -12, -36, -1], [-3, -3, -10, -1], [4, 12, 15, -12], [-15, 8, -43, 26], [-15, 14, -23, 2], [-17, 5, -31, -6], [28, 10, 18, -12], [54, 2, 24, -9], [-41, 5, -10, 6], [21, -21, 21, -18], [7, -12, -43, -7], [-28, -3, 18, -17], [-6, 9, -25, 22], [-35, 2, -10, 6], [-67, -3, 4, -14], [36, -8, 20, -15], [11, -5, 8, 12], [19, 12, 25, 10], [6, -9, 34, 2], [-18, -2, 26, 7], [-60, 13, -1, 0], [-20, 9, 1, 14], [23, 20, -4, 4], [-3, 22, 0, -5], [12, 10, 5, 5], [-33, -2, -4, -5], [9, 4, 64, 1], [34, 8, 19, 2], [-37, 3, -29, 10], [2, 1, -12, 7], [13, -3, -23, 16], [-26, 3, -11, -14], [6, 11, -8, -6], [15, 15, 18, -21], [28, -11, 7, -20], [6, 11, -5, -4], [18, -1, -12, -14], [41, -3, -2, 10], [15, 23, -5, 6], [-71, 12, -36, -16], [-17, 12, -3, 16], [18, 8, -5, -7], [2, -23, 34, -23], [50, -8, 21, -6], [-16, -22, -7, 10], [44, -6, 40, -8], [3, 8, 10, -9], [39, -10, 33, -5], [-36, 0, -21, -8], [38, 3, 5, -10], [5, -13, 33, -4], [41, -15, 3, 17], [27, -23, -10, 5], [-34, 17, 11, -14], [-2, 3, 24, 4], [-26, 19, -21, -4], [-17, 7, 7, -10], [-26, 1, -9, -7], [41, 2, 31, 10], [-17, -6, -16, -28], [-3, -3, 32, -27], [-22, -16, 5, 7], [-21, -5, 25, -17], [5, 6, 28, 16], [-39, 6, -13, 1], [5, -13, -14, -10], [-63, -5, -40, 16], [23, -9, 3, -17], [3, 14, 7, 18], [-59, 3, -11, -15], [39, 1, -34, -2], [1, 21, -24, 28], [20, 8, 42, -8], [-16, 2, -45, 14], [-29, 8, -64, 11], [-17, -10, -28, 17], [-42, 0, 12, -15], [-21, 21, 19, -2], [41, 16, -23, 9], [-20, 16, 4, -11], [31, -8, 2, -13], [51, -6, 55, -10], [-12, -9, -10, -17], [1, 28, -34, 8], [10, -12, -11, -14], [14, -10, 14, 11], [24, -14, 40, -2], [-44, 0, -17, -8], [-56, -7, -15, 5], [45, -5, -2, 13], [17, -19, 21, 3], [-10, 20, 25, 17], [17, 32, 29, -16]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1875_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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