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