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