
// Make newform 7605.2.a.bs in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7605_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_7605_2_a_bs();".
// 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_7605_2_a_bs();".
// 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, -5, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-4, 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_7605_a();"
function MakeCharacter_7605_a()
    N := 7605;
    order := 1;
    char_gens := [6761, 1522, 6931];
    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_7605_a_Hecke(Kf)
    return MakeCharacter_7605_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, -1, 0], [0, 0, 0], [1, 0, 0], [1, 0, 1], [-2, 1, 1], [0, 0, 0], [2, 0, 2], [2, 1, -1], [3, -1, 0], [1, 0, 1], [4, -1, 1], [7, 0, 1], [2, -2, 2], [-3, -1, 2], [1, 0, 1], [-2, -2, -2], [4, 1, 1], [-1, -2, 1], [7, -2, 1], [-2, -1, 1], [5, 4, -1], [6, -4, 2], [-5, -2, 1], [2, -4, 2], [-4, 0, 2], [-12, 2, 0], [5, -3, -2], [-3, 5, 0], [4, -4, -2], [4, -4, 4], [3, 3, -2], [2, -4, 2], [0, 6, 0], [-6, -4, -2], [4, 0, -2], [6, 7, -3], [6, -2, 4], [11, -4, -1], [-11, 2, -5], [8, -2, -4], [-6, 6, 0], [-5, 4, 3], [-4, 0, -4], [-8, 6, 4], [-6, 2, -6], [-2, -2, -4], [6, 6, -4], [-3, -4, -3], [-5, 10, 1], [14, -6, -4], [-16, 0, 2], [-14, -1, -5], [0, -6, 0], [0, -6, 6], [-10, 8, -4], [3, 9, 0], [0, -2, 0], [-4, -5, -1], [-6, 10, 2], [-8, -2, -8], [5, -5, 6], [15, 0, -3], [7, -10, 1], [-10, -2, -4], [-12, 4, -4], [3, 8, -3], [26, -3, 5], [-2, -8, 2], [-11, -7, -2], [-12, 2, -6], [-11, 4, -5], [14, -9, 5], [-13, -7, 0], [14, -2, 4], [10, 7, -5], [1, -6, 7], [2, -8, 8], [-13, 0, -7], [-16, 4, -4], [-14, -2, -2], [-4, 2, 2], [0, -16, 6], [4, 1, -5], [14, 4, 0], [4, -10, 6], [-21, 3, -6], [-8, 10, -8], [8, -8, -10], [6, -14, 0], [-1, 0, -1], [15, -9, -6], [-6, 3, -3], [19, 4, -5], [4, -4, -8], [2, 13, -1], [25, -3, 4], [-14, -2, 4], [-11, 8, 1], [11, 9, 0], [16, 6, -2], [-21, 7, -8], [13, 4, 7], [-5, 13, -2], [-13, 2, 5], [10, -12, -10], [-19, 12, -1], [13, 0, 1], [20, -8, 2], [-18, -2, 0], [-2, -4, 0], [-3, 5, -8], [6, -8, 0], [16, 2, -8], [-8, -1, 7], [10, -7, 1], [2, 20, -4], [7, 8, 7], [21, 5, -6], [-8, -10, 10], [8, 2, -10], [-2, -16, 4], [-12, 4, -4], [20, 2, -4], [-43, -2, -1], [8, 1, -1], [4, -2, 4], [8, 10, 2], [6, 12, -6], [-9, -1, -8], [-6, -6, -6], [10, 1, 13], [13, -6, -5], [-12, 10, 2], [-32, 2, 0], [22, -4, 10], [10, -4, 10], [13, 16, -5], [15, 14, -3], [4, 6, -2], [3, 0, -9], [12, -11, 3], [4, 4, -2], [-5, 1, -12], [31, -6, 1], [-17, 14, 5], [8, 5, 11], [-7, -4, -1], [28, 8, -2], [-20, 8, -12], [11, -16, 11], [-2, 0, -8], [1, 10, -5], [-33, -5, 4], [23, 7, 2], [21, -11, -2], [6, 14, 0], [6, 2, -4], [-26, 6, -2], [-8, 8, 6], [-18, -2, -12], [-5, -14, 1], [-12, 12, 6], [-7, -6, -1], [-6, 6, 12], [-5, 0, 13], [-7, 4, -7], [-16, 10, 6], [16, -14, 8], [10, -12, 10], [-18, -6, 6], [-12, 17, 3], [22, -10, 16], [-36, 4, -12], [3, 4, -3], [-28, 2, -14], [-10, 8, 8], [38, -3, -1], [-4, 14, 14], [3, 21, -10], [38, -8, 4], [11, 8, -1], [-14, -14, 4], [0, -14, -4], [-24, 6, 0], [21, 2, -9], [7, -8, -5], [-8, 6, -6], [-25, 8, -1], [-4, 18, -4], [18, 9, -9], [6, 4, -2], [3, 6, 9], [-22, 10, 0], [-22, 0, -4], [-7, 7, 2], [-10, 8, -4], [-8, -6, 4], [32, 10, -6], [-3, 8, 3], [39, -11, 18], [24, 2, 6], [10, -12, 14], [-6, -4, 12], [-7, 16, 9], [-6, -5, 15], [-16, 14, -4], [-46, 13, 5], [7, 19, -14], [8, 8, 8], [20, 8, 0], [6, 12, -8], [-23, -6, -5], [21, -17, 2], [-25, -4, 11], [-16, 13, -19], [28, -6, 4], [19, -19, 0], [-12, -10, 0], [-1, -20, -1], [-10, -2, 2], [-1, 10, 9], [20, 7, 5], [20, -12, -4], [57, -6, 3], [3, 19, -6], [11, -22, 1], [-16, 8, -10], [0, -22, 6], [-19, 3, -18], [8, -5, -13], [-8, -18, 6], [-28, -4, 0], [-36, 1, -15], [36, -2, 0], [31, -3, 8], [-19, -16, 5], [-14, 26, -2], [-21, -8, 9], [-6, -2, -12], [20, -22, 14], [21, -10, 3], [-34, 14, 12], [-5, 3, 0], [-24, 18, -6], [4, -6, -8], [-20, 2, -2], [-17, 20, 7], [-12, 5, 3], [48, -5, -3], [-33, -5, -6], [-21, 12, -3], [-6, 16, -18], [-33, -12, 3], [-22, -16, 0], [32, -10, 2], [2, -11, -1], [-27, 16, -7], [1, 20, 1], [22, -2, -8], [-15, 24, 3], [-1, 1, 6], [1, 9, 10], [22, 2, -8], [-20, 18, 8], [-23, 4, -17], [-6, -6, -4], [26, -22, -4], [-52, 4, 8], [-19, -10, -13], [26, -10, 2], [-16, 10, 12], [-5, 0, -5], [-20, -14, -8], [18, 6, 8], [-46, 4, -2], [-9, -22, 9], [43, -10, 1], [46, -6, -8], [-12, -14, 0], [-14, -20, 10], [-9, 9, -18], [10, 1, 13], [-3, 3, -18], [-50, 2, 4], [27, -6, 9], [8, 2, 14], [28, -8, 18], [6, 12, 12], [-40, 21, -7], [3, -14, 9], [25, -18, 19], [-27, -7, 0], [-28, -8, -10], [0, -3, -9], [36, -14, -14], [-14, 12, 4], [22, -10, 20], [-8, 34, -14], [18, -6, -12], [45, -2, -9], [12, 8, 14], [-22, -16, -4], [2, 18, -8], [25, -5, 16], [28, 14, 2], [-39, -8, -9], [-15, 3, 0], [4, -6, -16], [12, 21, 3], [22, 14, 8], [25, 17, -2], [-6, -6, 12], [-55, 0, 5], [-37, 1, -2], [33, 6, -9], [-19, 0, -11], [40, 7, 7], [24, 3, -9], [21, -28, 3], [-16, -22, -4], [8, -2, 10], [17, 8, 23], [61, -2, 7], [-5, 12, -5], [7, 16, 13], [33, 2, -13], [0, -17, 3], [17, -14, -13], [31, 1, -8], [-20, -2, -26], [-20, 4, 10], [2, -22, -16], [38, -10, 28], [-5, -18, 1], [50, -5, 17], [9, 6, -9], [26, 16, -4], [20, -32, 14], [10, 14, -2], [9, 15, -4], [10, 26, -2], [-4, 0, -4], [24, -8, -18], [18, -8, -10], [-30, -6, 6], [-14, 32, -2], [-16, 6, -8], [-13, -8, 11], [8, -11, 17], [-14, -26, 4], [-26, 17, 13], [-60, 2, 0], [-42, -4, 12], [-29, -7, -4], [26, -24, 12], [14, 16, 14], [14, 5, -19], [-8, 35, -11], [26, -4, -4], [-3, 16, 9], [5, 16, -1], [-13, -16, -13], [21, 7, 12], [-26, 13, 1], [39, 5, 2], [-30, -16, -2], [38, -4, 8], [17, -14, 11], [30, -24, 8], [2, -22, -4], [16, -12, 0], [-3, -6, 15], [23, 14, -7], [34, -12, -6], [26, -18, 6], [50, -21, -7], [-38, 16, 10], [0, 0, -18], [1, 38, -17], [-84, 4, -4], [44, -18, 2], [15, -12, -15], [15, 14, -15], [7, -8, 13], [40, 5, 19], [-15, 24, -15], [-48, 23, -15], [50, -18, 18], [-11, -6, 19], [33, 27, -6], [-12, 22, -12], [49, -8, -5], [24, -7, 9], [17, 11, -2], [44, -3, 5], [16, 24, -6], [40, 13, 7], [33, -20, -3], [-4, -6, -2], [30, -24, 24], [-74, 4, -8], [32, -16, -4], [-5, -28, 7], [-51, 16, -9], [-60, 12, -6], [16, 10, 6], [29, -12, 11], [-34, -4, 2], [-13, 16, 23], [36, 5, -3], [56, -20, -14], [-4, -18, 8], [69, -1, -6], [4, -2, 18], [-12, -28, -10], [-2, -20, -20], [-6, -33, 15], [-33, 25, -34], [-47, 16, 7], [29, -13, -16], [25, -26, -5], [22, -18, -2], [45, 0, -3], [-56, 20, 4], [-4, -4, 2], [-17, 4, -23], [-9, 1, -6], [-28, 22, -16], [-8, -7, 13], [-66, 6, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7605_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7605_2_a_bs();".
// 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_7605_2_a_bs(:prec:=3)
    chi := MakeCharacter_7605_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_7605_2_a_bs();".
// 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_7605_2_a_bs( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7605_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-3, -5, 1, 1]>,<7,R![12, -8, -2, 1]>,<11,R![-54, -6, 6, 1]>],Snew);
    return Vf;
end function;