
// Make newform 7605.2.a.bj in Magma, downloaded from the LMFDB on 23 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_bj();".
// 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_bj();".
// 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_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 := [[1, 1], [0, 0], [-1, 0], [0, 1], [2, 0], [0, 0], [1, 1], [-4, -2], [-2, 0], [5, 1], [1, -2], [0, 6], [9, -1], [-4, 3], [5, 3], [6, -2], [3, -5], [-5, -6], [-4, 3], [3, -1], [0, -1], [-11, 0], [4, 4], [-7, -1], [0, -3], [0, 6], [4, -1], [-3, 3], [-5, 6], [-8, 6], [8, 5], [-3, -3], [3, -5], [13, -4], [-8, -8], [6, 4], [-2, 1], [16, -3], [8, -8], [-7, 3], [-9, 5], [-2, -6], [-7, 9], [-14, 3], [-6, 6], [-11, 8], [5, -10], [-12, -8], [3, -1], [-8, -12], [4, -14], [0, -8], [4, 0], [10, 2], [-3, -3], [-15, -7], [13, -9], [19, -2], [-16, 6], [13, 1], [4, -7], [-3, 3], [2, 5], [3, 9], [14, -3], [18, -6], [17, -4], [10, -9], [-2, -2], [17, -8], [20, 6], [5, 3], [-4, -11], [16, 5], [3, -2], [21, 1], [18, 2], [8, -1], [6, -14], [-11, -10], [7, -19], [-1, -8], [28, 4], [0, -11], [-9, 6], [-17, 7], [-12, 2], [8, 13], [-9, -11], [-10, -5], [-19, -5], [1, 23], [16, 6], [-7, -15], [-8, 10], [6, -4], [18, 0], [-29, -3], [-2, -18], [-13, -14], [-6, 15], [-6, 2], [14, -12], [-7, -15], [-22, 12], [-12, -2], [-3, 15], [12, -2], [-7, -15], [-14, -2], [8, -6], [30, 1], [-4, -22], [25, -4], [15, -6], [0, -2], [-2, -9], [18, 8], [9, 13], [-6, -14], [5, -18], [-32, -11], [-44, 4], [-1, 9], [-21, 4], [34, -2], [-13, 14], [-15, 5], [6, 5], [-12, -15], [8, 4], [3, -19], [0, -6], [-12, 4], [32, 4], [12, 12], [-12, 6], [32, -7], [-1, -5], [6, -22], [17, 20], [-34, 0], [-30, -10], [-3, 5], [29, -10], [-28, 6], [-24, 5], [53, 3], [5, -4], [4, 30], [16, 6], [26, 6], [30, -1], [-39, -1], [32, -14], [-2, -26], [-10, -8], [48, 4], [-16, -2], [-19, 13], [21, 5], [-16, 2], [-10, -22], [18, 6], [-42, 2], [-24, -6], [-6, -4], [-4, -3], [-13, 12], [-15, 7], [37, -1], [-28, 8], [18, 0], [-14, -19], [22, -12], [21, -11], [-25, -4], [-2, 8], [-14, -9], [-23, 10], [16, 8], [-27, -3], [28, 13], [-3, -17], [3, -23], [16, -6], [42, 9], [-8, -16], [-37, 12], [19, 17], [20, -9], [-17, -9], [27, 10], [-33, -1], [27, 1], [-4, 20], [-3, 12], [20, -3], [-9, 13], [23, -3], [49, 3], [57, -2], [12, 25], [-3, -2], [-2, -12], [39, -1], [23, 12], [46, -14], [42, -6], [-16, -20], [16, -23], [36, -16], [32, 19], [-39, -1], [-12, -20], [2, 18], [-12, 23], [-12, -6], [-21, 13], [3, -29], [-61, 0], [31, 14], [-26, 18], [-60, -1], [-20, -28], [5, 2], [-30, 0], [6, -30], [-10, 11], [59, 9], [16, 3], [23, 18], [44, 4], [45, 5], [-20, 25], [8, -10], [-11, -6], [15, 13], [19, -23], [-50, -8], [42, -6], [-32, 2], [-6, 30], [11, -30], [26, 16], [-6, -18], [4, 13], [6, 12], [17, -4], [16, 28], [-26, -7], [7, -33], [-23, 23], [17, 6], [7, 1], [-29, 3], [-18, -6], [32, -6], [-45, -5], [-28, 4], [-14, 10], [-27, 9], [15, 14], [-34, 3], [17, -15], [55, -8], [-9, 15], [11, -1], [28, 20], [-46, -10], [27, 16], [28, 1], [-22, -8], [8, 26], [-4, 23], [-12, -8], [6, 8], [-42, 16], [-61, 0], [26, -2], [5, -25], [56, -8], [-48, 18], [9, -10], [32, 4], [62, 4], [22, -5], [5, 7], [-35, 0], [-7, 29], [51, 9], [-9, 29], [10, 2], [-6, -32], [4, 21], [21, 11], [-28, -12], [18, 8], [-16, 42], [22, 7], [12, -1], [-65, 1], [4, -20], [59, 1], [-35, 8], [-16, -33], [-14, -16], [-66, 4], [39, 7], [46, 8], [45, 9], [-22, -16], [-25, 9], [-78, 1], [45, -9], [-45, -22], [39, 29], [-22, 4], [-4, 41], [-21, -5], [-41, 20], [-26, -5], [-3, -5], [40, 9], [8, 38], [5, -10], [27, 2], [74, -2], [-3, -29], [-27, -17], [34, 30], [17, 31], [73, 12], [-15, 45], [-45, -16], [-12, -18], [55, 10], [38, 4], [46, -8], [-8, -11], [-8, -16], [72, 12], [17, 13], [5, 22], [-9, -11], [48, 14], [-21, -4], [74, 2], [-3, 37], [-30, 38], [7, 16], [10, -16], [-10, -6], [-14, -27], [-28, -12], [26, 6], [-49, 21], [25, -13], [10, 30], [30, -22], [10, -12], [12, -36], [-2, 32], [39, 11], [40, 23], [-18, -1], [31, 27], [62, 5], [-8, -24], [33, -1], [23, 6], [-32, -30], [18, 34], [14, 4], [-52, -4], [-21, 33], [2, -22], [20, 31], [13, 17], [28, 21], [6, 6], [59, -19], [46, -6], [25, 15], [-45, -30], [-85, -1], [10, -12], [40, -23], [18, 23], [24, -2], [6, -2], [-57, 9], [28, -32], [-8, -10], [-53, 9], [-28, 3], [46, -16], [25, -3], [-10, 16], [19, -27], [1, 52], [-65, -7], [32, -15], [29, -29], [-37, 5], [-23, -8], [8, 13], [5, -21], [86, -3], [12, 4], [-26, -13], [51, -17], [69, 3], [-20, 20], [14, -29], [-13, -7], [-24, -4], [-44, -21], [39, 7], [-39, -15], [-55, -3], [-14, 31], [-7, -23], [6, -54], [-34, -9], [-27, 39], [23, 17], [-4, 32], [1, 4], [14, 20]];
    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_bj();".
// 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_bj(:prec:=2)
    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_bj();".
// 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_bj( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7605_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-2, -2, 1]>,<7,R![-3, 0, 1]>,<11,R![-2, 1]>],Snew);
    return Vf;
end function;