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