
// Make newform 7600.2.a.br in Magma, downloaded from the LMFDB on 20 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_br();".
// 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_br();".
// 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, -3, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, 0, 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], [0, -1, 0], [0, 0, 0], [0, -1, 2], [1, -1, 2], [-1, -1, 3], [2, -1, 0], [-1, 0, 0], [2, 4, -1], [-1, -1, 4], [5, 1, 1], [3, -5, 2], [-3, -4, 1], [1, 0, 2], [1, 1, -3], [-1, 4, 0], [-2, -6, 2], [-3, 1, 5], [-1, 1, -2], [3, 0, 4], [-3, 2, -1], [4, -3, 0], [3, -6, 7], [2, -2, 3], [7, -5, 3], [-4, -5, 2], [2, 5, 4], [4, 2, -3], [-11, 2, -1], [2, 11, -5], [2, -2, -3], [3, -2, -5], [9, -2, -3], [5, -8, 0], [-3, -8, 9], [6, 15, -11], [4, 4, -9], [1, -3, 3], [1, -8, 9], [-10, -3, 4], [1, 12, -14], [3, 4, -12], [9, 1, 6], [9, 6, -3], [5, 9, -8], [-1, 9, 8], [9, -2, -2], [1, 6, -16], [-7, -2, -9], [-12, -3, 1], [5, -5, -2], [-7, -3, -1], [-9, 0, 3], [4, -7, -3], [10, 1, 6], [11, -1, -9], [2, -3, 7], [13, -7, -4], [7, -4, 12], [-6, 2, -4], [7, -10, 3], [-2, 14, -13], [14, -6, -1], [-1, -5, 15], [9, -9, 8], [3, -6, 15], [12, 5, 7], [-5, -3, 13], [7, 1, 16], [-8, 9, -3], [-6, -11, 11], [-13, -5, 5], [15, -2, 5], [-7, 9, 9], [-11, -3, 1], [9, -3, 21], [-3, 0, 2], [10, 19, -9], [2, 11, 2], [-4, 4, 17], [8, -1, 7], [5, 7, -13], [-15, 7, 10], [26, 0, -3], [-3, 9, 2], [-5, 4, -19], [-3, 21, -7], [-9, 3, -19], [8, 1, 1], [-2, -19, 19], [-13, 12, 11], [-4, 14, -2], [5, -2, -7], [1, 10, -1], [8, 13, -14], [-2, 3, 10], [-5, 20, -13], [12, 14, 2], [-8, -21, 8], [11, 3, 6], [14, 7, 1], [-8, -3, 4], [-13, -17, 10], [12, 10, -14], [-5, -24, 15], [2, 9, -20], [3, 17, -18], [25, 1, -3], [-7, -23, 14], [-9, -30, 19], [11, 2, -17], [0, -13, 15], [16, -6, -2], [-19, -4, 11], [-5, 12, -1], [-5, -12, -8], [-10, 12, -8], [26, 22, -15], [0, 10, 13], [-4, -15, 27], [2, 15, -23], [12, -4, -7], [-13, -5, 6], [12, -17, -14], [-18, 16, 4], [22, -17, -9], [-29, 5, 5], [-21, 5, -1], [-2, 5, 4], [-17, -6, -14], [-4, 3, -27], [16, 8, 5], [-2, 22, 9], [-10, -10, -1], [-13, -22, 11], [-4, 12, -6], [-4, -8, -11], [-5, -1, 5], [-17, 18, -11], [35, -5, 9], [2, -21, 17], [-7, 30, 3], [-20, -21, 17], [-8, -29, 29], [-44, 0, -2], [23, 7, -17], [-15, 15, 0], [20, -13, 21], [11, 14, -15], [-29, 16, -4], [-20, -8, 0], [2, 26, -31], [-32, -1, -2], [-8, -5, 14], [30, 2, 3], [-17, 11, -5], [8, 15, -17], [49, 2, -1], [-26, 3, -12], [1, -2, 5], [0, -10, 9], [33, 12, 3], [-22, -5, 1], [-26, -8, 2], [11, -3, 5], [1, 14, -14], [-3, 18, -19], [-28, -4, -13], [11, 31, -14], [2, 20, -32], [25, -7, -17], [9, -16, 34], [-2, -11, -5], [8, 26, -4], [6, 4, -5], [19, -29, -15], [-2, 24, -4], [26, -17, -3], [-27, 1, -4], [-36, -24, 16], [29, -8, 10], [-5, 16, -13], [-15, 25, -9], [-5, -7, -19], [36, -9, 16], [18, 11, -14], [3, 29, -6], [3, 11, 12], [-32, 7, -26], [-15, -19, 10], [7, 0, -16], [3, 25, -2], [33, -6, 1], [-13, 32, 4], [-9, -2, -18], [34, -6, 22], [-17, 26, -20], [-16, 20, -5], [9, -5, 28], [34, -12, -14], [37, -7, -3], [10, -23, -5], [-3, -6, -22], [-6, -23, 5], [-12, -7, -7], [-1, 1, -12], [9, -25, 15], [-4, 11, 19], [28, 19, -16], [-2, -8, 31], [-24, 5, 13], [-17, 22, -34], [-22, -6, 17], [26, 3, -2], [11, 12, 13], [-4, 17, -1], [-29, -2, -5], [-16, 5, -22], [-39, -13, 4], [-30, -7, 0], [-23, -19, 12], [52, -9, -3], [-17, 1, 1], [44, 13, -13], [-42, 0, -1], [-19, 4, 0], [27, -6, 26], [28, -14, 1], [-10, 0, -32], [-12, 17, -15], [-31, -11, -9], [42, -2, 5], [29, -2, 15], [-16, -6, -21], [-41, -22, 8], [0, 43, -17], [17, 34, -14], [-41, -5, 20], [-20, 21, -53], [-3, 4, -5], [54, -5, -7], [25, 20, -14], [-16, 36, -2], [-19, 33, -7], [6, -23, 1], [1, -5, -19], [-10, 8, 18], [-11, -7, -3], [-23, 15, 24], [6, 18, -18], [-35, 15, -9], [-3, -12, 0], [-49, 4, -1], [10, -10, 8], [-13, -37, 15], [65, 13, -9], [4, 16, -13], [10, -19, -4], [-2, 28, -13], [-19, -45, 15], [-7, 26, -46], [-16, 30, -7], [8, -32, 0], [-33, 23, -22], [-5, -7, 27], [43, 7, -3], [22, 13, 17], [1, -27, 17], [35, 7, -11], [15, -11, -2], [-13, -1, -10], [1, -10, 22], [-24, -35, 19], [-20, -4, -2], [11, 3, -38], [4, 43, -25], [-17, 26, -10], [13, 40, -23], [-45, -21, 17], [-11, 30, 4], [25, -20, 29], [13, 1, -22], [-13, -17, 7], [22, -9, 18], [-8, 30, -40], [16, -22, 22], [-47, 21, -8], [-7, -34, 21], [-27, 1, 26], [-29, 19, 8], [-27, 15, -50], [-35, 24, -21], [29, 6, -16], [47, 6, 2], [-8, -43, 22], [21, 19, -11], [21, 14, 0], [-42, -18, 24], [-7, -1, 19], [-29, 24, -5], [-16, 3, -2], [-23, 16, -31], [30, -7, 33], [15, -2, 4], [20, 19, -30], [0, -21, 34], [-6, -11, 25], [-31, 13, -16], [52, 4, -17], [18, -36, -18], [19, -5, 7], [72, -10, 3], [-14, -6, 17], [-35, -23, -1], [-34, 10, -12], [23, -36, 2], [1, 46, -39], [29, -17, 0], [43, 12, -13], [-25, 3, -40], [-19, -24, -3], [-2, 12, -15], [-12, 6, -34], [-2, -25, 31], [26, -9, 25], [-9, 19, -26], [26, 15, -26], [25, 26, -17], [10, 14, -18], [15, 28, -36], [-17, 19, -51], [-11, 22, -56], [-39, -47, 38], [18, 15, -18], [17, 48, -40], [19, 9, 14], [-49, 8, -8], [-6, -12, -3], [15, -35, -12], [9, -26, 38], [16, 5, 20], [45, 22, -10], [-31, 5, 9], [28, 0, -34], [42, 1, -1], [-28, 15, -16], [14, 14, -11], [7, 49, -46], [-31, -22, 27], [7, 3, 16], [27, 9, 34], [27, -6, 45], [-36, 1, 2], [-19, -2, 3], [-28, 10, -20], [-14, 21, -40], [-23, -25, 33], [-30, 2, -19], [21, 16, -14], [2, -14, -18], [-19, 29, 8], [-24, 26, 7], [61, -23, -7], [16, 24, 7], [-32, 15, -43], [25, -30, 8], [17, -13, 57], [16, -28, -25], [-10, 25, -55], [-22, 17, 4], [1, 53, -13], [16, -18, 15], [4, -14, 29], [24, -41, 2], [-3, 3, 5], [5, -4, -43], [21, 15, -18], [-8, -2, -5], [-8, 12, 9], [-17, 23, 29], [-2, 37, 17], [-13, -27, 31], [24, 27, -4], [27, 35, -28], [-28, 6, -22], [21, 8, 12], [-36, -14, -18], [52, -5, -15], [-12, -33, 1], [39, -32, -1], [10, -29, 37], [21, -18, 61], [19, -15, 7], [-17, -16, 1], [-53, -28, 21], [45, -15, -10], [-49, 8, -21], [-85, -2, -3], [38, 1, 23], [-12, -45, 46], [11, -43, 29], [62, -19, 13], [20, 24, 0], [55, -22, 7], [14, -41, -14], [-44, -24, 11], [-9, 40, 15], [4, 35, -19], [-33, 13, -12], [14, 38, -17], [-45, -27, 10], [-49, -5, 9], [-25, 12, -16], [-39, 2, 12], [-1, 1, 5], [26, 38, -32], [-44, 27, -11], [-30, -37, 25], [-43, 23, 14], [37, 39, -7], [21, 6, -35], [33, -5, -1], [63, -16, 3], [17, 16, 29], [-6, 36, -20], [-17, 13, -28], [1, 40, 0], [-50, -26, 29], [-6, -27, -2], [-29, 7, -20]];
    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_br();".
// 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_br(: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_br();".
// 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_br( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7600_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![1, -3, 0, 1]>,<7,R![9, -9, 0, 1]>,<11,R![17, -6, -3, 1]>,<13,R![17, -18, 3, 1]>],Snew);
    return Vf;
end function;