
// Make newform 3750.2.a.g in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3750_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_3750_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_3750_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, -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_3750_a();"
function MakeCharacter_3750_a()
    N := 3750;
    order := 1;
    char_gens := [2501, 3127];
    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_3750_a_Hecke(Kf)
    return MakeCharacter_3750_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 := [[1, 0], [1, 0], [0, 0], [-2, 0], [-2, -2], [0, 3], [-3, -3], [-6, 2], [-6, 0], [-3, 1], [-6, 6], [7, -3], [2, -5], [-2, 2], [-8, 2], [6, -9], [-4, 8], [-4, -3], [0, 6], [2, -10], [8, -3], [0, 0], [-6, 0], [3, -1], [9, 3], [13, -7], [12, -6], [2, -8], [-12, 9], [-3, 9], [-10, 6], [-4, 2], [-6, 13], [6, -12], [-14, 13], [6, -8], [-13, -3], [-14, -4], [0, -4], [19, -5], [-20, 10], [1, -13], [-4, 2], [-4, 1], [2, 7], [10, -10], [-8, 0], [12, -6], [4, 8], [0, -15], [14, 5], [-12, 24], [-9, -3], [-6, -4], [10, 1], [6, -4], [-10, 5], [12, 10], [27, -3], [2, -5], [0, -2], [11, 11], [26, -6], [4, -14], [-6, 20], [-6, 8], [-26, -4], [10, -24], [2, 2], [-3, 11], [-14, -4], [-2, -16], [6, 4], [-22, 12], [16, -12], [-14, -4], [-18, 21], [10, -24], [-18, -5], [-13, 21], [-12, -16], [-3, -5], [-6, 6], [28, -3], [4, -18], [12, -26], [-13, 11], [6, 4], [17, 5], [22, -6], [-32, 10], [-2, 4], [-20, 6], [4, 16], [-14, -12], [-28, 4], [17, -19], [-18, 15], [12, -6], [-3, 15], [-2, 0], [3, 15], [-4, -4], [23, -1], [24, 6], [10, -24], [-10, 16], [-15, 13], [14, -8], [-4, 7], [18, -10], [7, 9], [-10, 1], [-16, 12], [-14, -18], [-14, -8], [-12, 32], [10, 16], [-5, 23], [26, 8], [-30, 4], [1, 11], [-30, -4], [0, -12], [-8, -10], [30, -31], [-12, -11], [-10, 20], [-20, 6], [-26, 20], [18, -6], [16, -14], [18, -2], [24, 3], [-26, 31], [30, -20], [-6, -5], [18, -30], [2, 7], [-29, 23], [20, -6], [-6, -24], [-12, 22], [-18, 2], [44, -3], [24, -18], [24, -25], [22, -28], [52, -4], [4, -10], [16, -21], [-18, 40], [-26, -10], [-42, 10], [-30, 6], [14, 26], [-14, 8], [3, -21], [-27, -5], [33, -7], [2, -8], [-27, 37], [-28, -8], [18, -32], [6, 9], [-6, 30], [12, 30], [-18, 12], [-44, 3], [18, -13], [6, -12], [0, 9], [2, -10], [1, -9], [34, 12], [11, -17], [6, 2], [-43, 5], [-8, -16], [-11, -13], [12, -18], [-30, 44], [27, -11], [1, -31], [-38, 4], [-18, 16], [-9, 9], [4, -10], [27, -19], [-38, 20], [-14, 36], [-16, 50], [-32, 18], [-30, 9], [-8, -8], [14, 5], [-58, 0], [-20, 3], [30, -39], [-16, -10], [-18, 21], [30, -36], [26, 4], [8, -21], [-18, -4], [-53, 7], [40, 0], [-26, 10], [-14, 23], [30, -36], [0, 1], [-2, 8], [16, -34], [8, 20], [-6, -18], [28, -37], [-6, -22], [14, -49], [-4, -16], [-29, 31], [5, 19], [14, 22], [-42, 24], [26, -24], [-44, 4], [-19, 43], [-22, 17], [-22, 14], [32, -38], [12, -20], [15, 13], [36, -62], [24, -24], [35, -61], [-18, -36], [10, -4], [-61, -3], [-18, -1], [-10, 40], [-18, 0], [50, -2], [-6, -24], [-36, 0], [28, 29], [-18, 49], [-30, 30], [-28, 12], [-18, 30], [-50, 30], [32, -46], [39, -27], [-33, 35], [-12, -30], [12, 31], [-6, 0], [-30, -30], [-39, 27], [-24, 24], [39, 3], [13, -25], [-48, 54], [26, -16], [24, -3], [-12, 27], [-3, -23], [-60, 20], [30, 5], [27, 15], [-28, -6], [-6, 35], [-12, 13], [-30, 16], [28, -3], [12, 6], [-27, -5], [40, -52], [-10, -4], [-39, 3], [-1, -39], [-8, 20], [14, 40], [-12, -12], [-14, 4], [-40, -11], [-22, 0], [-38, 10], [-68, 9], [-1, -37], [-60, 30], [62, 11], [45, -51], [-46, -22], [-71, 25], [6, -18], [-4, 31], [-6, 57], [-28, -30], [-1, -5], [-4, 8], [6, -26], [-12, -3], [-13, 7], [70, 0], [-46, 20], [-32, 18], [-24, 9], [48, -50], [-3, -9], [-8, -44], [18, -48], [66, -24], [-18, -44], [10, -1], [-20, 8], [24, 18], [-17, 29], [10, -20], [-14, -38], [-51, 15], [66, -17], [-8, -10], [-36, -7], [70, -31], [28, 12], [25, -47], [-9, 57], [-6, 12], [54, -30], [-42, 40], [14, -25], [-28, -15], [2, -53], [-48, 66], [26, 26], [-52, 48], [-72, 10], [57, -29], [34, 25], [-36, 31], [8, 30], [27, -71], [2, 32], [-18, -39], [-40, 4], [31, -49], [48, 4], [37, -25], [-62, 30], [-4, -8], [-6, 3], [-12, 58], [4, -27], [65, -11], [-2, 42], [-38, -4], [-30, 33], [-52, 44], [-42, 18], [-15, -19], [-14, 46], [55, 21], [-13, -25], [84, -12], [-36, -38], [-24, 44], [-23, -1], [46, 19], [16, 6], [59, -39], [-28, 50], [14, -48], [-78, -6], [78, -16], [16, -18], [-38, 12], [72, -14], [2, -10], [21, -9], [43, 19], [-51, -17], [-74, -8], [-11, 5], [-34, 84], [-2, 25], [-2, -6], [18, -18], [-16, 6], [-33, 77], [-54, 36], [-66, 28], [-12, -41], [-22, -28], [18, -36], [-18, 22], [30, -46], [-32, -3], [50, 0], [-57, 19], [0, 14], [-58, 20], [25, 15], [-30, 53], [-6, 38], [-14, -11], [42, -24], [-12, -2], [24, 23], [66, -33], [12, 44], [8, 14], [22, -76], [-14, 4], [54, -50], [-64, 22], [56, 9], [14, -4], [-26, 22], [28, 30], [-86, 8], [18, -8], [6, 33], [3, 45], [-78, 32], [42, -74], [-55, 43], [58, -20], [58, -38], [-2, -41], [-12, -42], [4, -38]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3750_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3750_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_3750_2_a_g(:prec:=2)
    chi := MakeCharacter_3750_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_3750_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_3750_2_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3750_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![2, 1]>],Snew);
    return Vf;
end function;