
// Make newform 7500.2.a.g in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7500_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_7500_2_a_g();".
// 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_7500_2_a_g();".
// 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, 4, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-2, 0, 1, 0], [0, -3, 0, 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_7500_a();"
function MakeCharacter_7500_a()
    N := 7500;
    order := 1;
    char_gens := [3751, 2501, 6877];
    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_7500_a_Hecke(Kf)
    return MakeCharacter_7500_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, 0, 0, 0], [1, 0, 0, 0], [0, 0, 0, 0], [-1, 1, -1, 0], [0, -1, 0, 0], [1, 1, 2, 1], [-3, 3, 1, -2], [0, -3, 0, 1], [-2, 0, -3, -1], [-2, -3, 1, -3], [-1, -1, -2, 1], [0, -3, -1, -1], [3, -2, 2, 6], [-9, 2, 2, 1], [0, -1, 5, 5], [3, -3, 1, 4], [1, -1, -6, -2], [-3, 2, 4, -2], [-1, -2, -4, -7], [-2, -1, -3, 4], [-6, 6, -4, -5], [-6, 6, -1, -8], [-3, 0, 2, 2], [3, 3, 2, 1], [-11, 4, 0, -6], [0, 7, 3, -6], [5, -9, -2, 5], [-7, 2, -4, 1], [0, 4, 3, 0], [4, 1, -2, 1], [-6, -3, 5, 1], [3, 2, 1, 11], [-3, 3, 0, -6], [8, -2, -2, 12], [-14, 10, 1, -6], [6, -4, -2, -1], [0, 2, 3, -6], [7, -3, 9, 12], [-16, 3, -1, -10], [11, -3, 9, 13], [-7, -1, 4, -8], [-15, -3, -2, 5], [-1, 3, 0, -1], [5, -5, 6, 11], [5, 4, -10, -5], [-13, -1, -4, -12], [5, 7, -10, -4], [-5, -7, 0, -1], [-20, 7, -3, -13], [-3, -9, -8, 6], [-10, -4, -3, 9], [17, -1, 1, 3], [4, -2, -15, -9], [9, -9, -7, -1], [-16, -7, 4, -10], [-12, 0, -4, 1], [6, 2, -14, -6], [0, 2, 15, 8], [-2, -5, 10, 5], [-1, -5, 0, 6], [3, 3, -10, -9], [12, -2, 0, -6], [-4, 6, 7, 2], [9, 12, -8, -3], [-6, 0, -14, -1], [-14, -5, 1, -3], [-9, 8, 13, 16], [-9, 4, 7, -4], [1, 1, -1, 3], [-26, 5, -3, -13], [-14, 6, 11, 14], [12, -3, 16, 15], [9, -9, 0, 18], [15, -4, 3, 14], [-12, 10, -3, -14], [-7, 0, 2, 3], [20, -1, -5, 5], [-18, 5, -4, -17], [14, 3, -6, -8], [-2, 1, 7, 3], [-2, 11, 5, -10], [2, -4, -3, -7], [1, 13, 2, 11], [5, -8, 7, 15], [19, -8, 4, 15], [8, 8, -14, -9], [14, -7, -5, -14], [-13, 3, -6, -15], [-2, -10, -6, -9], [-9, 0, 6, 6], [-19, -3, -3, -10], [12, -2, 2, -9], [-21, 5, -6, -6], [15, -6, 5, 4], [4, 4, 6, 10], [-5, -12, -4, 5], [29, -5, 2, 10], [16, -6, 13, 19], [-15, 12, 7, -2], [2, 14, 8, 9], [-8, 4, -4, -7], [-5, 1, -8, -17], [-17, 0, 0, -19], [9, -10, 14, 13], [-7, 1, -10, -1], [14, 7, -8, -11], [21, -16, -8, 2], [6, -5, 18, 8], [3, -5, 13, -2], [-9, 12, -4, -15], [1, -12, 2, 8], [-21, 9, 0, -4], [-21, 6, 7, -15], [14, -18, -6, 3], [20, -1, -6, 0], [20, -5, -5, 17], [-7, -7, 17, 9], [17, -1, 2, 33], [4, -10, -3, 16], [-16, 5, -14, -35], [-32, 12, -4, -16], [-13, 3, -9, 6], [3, 11, 15, -14], [17, -4, -1, 27], [-31, 4, -1, -4], [-4, -2, -2, 8], [30, -14, 6, 13], [11, -6, -20, -12], [1, 1, -19, -13], [12, 2, 15, 2], [-18, 17, 15, 0], [-5, 4, 12, 1], [-9, 18, -13, -22], [13, -2, -14, 1], [15, -3, 7, 3], [-15, 2, -5, 7], [7, 0, -17, -18], [-19, 6, 10, -11], [15, 10, 13, -2], [-4, 0, -16, -28], [3, -23, -2, 11], [13, 7, -13, -14], [7, -14, -2, -3], [13, -18, 9, 23], [-25, -1, -2, 7], [-10, 2, -21, -10], [9, 18, -9, -6], [1, -1, 12, 24], [10, -4, -7, 27], [-12, 20, 3, -26], [21, 3, 0, 14], [-22, 20, -4, -26], [-22, 5, 3, -16], [18, -6, 11, 13], [8, -13, -6, 15], [3, -3, 17, 22], [-15, 6, -10, -23], [16, 22, -7, -4], [-2, -12, 1, -6], [-2, 19, -11, -5], [8, -3, 0, 13], [10, -16, -14, 18], [17, 4, 9, 23], [-1, 6, 9, 7], [-5, -3, 10, -15], [-51, 14, -11, -27], [-3, -10, 18, 17], [12, -8, 16, 11], [-40, 6, -10, -29], [31, 1, 7, 3], [-10, 20, 21, 2], [24, 0, -8, 5], [14, -4, -9, 10], [7, -8, -8, 0], [-3, -2, 21, -2], [31, -1, -6, -5], [-25, 2, 7, -11], [8, 16, -22, -12], [21, -8, -13, 14], [-12, 1, -14, -21], [-10, 27, 15, -16], [9, -1, 3, 22], [8, -9, -12, -16], [32, 4, -14, -4], [6, -6, 20, 14], [-10, 20, -2, -1], [27, -16, -6, 11], [19, 23, -3, -1], [6, 4, 12, 24], [29, -18, -2, 30], [23, 11, -6, -2], [3, -18, -8, -24], [-2, 1, 4, -6], [13, -2, 7, 3], [15, 13, 5, 30], [2, 7, 2, -17], [-21, 0, -2, 8], [-8, -8, -7, 14], [-23, 10, -21, -32], [-22, 20, 10, -19], [37, -17, 13, 25], [22, 2, 0, -13], [32, -4, -18, -13], [22, 8, -2, -5], [-2, -17, 26, 16], [-18, -2, -17, -1], [21, -17, 8, 17], [-5, 13, 13, 0], [-8, -4, -20, -1], [-2, -2, -15, -26], [12, -25, -11, -8], [2, -22, -26, 10], [-8, 11, -20, -26], [-1, -19, 3, 17], [8, -4, 0, -28], [15, -13, 17, 22], [-11, -7, -7, 30], [-2, 9, 16, 39], [-2, 15, 20, 15], [29, -20, -5, 5], [-5, -15, 25, 6], [19, 4, 2, 38], [-13, -10, 17, -10], [-24, -3, 4, -2], [0, -21, -11, 14], [6, -8, 7, 21], [0, -5, 2, -20], [-35, -7, 1, -42], [18, -15, -20, 10], [18, 2, 14, 44], [19, 9, 10, -13], [1, -12, 28, 20], [-21, 30, -2, -28], [-3, 13, 24, -21], [-18, -8, -18, -23], [41, 11, 3, 7], [-5, -29, -3, -11], [-26, 17, -3, -23], [1, -14, -6, 3], [8, -1, -25, 9], [10, -13, -3, 15], [-12, 7, 0, 1], [-24, 19, -21, -35], [5, -4, 18, -4], [19, -18, -4, -15], [-37, 31, 9, -25], [12, -17, -9, 31], [-26, 6, 14, -9], [30, 21, -22, 7], [1, -29, 0, 21], [-22, 19, 4, -9], [7, -5, -8, 6], [10, 12, -12, 4], [-36, 3, -11, -22], [11, -43, -4, 12], [5, -4, -22, -42], [10, -6, 3, -8], [33, -8, 1, 32], [-8, 18, 5, 23], [24, -15, -1, -2], [-13, 31, 8, -7], [13, -31, -16, 19], [9, -1, 1, 4], [39, 1, 15, 21], [50, -29, 2, 31], [2, 5, 25, 18], [40, -12, -12, 14], [4, 2, -24, 1], [1, 8, 10, -32], [1, -14, -3, -5], [21, -6, 5, -3], [2, 30, 8, -24], [-5, -17, 25, 22], [12, -5, -11, -6], [-11, 1, 17, -3], [-10, 11, -15, -43], [-22, 17, -28, -39], [-2, 7, -14, 0], [11, -15, -2, 10], [-4, -11, 29, 22], [-12, 6, 10, -43], [32, 1, -24, -14], [4, -3, 34, 34], [-15, 4, -1, -10], [8, 7, 1, -2], [-11, 15, 15, 17], [-24, 10, -9, -32], [21, 9, 2, 17], [22, 4, -16, 11], [-19, 23, 5, 3], [-6, 18, 25, -10], [-7, -4, 13, -6], [26, 3, -25, -24], [16, 7, -22, -10], [23, 26, -11, -8], [3, 36, 4, -16], [24, 13, -4, 20], [43, -6, -6, 20], [18, -21, 5, 15], [22, -21, -14, 36], [-19, -8, -1, 26], [30, 25, -25, 9], [16, -24, -4, 17], [-9, -5, -9, 2], [-23, 30, -2, -9], [-44, 13, -4, -25], [6, 21, -10, -2], [-9, 24, -16, -24], [-14, -4, 28, 26], [35, -10, -7, 8], [-3, -24, -6, -3], [-29, 7, -7, -23], [32, -25, -28, -10], [15, 9, 8, 61], [-8, -19, -6, -23], [-42, -17, 18, -27], [7, -27, -1, 23], [4, -28, -13, 4], [-18, 17, 21, 3], [-6, 13, 6, 23], [-15, -21, -7, -9], [21, -9, 7, -13], [20, -29, 19, 32], [-35, -14, 23, -25], [-51, 22, -15, -22], [-35, -4, 1, 3], [-22, 5, -7, -43], [1, -42, 5, 5], [18, -5, 5, 6], [-20, 37, 7, -27], [46, 0, -2, -7], [23, -37, 14, 39], [36, 15, -24, 2], [23, -22, -25, 0], [-15, -15, -1, 16], [-16, 28, 19, -29], [-57, -1, 4, 14], [0, 5, 4, 39], [27, -18, 15, 1], [15, -4, 6, 47], [4, 2, 24, -11], [-6, 0, 24, -15], [28, 9, 7, 13], [22, 10, 6, -2], [-28, 15, -10, -13], [1, 15, 13, -8], [6, -11, -33, 21], [-12, -29, 16, 0], [-10, 16, -25, -47], [1, 7, 1, 17], [-29, 26, 14, -28], [3, -17, 9, -6], [-18, 15, -12, -39], [-31, 35, 17, -10], [-2, 30, 16, 29], [-40, -13, -13, -4], [40, -11, 2, 59], [1, 3, -15, -5], [17, -1, 9, 23], [-29, -16, 10, -22], [-9, 7, 0, 19], [7, 7, -6, -26], [-9, 9, 32, 35], [-19, -3, -6, 1], [1, -6, -10, -11], [-2, 21, 15, -21], [4, 36, 5, -25], [16, -7, -27, 31], [-5, -19, -5, 33], [6, 33, -3, 12], [-9, -38, -5, 21], [17, -21, -3, -5], [-11, -25, 19, -9], [16, -1, 33, 4], [5, -13, 25, 16], [-52, 11, -3, -13], [-55, 4, 10, -14], [10, 4, -12, 47], [15, -31, -12, 16], [0, -24, -21, 15], [-29, 32, 0, -45], [5, -34, 10, -5], [-16, -2, 2, 0], [35, -25, 14, 11], [8, 11, -22, -30], [49, -38, 2, 29], [13, -1, 15, 17], [-30, -9, -17, -5], [-6, -2, -33, -8], [17, 18, 9, 41], [-19, 15, 5, -21], [14, 13, -9, 8], [7, 9, 7, -33], [-12, 17, -21, -37], [-49, 16, 5, -30], [-14, -20, -6, 3], [11, -12, -6, -12], [15, 0, 7, 23], [3, 15, 24, 34], [-14, -2, 21, 10], [-55, 30, -6, -24], [6, -7, 48, 30], [17, 5, -39, -22], [-15, 7, -15, -34], [56, -2, -11, 20], [-2, -14, -44, -11], [-16, 30, -31, -24], [-19, 11, -13, -50], [-9, 9, 35, 10], [-34, 20, 20, -30], [5, -8, -2, 31], [-51, 11, -22, -47], [-5, 31, 24, 13], [6, -39, 6, 3], [-10, 3, 21, -13], [-28, 27, -18, -44], [-40, 1, -32, -1], [9, -7, -2, -5], [-34, 20, -4, -61], [-26, 22, 1, -19], [15, 6, 14, 8], [-19, -10, 4, 37], [-8, -11, 38, 23], [16, -20, 18, 22], [45, 4, -4, 53], [-5, -20, -7, -10], [-45, -4, 3, 13], [0, 20, 19, 26], [-5, -7, -8, -20], [-8, 6, -16, -51], [-4, 16, -10, -31]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7500_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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