
// Make newform 7623.2.a.by in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7623_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_7623_2_a_by();".
// 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_7623_2_a_by();".
// 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, -1, 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_7623_a();"
function MakeCharacter_7623_a()
    N := 7623;
    order := 1;
    char_gens := [848, 4357, 4600];
    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_7623_a_Hecke(Kf)
    return MakeCharacter_7623_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], [0, -1], [-1, 0], [0, 0], [1, -4], [-3, 0], [-4, 0], [4, 2], [3, 0], [-3, 2], [-2, -4], [5, -5], [9, 0], [-2, -5], [4, -5], [-11, -1], [-3, 6], [6, -6], [-9, -2], [-1, 3], [-2, -3], [-10, 8], [-14, 7], [3, -12], [0, 2], [9, 2], [-3, -8], [-15, 9], [-5, 4], [8, -9], [10, -7], [4, 4], [3, 9], [-9, -7], [9, 1], [-21, 3], [17, -3], [7, 5], [11, 1], [-19, 4], [11, -2], [-23, 4], [2, 12], [14, -10], [3, -9], [9, -14], [1, -10], [1, -1], [-14, 26], [-15, 12], [-2, 1], [-9, 6], [-9, 12], [-6, 4], [-15, 0], [-9, 18], [-9, 16], [6, 4], [-16, 17], [11, 6], [-22, 14], [-3, 6], [-3, -13], [10, -7], [-11, -2], [-17, 30], [-3, 2], [2, -16], [12, -9], [-15, -6], [-18, 21], [-15, -6], [18, 10], [6, -11], [-18, 15], [-14, 26], [-6, 15], [21, -15], [-8, -1], [2, 7], [3, 1], [18, 1], [6, 8], [9, -24], [-30, 14], [-7, -4], [16, -3], [-15, 12], [-13, 27], [-5, -14], [16, -7], [3, -15], [-18, -14], [-5, 0], [27, -2], [-21, 10], [-7, 20], [-27, 12], [24, -25], [13, -22], [-8, 10], [27, -28], [-5, -4], [-3, 16], [-20, -3], [-6, 0], [6, -20], [-34, 11], [12, -16], [-31, -3], [18, -21], [4, -11], [22, 6], [-1, -14], [28, -17], [-32, 0], [17, -8], [-25, -4], [21, -18], [1, -12], [-9, 12], [31, -5], [-23, 14], [16, -7], [5, -10], [-12, 10], [15, -5], [-17, 33], [17, -26], [-3, 9], [12, -5], [12, 9], [14, -18], [6, -27], [-30, 4], [-6, -8], [-24, 27], [-42, -3], [-15, 19], [26, 6], [-30, 26], [8, 24], [-23, 38], [22, -9], [15, 0], [-31, 15], [11, 8], [21, 12], [-1, 2], [-31, 25], [41, -26], [36, -25], [47, -10], [41, -27], [14, -23], [28, -4], [-36, 0], [27, -4], [-38, 34], [3, -9], [41, -1], [10, 14], [21, 12], [-19, -22], [15, -38], [25, 11], [-50, 8], [8, -11], [-9, 18], [9, 26], [-6, 39], [-10, 20], [43, 12], [-36, -3], [5, 25], [-18, -25], [-13, -13], [-13, -20], [-39, -3], [32, 4], [-5, -5], [-25, 6], [42, 0], [40, -23], [30, 2], [-3, 10], [54, -20], [43, -24], [9, -42], [0, -12], [-3, -33], [24, -24], [3, 27], [-51, 18], [25, -5], [3, 6], [24, -51], [-12, -23], [-7, -11], [31, -19], [5, 22], [-8, 42], [26, -56], [-39, 27], [-32, 16], [-4, 15], [12, -4], [-7, -25], [-15, 6], [8, -18], [36, -32], [39, -27], [31, -46], [-49, 10], [11, -27], [-39, 2], [-8, -14], [-49, 2], [21, -24], [16, -16], [-53, -6], [-7, 11], [24, -27], [40, 7], [9, -1], [-16, -7], [7, -7], [31, -39], [2, -10], [-7, -23], [36, 15], [8, 19], [16, -14], [10, -22], [-48, 21], [29, -36], [40, 1], [-34, 44], [16, -28], [-15, -17], [-34, 21], [-22, -11], [22, 9], [-49, -8], [16, -11], [0, 9], [-63, 12], [0, -22], [-10, 8], [30, 15], [9, -48], [8, 8], [9, 30], [-53, 4], [15, -18], [25, 24], [-27, -20], [-30, 16], [-20, 29], [-40, 9], [26, -4], [-33, -8], [-54, -9], [32, -13], [52, -1], [-8, -2], [-42, 36], [39, -1], [-9, -36], [7, 17], [1, 12], [-35, -16], [-30, 24], [-38, 36], [-40, 7], [39, -42], [-14, -22], [-25, 13], [8, 34], [-21, 1], [-43, 10], [-57, 38], [-22, 42], [-17, 9], [17, -19], [12, 0], [7, 16], [-40, -9], [21, 29], [-35, 10], [38, -22], [5, -49], [-27, 63], [9, 30], [-10, 11], [6, -18], [17, -4], [-18, -1], [-17, 60], [36, -32], [48, -37], [55, -15], [-54, 2], [-66, -3], [-63, 30], [6, 33], [-34, 33], [-16, -8], [15, 30], [19, -2], [-6, 30], [-27, 48], [9, 24], [-3, 42], [33, -37], [-15, 30], [35, -5], [-65, 9], [57, 11], [29, -53], [-71, 30], [-38, 59], [-6, 21], [-34, -4], [-6, 33], [45, -30], [36, -55], [35, -64], [54, 8], [17, -8], [0, -56], [0, -12], [-69, -12], [4, -36], [3, 24], [69, -12], [-84, 0], [26, -45], [-8, -28], [-63, 4], [-10, 11], [-45, 66], [-49, -6], [-3, -11], [24, -66], [31, -49], [-33, 30], [-11, 2], [38, -77], [-21, 52], [17, -47], [36, 21], [-24, -30], [-44, 75], [14, 41], [47, 4], [-15, 19], [9, -39], [-45, 30], [-7, -8], [46, -19], [15, 34], [42, -24], [-19, 48], [-24, 48], [75, -22], [27, -15], [-7, -50], [-6, -48], [5, -29], [40, -47], [-53, 10], [-18, 35], [-42, 18], [13, -16], [-18, 20], [-13, 42], [-7, 59], [15, -12], [-29, 4], [15, -37], [-53, 24], [-77, 13], [-20, -25], [7, -61], [60, -8], [49, 18], [73, -9], [28, -44], [12, -32], [63, 15], [43, -56], [-18, 25], [3, 6], [82, -1], [-8, 24], [-3, 0], [10, 36], [-69, 12], [79, -18], [-62, 20], [6, 24], [2, 22], [29, -5], [-64, 25], [6, -23], [28, -58], [7, -69], [-26, 43], [28, 12], [2, -25], [35, 20], [-59, 20], [17, -26], [-17, -38], [9, -21], [25, -78], [28, -7], [50, -73], [39, -62], [-37, -27], [-21, 36], [42, -51], [34, 20], [-87, 9], [-39, 24], [52, -47], [61, 17], [-69, 64]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7623_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7623_2_a_by();".
// 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_7623_2_a_by(:prec:=2)
    chi := MakeCharacter_7623_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_7623_2_a_by();".
// 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_7623_2_a_by( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7623_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![1, -3, 1]>,<5,R![-1, 1, 1]>,<13,R![-19, 2, 1]>],Snew);
    return Vf;
end function;