
// Make newform 7600.2.a.bd 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_bd();".
// 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_bd();".
// 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, 0, 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_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], [1, 1], [0, 0], [0, 0], [-2, 0], [-1, 1], [-4, -2], [-1, 0], [2, -2], [0, -2], [-4, 0], [1, -5], [4, -2], [4, -4], [4, -4], [3, 5], [2, -2], [-10, 2], [1, -3], [-4, -4], [0, 6], [-2, 6], [-2, -2], [0, -2], [7, 5], [-2, 2], [-3, 5], [3, 7], [-14, 0], [-15, -1], [9, 5], [-12, 0], [-4, 2], [6, -8], [-2, 10], [2, 2], [4, 2], [-4, 0], [-5, -1], [5, 7], [6, 2], [-2, -8], [4, 4], [-9, -3], [2, -8], [12, 4], [6, 6], [7, 11], [3, -1], [2, 2], [-14, 0], [12, 4], [0, -6], [-12, 8], [-23, -1], [2, 10], [-2, -4], [-14, 0], [24, -2], [-12, -6], [-6, -2], [-13, -3], [27, -1], [-6, -8], [2, 8], [-9, 9], [10, -14], [-3, -5], [2, -6], [-2, -12], [-8, -14], [-2, -4], [4, 4], [-5, -3], [0, 20], [27, 3], [-2, -8], [16, 2], [14, 0], [22, -4], [-12, -8], [-8, 14], [-18, -6], [1, 15], [-2, -14], [-30, -2], [-2, -20], [-22, -4], [14, 0], [-14, 14], [-18, -10], [-6, -8], [41, 1], [-12, 8], [-10, -12], [6, 10], [-8, 6], [-6, 0], [-17, -1], [-34, 6], [1, 9], [12, -14], [7, -9], [-6, 12], [10, 12], [-22, -8], [-2, 22], [22, 8], [-2, 26], [-40, 2], [9, 17], [-20, -14], [0, -2], [14, 0], [14, -20], [0, 26], [26, -14], [-30, -10], [24, 6], [-22, -6], [-20, 2], [39, -3], [3, -19], [-21, 3], [18, 12], [2, -14], [-2, 12], [6, 24], [28, -4], [30, -8], [-4, 0], [-7, 21], [-22, -2], [22, -12], [14, 6], [14, 6], [-5, -3], [5, -3], [3, -11], [-18, 16], [0, -8], [2, 12], [-20, -4], [3, 19], [-6, -16], [-34, 6], [6, -12], [17, 7], [-44, 8], [-27, 1], [-17, 17], [2, 6], [4, 20], [-33, 7], [-5, -17], [-46, -2], [4, -4], [-50, 0], [-40, 6], [42, -4], [-26, -14], [33, -9], [-26, -18], [0, -4], [-21, 17], [19, -13], [-14, 10], [28, 6], [8, 6], [0, 2], [8, 16], [-14, 4], [34, -12], [-14, 0], [-12, 12], [-34, -2], [44, -8], [6, -14], [37, 1], [38, -10], [-14, -18], [-12, 8], [-1, 17], [-13, -15], [-38, -14], [10, 4], [-35, -17], [19, 19], [34, 12], [-20, 4], [1, -1], [18, 18], [32, -4], [-12, -2], [20, -4], [33, -17], [2, -20], [-18, -4], [-30, 0], [24, 4], [36, 2], [10, -6], [-13, -19], [-4, 14], [-6, -24], [0, 26], [-10, 20], [15, 11], [-54, -4], [4, 0], [-34, 8], [30, -22], [-18, -22], [-37, -5], [28, -16], [-4, -6], [20, 0], [-46, 12], [-7, -19], [-14, -20], [-12, -10], [-20, 12], [-8, 30], [-22, -2], [-61, -1], [-6, 16], [-13, -7], [-20, -12], [-25, 7], [32, -4], [-18, 8], [8, 32], [18, -26], [8, -18], [-10, -6], [-24, -12], [-10, 30], [18, 16], [30, 20], [6, -6], [25, -11], [-28, 16], [8, 28], [0, -14], [-21, 9], [12, -28], [20, -20], [-6, 2], [40, 12], [12, 0], [14, 24], [-6, 24], [-70, -2], [-26, 12], [-10, 16], [36, 16], [18, 8], [41, -3], [15, 1], [-8, 30], [13, -3], [39, -1], [30, 10], [-21, -3], [6, -8], [38, 10], [-12, 14], [38, -14], [7, 3], [18, -24], [-34, 24], [-5, 35], [0, -30], [-22, -20], [-13, 25], [48, 4], [-40, 12], [-44, 6], [-8, 10], [-6, -40], [27, 19], [-18, 8], [-26, 18], [10, 0], [46, 2], [14, -32], [-6, -8], [-73, 1], [-16, -40], [42, 20], [2, 20], [-16, 12], [-9, 5], [30, 22], [37, 23], [-18, 6], [-28, 8], [54, 0], [-48, 16], [36, -20], [-16, -38], [45, -17], [-34, -16], [45, 21], [-48, -20], [-23, -17], [-33, -9], [16, 14], [52, 12], [-6, 0], [56, 12], [-34, 2], [14, -32], [3, -5], [-30, 26], [12, 22], [-58, 4], [-30, 22], [-26, 8], [-66, -8], [68, 0], [-4, 18], [52, 22], [19, -13], [-4, 10], [12, 18], [-2, -22], [-5, 11], [-3, -23], [20, 14], [14, -38], [-43, 15], [50, 8], [84, 0], [-30, 28], [16, -40], [30, 28], [21, 3], [-2, -8], [10, -26], [29, -9], [28, -14], [-14, -28], [68, 4], [-5, -11], [-54, -2], [-6, 16], [-69, -5], [-68, -4], [0, 22], [44, 20], [-33, 21], [-10, 26], [27, 35], [44, -6], [-17, -19], [36, -28], [-72, 12], [-12, 6], [-3, -7], [52, 6], [-50, -2], [-51, -11], [-60, 20], [-2, -10], [37, 11], [-52, 22], [-13, -45], [16, 38], [-6, -20], [-14, -6], [-4, -36], [18, 20], [56, 8], [68, 14], [-16, -48], [-48, 24], [-70, 0], [-14, 24], [-61, -15], [30, 8], [-22, 40], [68, 8], [78, 12], [42, -26], [25, 1], [10, 4], [64, -10], [76, 4], [49, -23], [10, 24], [-11, -41], [-48, -4], [-38, 14], [66, 2], [-25, 5], [22, -10], [12, -38], [16, -16], [-22, -16], [-70, 12], [30, -28], [31, -21], [-41, 29], [-34, 0], [-28, 4], [-4, -10], [-2, 12], [-49, 23], [-60, 16], [13, -5], [-42, 20], [-81, 11], [62, -16], [20, 10], [66, -8], [6, 38], [-43, -31], [16, 6], [-5, -13], [-46, 8], [7, 1], [40, 4], [4, 8], [-47, 7], [-3, 31], [7, 23], [-18, -46], [-4, -16], [10, -48]];
    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_bd();".
// 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_bd(:prec:=2)
    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_bd();".
// 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_bd( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7600_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-2, -2, 1]>,<7,R![0, 1]>,<11,R![2, 1]>,<13,R![-2, 2, 1]>],Snew);
    return Vf;
end function;