
// Make newform 7600.2.a.bh in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7600_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_7600_2_a_bh();".
// 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_7600_2_a_bh();".
// 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, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-3, -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_7600_a();"
function MakeCharacter_7600_a()
    N := 7600;
    order := 1;
    char_gens := [4751, 5701, 5777, 401];
    v := [1, 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_7600_a_Hecke(Kf)
    return MakeCharacter_7600_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], [-1, 1, 0], [0, 0, 0], [-1, -1, 0], [0, -1, 0], [2, 0, 3], [5, -1, 0], [-1, 0, 0], [-4, 1, -3], [-2, 1, 0], [0, 2, 1], [2, -3, -2], [3, -3, 5], [5, -4, 6], [0, -4, 5], [11, 0, 2], [0, 4, -2], [2, -2, 1], [2, 3, -4], [-1, -2, 2], [-1, 1, -3], [7, 1, 4], [-5, 9, -3], [-4, -3, 5], [-6, 4, -1], [1, 7, -2], [7, -1, 4], [6, -5, 9], [-3, 9, -5], [-7, 4, -3], [8, 3, -3], [1, -5, 3], [11, 3, -1], [3, -6, -4], [-5, -1, -7], [-1, 2, -5], [6, -9, 5], [-16, -2, -1], [-1, 7, -9], [-1, -3, -6], [5, -8, 4], [-3, 0, -10], [-10, 9, 0], [-1, 13, -9], [8, 5, 0], [8, 3, -6], [7, -2, 0], [17, 0, 6], [13, 3, -3], [5, -10, 5], [-2, 1, 6], [12, -2, 13], [-11, -5, 7], [9, -2, 7], [15, -9, 4], [-4, 0, -5], [9, 2, 3], [-6, 11, -2], [13, -8, 4], [-4, 2, -12], [11, -7, 1], [8, 7, 3], [8, 1, 3], [4, 4, 9], [-2, -5, 4], [21, -1, 1], [-5, -2, -7], [-4, 8, -11], [0, 5, -2], [9, -6, 17], [9, 0, 5], [16, -6, -1], [-13, 15, -5], [14, -12, 1], [4, 2, -7], [20, -6, 7], [-15, 10, -10], [-9, 2, -3], [-1, -17, 8], [12, -3, -9], [3, 10, -7], [8, -12, 17], [22, -5, 4], [-2, 3, 5], [0, 5, 0], [-7, 1, -1], [10, 0, -5], [-14, 12, 7], [-19, 14, -3], [5, -4, -9], [-11, 3, -7], [-22, 0, -2], [13, -7, 7], [7, -9, -9], [7, 3, -12], [9, -5, -12], [-7, -13, 7], [2, -8, -6], [-13, 13, -8], [24, -5, 2], [17, -6, -7], [25, 5, -8], [20, -7, 0], [-6, 0, -6], [-1, -7, 7], [15, -15, 12], [-8, -13, 4], [10, -10, 11], [-4, -7, -8], [-9, 17, -17], [11, -5, -11], [-27, 6, -19], [6, -4, -10], [-15, 9, -17], [3, -11, 3], [-35, 4, -14], [-22, 16, 4], [-2, 13, 7], [8, 19, -13], [7, -22, 13], [23, -6, 9], [-16, -1, 13], [-2, 5, 10], [15, 3, 10], [26, -8, 12], [13, 10, -9], [4, -10, 9], [-30, 10, -15], [-1, 11, -6], [7, 8, -6], [7, 4, 15], [-8, 1, 13], [12, -19, 11], [-6, 17, -15], [15, -9, 15], [12, 10, 2], [28, -9, 1], [16, -16, 7], [-15, -7, 3], [30, -16, 13], [-25, 10, -13], [9, 7, -9], [13, -20, 17], [15, -14, 5], [8, 18, -6], [4, -6, 7], [38, -1, 12], [-5, -2, 3], [5, 1, 17], [-15, 10, -6], [16, -28, 12], [14, -3, 1], [-9, -17, 16], [7, -5, -10], [-16, 13, -17], [-4, -6, -9], [3, -18, 17], [-3, 11, -1], [-3, -9, -4], [21, -9, 1], [8, 5, -9], [1, 5, -3], [-33, -8, 9], [14, 2, -10], [4, -12, -3], [13, -2, -12], [3, 19, -7], [-14, -17, 9], [-30, 15, -10], [18, -4, -4], [-16, -4, 11], [7, 22, -16], [-5, 12, 1], [-2, 14, -8], [-14, -15, 1], [10, -12, 1], [-14, 24, -24], [21, -20, -11], [-12, 5, 2], [-28, 4, -20], [-11, -24, 14], [-25, -13, 11], [-2, -2, 15], [-12, 12, 9], [-1, -19, 10], [3, 7, -18], [-32, 7, -6], [-24, 7, -6], [5, -5, 0], [42, -15, 4], [-21, 8, -14], [8, 7, 16], [-29, -9, 5], [-11, -12, -2], [1, -14, -14], [-16, -12, -14], [9, 10, -8], [-10, -1, 9], [-14, 15, 8], [2, 10, 6], [-6, -20, 19], [29, -18, 25], [-9, 20, -12], [-23, 8, 13], [5, 10, 15], [46, 9, -4], [-18, 16, -11], [3, 4, 15], [-3, -11, 0], [42, -7, 5], [-17, -14, 7], [-27, 8, -18], [-10, 21, 11], [25, -21, 26], [19, -15, 29], [7, -18, -1], [-25, 1, -15], [-21, 5, 12], [22, -9, 2], [35, -19, 8], [14, -29, 4], [5, -6, 3], [4, 0, -1], [31, -16, 3], [-6, 3, 3], [13, -4, 20], [-7, -4, 16], [-38, 17, -29], [2, 4, -12], [17, 2, -17], [-30, 24, -11], [-36, 9, -13], [23, -19, -13], [50, -11, 21], [17, 0, 16], [-59, -2, -5], [11, 0, -14], [8, 3, 20], [-43, 24, 5], [9, 7, -25], [29, 14, 1], [15, 4, 10], [-12, 34, -30], [-26, 8, -5], [-1, 28, -9], [-30, 26, -33], [18, -2, 22], [-24, 10, -7], [-26, -7, -10], [-16, 4, 6], [-32, -2, -19], [9, 4, 20], [9, -5, -3], [-4, -2, -8], [30, -18, 5], [-20, 2, 9], [-34, -11, 7], [-61, -9, 4], [34, -7, 7], [-32, 18, -19], [-23, 14, -16], [-26, -9, 9], [32, -24, 4], [-14, -27, 18], [-16, 16, -27], [16, 0, 21], [-19, 8, -3], [14, 6, 9], [16, 4, -17], [46, 7, 6], [-26, 23, -22], [37, -2, 16], [-17, 8, 5], [0, -14, 22], [6, -7, -6], [21, 2, -1], [13, 10, 6], [-37, -7, 9], [30, 18, -1], [33, -12, 16], [-9, 23, -9], [-38, 5, -36], [-12, 24, -21], [51, 3, 0], [-10, 30, -12], [-2, -4, 2], [-28, -19, 0], [-21, 13, 7], [-34, -7, -8], [-14, 17, 20], [-26, 7, -14], [-9, 15, -11], [39, -18, 34], [-7, 18, -4], [21, -9, -16], [-4, 24, 9], [51, 8, -6], [-4, 26, -36], [-46, 18, -5], [-23, 3, 1], [-9, 13, -22], [57, -17, 15], [43, -18, -13], [-9, -20, 10], [49, -3, 0], [27, 9, -8], [-49, 16, -39], [-10, 31, -28], [-2, 7, 27], [10, -26, 34], [20, -20, 19], [-52, 7, -13], [24, 3, 3], [8, -4, 9], [20, -14, 40], [21, -30, 16], [-17, 9, 1], [62, -3, -2], [27, -13, -3], [-8, -19, 4], [-27, 5, -15], [-12, 17, -1], [42, -4, 22], [-7, 28, -17], [23, -16, 7], [-10, 31, 10], [-5, 5, -10], [-23, -1, 9], [24, -20, -18], [13, -28, 8], [10, 8, 29], [59, -2, 22], [26, -15, -4], [13, -13, -24], [31, 14, -24], [12, 11, 12], [9, -24, 6], [-14, -25, -3], [-38, 23, -44], [-25, -22, 14], [69, -11, -2], [29, 4, 34], [14, 12, -17], [40, -18, 6], [39, -2, 1], [-11, -5, -36], [2, -15, 5], [-46, -9, 4], [-33, 17, -17], [36, -9, 20], [-2, -19, 32], [29, -11, -1], [35, -3, 22], [-63, 7, -15], [2, 38, -12], [3, -7, -10], [6, -18, 15], [22, 7, 13], [39, -10, 46], [8, -8, 6], [-4, 5, 8], [-4, 11, -9], [12, 22, -1], [28, 5, -7], [-19, 16, 1], [43, -34, 26], [-16, 0, -9], [12, -41, 19], [53, 12, 5], [33, 1, -18], [-4, -12, 7], [8, -1, 25], [-2, -9, 15], [-51, 21, -12], [-36, 12, -5], [41, 1, 13], [36, 3, -16], [-36, -7, -19], [30, -5, 25], [-50, 18, -27], [9, 48, -27], [-8, -8, -3], [-57, 13, -18], [-4, 3, -16], [14, 4, -18], [39, 14, 6], [-62, 4, -2], [33, -20, 35], [29, 16, 5], [-23, 33, 1], [-1, 2, 13], [35, 37, -25], [-14, 14, -31], [33, 1, -17], [55, 1, 9], [-18, 43, -26], [23, -13, 27], [-41, 23, -15], [-11, 22, 5], [-15, 23, 14], [-28, -16, -5], [9, 22, -21], [-32, 16, -12], [41, -17, -11], [-17, -21, 16], [-10, 3, 3], [7, -17, -35], [53, -30, 21], [-18, 9, -26], [10, 21, -13], [36, -1, 30], [6, -32, 19], [-47, 2, -14], [-23, -40, 24], [40, -34, -1], [-8, -38, 24], [13, -14, -5], [-7, -2, -23], [-14, 13, 14], [86, 4, 3], [41, 7, 5], [28, -24, 27], [-47, 31, -27], [-35, 33, 1], [-2, 12, 28], [-36, 13, -48], [31, -2, 26], [-2, -15, 13], [-7, 7, 4], [62, 13, -2]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7600_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7600_2_a_bh();".
// 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_7600_2_a_bh(:prec:=3)
    chi := MakeCharacter_7600_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_7600_2_a_bh();".
// 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_7600_2_a_bh( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7600_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-5, -3, 2, 1]>,<7,R![-1, 1, 4, 1]>,<11,R![1, -4, 1, 1]>,<13,R![103, -36, -3, 1]>],Snew);
    return Vf;
end function;