
// Make newform 7605.2.a.y in Magma, downloaded from the LMFDB on 20 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_y();".
// 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_y();".
// 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], [-1, -2], [0, -2], [0, 0], [5, 1], [2, 2], [4, -2], [1, 1], [-2, 3], [-4, 0], [-7, 1], [-2, 1], [5, -3], [0, 4], [-9, 1], [1, 2], [-9, -2], [-11, -1], [5, 6], [-5, 4], [-6, 2], [-3, 1], [13, 2], [-2, 4], [2, -3], [-5, -7], [10, -1], [-16, -2], [6, 5], [-3, 1], [-3, 7], [-11, -4], [-4, 0], [4, 8], [8, 1], [9, -2], [-14, -2], [-5, 1], [3, -7], [-18, 2], [5, 13], [-13, 4], [-4, 4], [-15, 0], [15, -2], [2, -8], [3, 5], [-8, -6], [-10, -8], [-2, -2], [12, -6], [0, 0], [-9, -1], [15, -5], [-7, -5], [2, 1], [-4, 14], [-9, -7], [-2, 1], [-9, -9], [19, -4], [-5, -3], [-16, 3], [14, 2], [4, -7], [12, 11], [-10, 2], [-4, -15], [30, 4], [25, 5], [-6, -7], [-14, 7], [-18, -1], [17, -5], [-14, -2], [7, 10], [2, -10], [6, -5], [9, -17], [8, 9], [6, 10], [10, -3], [5, 6], [9, -7], [-18, 4], [5, -6], [-11, 13], [19, -12], [15, 5], [-3, -19], [0, -12], [5, -7], [-10, 6], [10, 12], [-6, -4], [11, 1], [-34, -2], [2, 9], [-16, -5], [-18, -2], [0, 2], [39, 3], [10, -8], [16, -16], [17, 5], [-4, -10], [11, 7], [2, -14], [28, -6], [-23, 12], [10, -20], [4, -9], [-26, 9], [-18, -12], [-17, 12], [-2, 0], [23, -13], [6, 18], [-2, -11], [-10, -5], [-12, -12], [-43, 1], [-28, -9], [-12, 12], [-22, -5], [-33, -1], [-8, 1], [15, -10], [0, -6], [-7, -19], [-4, -10], [20, 4], [-8, 8], [40, 6], [-6, 8], [-25, 2], [1, 17], [-36, 0], [-20, 11], [-6, 4], [18, -18], [-13, 9], [-7, -18], [24, -2], [-27, 6], [5, 7], [-13, 12], [-24, -6], [-16, 20], [-6, 18], [8, -5], [-23, 15], [-28, 2], [-20, 16], [-26, 4], [2, -10], [8, 14], [25, -9], [-21, 9], [0, -14], [-8, 14], [-30, -18], [8, 4], [-10, 8], [22, -4], [-42, 9], [-16, -13], [21, 11], [-1, -17], [-8, -6], [14, 4], [-5, 12], [6, -12], [-33, 3], [4, 19], [0, 2], [0, -23], [7, -22], [-6, -12], [-9, -17], [-10, 27], [-45, -1], [23, -5], [-30, -8], [40, -9], [6, -16], [52, 3], [9, 17], [26, 15], [3, -23], [7, 10], [-35, 7], [61, 3], [-24, 8], [-4, 29], [-2, -27], [-25, -25], [-1, -7], [-25, -5], [13, -2], [35, 6], [-59, -6], [10, -4], [45, -7], [8, 15], [-18, 6], [0, -20], [48, 4], [-6, 1], [-26, 18], [26, -3], [-3, -23], [-4, -28], [2, -20], [-22, -11], [4, 6], [-7, -7], [-1, -15], [31, 8], [38, 3], [-2, -10], [-15, 22], [-10, -30], [-21, 10], [-6, -16], [58, -2], [44, 3], [11, 31], [-2, -31], [39, 2], [40, -10], [-25, 7], [46, 5], [54, 12], [10, -1], [19, -1], [17, 7], [0, 22], [14, -18], [-24, 18], [-2, 22], [-42, 9], [-28, 18], [-4, -36], [1, -6], [-34, 0], [-8, -15], [14, -34], [-15, 8], [-17, -3], [-27, -11], [9, -34], [33, -9], [-1, 5], [14, 18], [-20, 12], [-21, 7], [66, 0], [-2, -10], [1, 29], [10, -19], [-44, 3], [-9, 5], [-27, -20], [39, -15], [-61, 9], [-54, 0], [36, 20], [19, -12], [-25, -10], [18, 10], [-24, 10], [-2, 13], [14, 16], [34, 0], [32, -24], [40, -1], [-60, 4], [-21, -11], [0, -22], [60, -2], [22, -3], [-30, -4], [-30, 16], [-12, -19], [57, 13], [4, -15], [-1, -21], [-83, -1], [37, 15], [-46, 22], [12, -2], [-10, 29], [25, 19], [-4, -44], [48, -14], [12, 2], [1, -28], [-14, 1], [-33, 19], [-28, 20], [21, -1], [-7, -28], [-11, -18], [-42, -16], [-50, 12], [69, -5], [14, -4], [-31, 9], [-42, 24], [-31, 27], [28, 7], [51, 7], [29, -14], [-15, 9], [6, 8], [35, 18], [15, 7], [-35, -24], [27, 16], [21, -33], [-37, 30], [18, 36], [-65, -2], [-62, 11], [-4, 18], [-27, 27], [69, -1], [-30, 24], [3, -3], [-57, -8], [-25, -15], [-4, -3], [18, 12], [50, -5], [-4, 14], [28, -8], [-6, -5], [22, 12], [2, -22], [7, 1], [23, 30], [-27, -7], [-58, -8], [41, 16], [-4, 14], [35, 5], [6, -50], [-68, -7], [38, 10], [20, -36], [20, 37], [44, -12], [-32, 8], [15, -17], [7, -13], [30, 18], [-44, 0], [26, -6], [18, -26], [-4, -26], [3, 33], [-38, 17], [4, 15], [51, 21], [-1, 56], [0, 0], [-39, 27], [-59, -10], [36, 10], [84, 8], [-2, 16], [-52, 4], [25, -23], [42, -14], [-3, 34], [-7, -47], [2, -49], [-20, 0], [21, 29], [-76, 2], [-33, 35], [34, 7], [-45, -7], [-28, -32], [-10, 17], [-19, 12], [0, -6], [-2, -24], [-51, -11], [-28, -20], [-72, 14], [-41, -29], [10, -23], [-36, -28], [-37, -1], [-34, 20], [-15, -47], [36, 19], [57, -1], [37, -22], [43, -25], [15, -5], [-33, 12], [-35, -30], [-51, 29], [-1, -12], [44, -4], [52, -15], [5, 5], [13, -13], [60, 20], [28, 25], [3, -19], [42, 2], [-22, -3], [21, -5], [-57, -25], [15, -9], [29, 8], [33, 15], [-40, 20], [81, -4], [21, 1], [5, -13], [-34, 14], [4, -35], [-18, -4]];
    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_y();".
// 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_y(: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_y();".
// 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_y( : 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![-11, 2, 1]>,<11,R![-12, 0, 1]>],Snew);
    return Vf;
end function;