
// Make newform 7623.2.a.bk in Magma, downloaded from the LMFDB on 25 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_bk();".
// 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_bk();".
// 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, -2], [0, 0], [-1, 1], [1, 0], [0, 0], [0, 2], [0, -3], [-2, 3], [-6, 1], [6, 0], [5, -5], [3, 1], [-9, 1], [0, 6], [2, -4], [-10, 2], [0, -2], [0, 0], [0, 0], [-8, 8], [4, 6], [-10, 0], [-10, -4], [-4, -1], [-6, 0], [-11, 11], [-10, 7], [2, -11], [-3, -9], [2, 2], [10, -6], [-6, 14], [8, -10], [18, -3], [-8, 8], [-22, 4], [6, -18], [-10, 0], [18, 2], [12, 1], [-3, 11], [6, -16], [-13, 5], [-17, -3], [-16, -4], [18, -3], [14, -20], [18, 1], [-6, -4], [0, 10], [6, 6], [-2, 13], [12, 0], [-18, -6], [16, -25], [-6, -3], [-6, 12], [5, -17], [8, -5], [14, 8], [7, -15], [-19, 23], [-3, -9], [2, -14], [-24, 10], [-10, 2], [-2, 12], [19, 5], [-13, 17], [-12, -6], [18, 0], [-21, 9], [27, -15], [5, 7], [28, -4], [-18, 24], [-12, -2], [-18, 30], [12, -12], [-6, -10], [0, 2], [-8, 11], [-7, -5], [-28, -2], [-3, 3], [-22, 1], [16, 16], [2, 12], [6, 0], [-4, -12], [-10, -10], [-12, 8], [18, 6], [26, -17], [-8, 18], [8, 4], [19, 5], [1, 7], [18, -3], [-5, -7], [-30, -4], [10, -20], [16, -4], [24, -22], [38, -14], [-26, -6], [-18, 12], [5, -17], [22, 1], [10, -4], [22, -21], [12, -21], [-28, 26], [7, -27], [0, -28], [-16, 2], [-14, 15], [-30, -4], [16, -20], [21, 3], [16, -30], [-6, -24], [-2, -20], [-9, -11], [18, 19], [-4, -22], [13, -13], [16, -34], [-14, -3], [24, -26], [12, 18], [5, 7], [24, 0], [-4, 9], [18, -12], [14, -8], [-2, -4], [-21, -3], [-27, -9], [-4, -2], [28, -12], [-2, 8], [-34, 24], [30, -37], [28, -36], [-18, 36], [-32, -6], [2, 20], [12, 0], [1, 7], [6, 4], [0, -7], [-16, 22], [8, -22], [26, -6], [-12, 8], [-24, -4], [-48, 15], [-8, 26], [28, -17], [-9, -3], [14, -16], [-36, 20], [-6, -30], [46, -20], [-2, 8], [-30, -2], [30, -46], [18, 4], [-12, 9], [13, 11], [24, 12], [-25, 5], [8, 15], [-24, 12], [-3, -1], [-32, -4], [-26, 28], [48, -20], [24, 12], [-12, -22], [-2, 10], [-52, 9], [21, -21], [-46, -1], [-28, 13], [-16, -5], [-17, 17], [-13, -15], [-12, -12], [-42, -6], [-21, 45], [-30, -6], [-15, -21], [-6, -9], [-10, -28], [21, -33], [9, -45], [14, 16], [0, -20], [12, -40], [30, 1], [-8, -6], [-12, 34], [-30, 12], [17, -25], [8, 36], [4, -16], [8, 14], [18, -9], [28, -15], [4, 35], [-12, 42], [54, -20], [6, 4], [-52, 30], [4, 14], [10, 28], [10, 19], [-12, -6], [-12, -7], [-31, 15], [28, -8], [-12, -18], [-56, -2], [-56, -1], [-41, 49], [-15, 19], [26, 9], [-16, 8], [0, 41], [-36, 48], [-60, 22], [64, 4], [-33, 49], [6, -12], [2, -12], [-14, 16], [31, -23], [-18, 40], [40, -40], [-17, 33], [-33, -7], [4, -39], [-33, 13], [-2, -8], [39, -15], [30, -12], [22, 2], [32, -28], [3, 33], [-15, 51], [4, -32], [-18, 6], [1, 7], [30, -27], [-11, 39], [-52, 16], [10, 20], [18, -16], [-8, 24], [-55, 11], [44, 10], [-12, -18], [4, 13], [-54, 31], [44, -34], [6, 0], [-20, -16], [12, 18], [-30, 4], [-32, 48], [12, -8], [-54, 18], [-16, 42], [54, -37], [-51, -9], [-60, 17], [-24, 43], [0, 22], [-52, 28], [-12, 20], [-2, 8], [-32, 12], [-31, 15], [46, 1], [-27, -21], [-14, 4], [-34, 15], [31, -31], [-34, 56], [16, 40], [-46, 38], [30, 30], [12, -51], [17, -1], [30, 33], [4, -17], [-44, -4], [2, 39], [14, 22], [34, -22], [-16, 48], [53, -17], [-12, 30], [-60, 15], [12, -24], [32, -12], [42, -61], [-15, 3], [-8, 52], [-12, -24], [-48, 30], [12, -30], [-33, 9], [-38, 44], [6, 18], [84, 4], [22, 0], [-50, 2], [57, -29], [-56, -3], [-72, 5], [-18, 42], [2, 2], [-18, 6], [48, -42], [2, -47], [35, -7], [28, 20], [42, -20], [16, -16], [-18, 27], [66, 0], [32, -18], [6, -18], [12, 15], [-60, 3], [-34, -6], [-21, -7], [-59, 11], [22, 22], [-48, 3], [32, 12], [-32, -34], [39, -51], [12, -44], [-30, 36], [6, 44], [-60, 17], [-7, 31], [-48, 41], [-36, 18], [63, -3], [-40, 21], [-40, -19], [54, 14], [80, -20], [42, 18], [36, -36], [12, -23], [-24, 11], [10, -49], [-30, 9], [38, -21], [-51, 39], [34, 8], [6, -54], [0, 7], [30, -33], [54, -7], [46, -35], [34, -32], [10, 23], [-6, 24], [-18, 34], [-2, 47], [-62, 6], [-67, 23], [-60, 60], [-16, 17], [-58, 70], [38, -6], [4, -20], [39, 5], [-18, -2], [34, -76], [-8, -48], [68, -18], [50, 8], [-68, 11], [-12, -45], [-34, 41], [-50, 23], [-15, -21], [-60, -13], [47, -75], [33, -9], [-20, 66], [36, 0], [-28, 0], [-42, 10], [12, -24], [-45, 53], [48, 7], [39, -83], [34, 20], [-30, -4], [37, 3], [8, 8], [-22, 42], [44, 32], [-2, 37], [12, 8], [48, -5], [8, -25], [-39, 15], [-47, 15], [-30, -20], [8, 8], [10, 2], [-26, 0], [-39, -21], [-54, 48], [36, -56], [24, -51], [-6, 27], [-32, 4], [57, -5], [-46, 52]];
    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_bk();".
// 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_bk(: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_bk();".
// 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_bk( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7623_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-5, 0, 1]>,<5,R![-1, 1, 1]>,<13,R![-4, -2, 1]>],Snew);
    return Vf;
end function;