
// Make newform 7623.2.a.s 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_s();".
// 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_s();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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 := [[2], [0], [3], [1], [0], [-2], [3], [4], [-2], [8], [2], [10], [2], [-9], [-9], [8], [3], [10], [13], [-14], [10], [4], [1], [9], [-16], [17], [14], [-10], [-13], [-6], [-13], [13], [-8], [2], [-12], [5], [-8], [4], [-3], [25], [-20], [-16], [20], [23], [22], [-14], [-7], [-24], [7], [-4], [-4], [-6], [-28], [-12], [-7], [-18], [14], [-20], [17], [12], [-4], [9], [-12], [25], [-24], [6], [3], [-2], [16], [-6], [-30], [-18], [-8], [-21], [-5], [-19], [-4], [-18], [0], [-28], [-19], [33], [-4], [4], [-26], [38], [-6], [-3], [-15], [16], [4], [29], [37], [42], [-5], [11], [15], [-1], [8], [33], [20], [-6], [21], [-40], [-4], [22], [-39], [11], [-34], [6], [22], [29], [-18], [-18], [-25], [24], [12], [-3], [-24], [24], [-40], [1], [9], [34], [4], [20], [-9], [-36], [16], [26], [-36], [6], [-37], [-9], [45], [-24], [-15], [-38], [-11], [6], [-52], [-46], [-20], [38], [38], [-51], [32], [-31], [18], [26], [18], [-2], [-21], [-55], [12], [6], [-40], [-3], [16], [-14], [30], [22], [-1], [-37], [14], [8], [-52], [-14], [-30], [14], [36], [-2], [48], [-18], [-16], [51], [9], [-40], [30], [8], [53], [-32], [-65], [-42], [54], [46], [-55], [-62], [-5], [-25], [-30], [14], [63], [54], [6], [7], [26], [-65], [-2], [-48], [0], [28], [-2], [-18], [1], [-58], [28], [-24], [20], [-22], [-7], [-22], [-56], [59], [-31], [-62], [67], [-1], [-44], [38], [-53], [2], [-18], [-5], [3], [54], [-6], [-16], [6], [-10], [51], [-68], [-17], [-36], [-12], [-43], [16], [18], [-12], [-21], [36], [-2], [-66], [50], [-30], [-27], [-38], [0], [-11], [-32], [37], [-21], [50], [62], [54], [30], [-69], [-44], [-23], [52], [23], [28], [64], [38], [38], [0], [-24], [15], [57], [-44], [22], [-24], [24], [3], [-52], [38], [-22], [-41], [-2], [-5], [24], [-51], [-60], [-72], [-22], [52], [45], [-14], [64], [33], [12], [-28], [46], [51], [59], [65], [38], [51], [4], [-56], [-44], [-60], [43], [28], [-68], [67], [-38], [-12], [-36], [-13], [63], [-30], [-38], [36], [8], [76], [60], [-6], [-26], [-2], [10], [81], [6], [19], [0], [60], [-19], [-8], [-18], [14], [14], [14], [8], [-44], [-68], [63], [6], [29], [-70], [-76], [79], [34], [-21], [79], [52], [-2], [24], [-57], [28], [-83], [56], [37], [94], [66], [82], [-45], [-9], [-27], [-60], [-58], [82], [18], [-10], [-26], [2], [-47], [46], [-83], [22], [72], [70], [28], [-60], [46], [25], [-5], [-10], [40], [-69], [-18], [-30], [-6], [-7], [6], [-22], [25], [7], [-38], [43], [72], [-2], [95], [46], [28], [62], [58], [-30], [63], [-32], [50], [98], [-12], [88], [13], [66], [-48], [53], [62], [-6], [-12], [52], [88], [8], [75], [-29], [-13], [-50], [28], [71], [72], [38], [22], [36], [36], [-92], [-15], [98], [-72], [32], [-91]];
    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_s();".
// 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_s(:prec:=1)
    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_s();".
// 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_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7623_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-2, 1]>,<5,R![-3, 1]>,<13,R![2, 1]>],Snew);
    return Vf;
end function;