
// Make newform 3888.2.a.b in Magma, downloaded from the LMFDB on 04 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_3888_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_3888_2_a_b();".
// 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_3888_2_a_b();".
// 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_3888_a();"
function MakeCharacter_3888_a()
    N := 3888;
    order := 1;
    char_gens := [2431, 2917, 1217];
    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_3888_a_Hecke( : Kf := Kf)
    return MakeCharacter_3888_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]];
    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], [0], [-3], [-2], [0], [-4], [6], [7], [9], [-9], [-2], [-4], [6], [4], [3], [3], [0], [-10], [-5], [3], [-7], [-8], [-6], [-12], [-1], [3], [-14], [-12], [8], [12], [-8], [-6], [0], [-8], [-18], [10], [20], [-5], [-3], [-3], [6], [-4], [15], [-22], [6], [16], [4], [4], [30], [2], [-6], [15], [2], [-30], [-6], [-12], [-6], [-20], [-22], [-18], [-29], [-9], [7], [21], [29], [-6], [1], [-19], [-30], [20], [0], [27], [-26], [-4], [-5], [3], [-15], [-28], [6], [-1], [6], [-16], [21], [-19], [-26], [-24], [-36], [14], [18], [-14], [-30], [12], [-2], [0], [13], [-27], [15], [-12], [7], [-40], [-17], [6], [6], [30], [-17], [-25], [-30], [6], [9], [23], [-8], [2], [-48], [-8], [40], [-36], [31], [-45], [-18], [42], [14], [17], [-15], [18], [13], [-6], [-10], [0], [28], [20], [-44], [-39], [28], [-16], [-24], [5], [-45], [49], [21], [-30], [19], [39], [4], [-42], [-34], [-15], [-10], [-30], [19], [3], [-10], [12], [52], [48], [37], [21], [-38], [42], [14], [45], [-42], [-36], [4], [36], [36], [24], [-20], [-10], [11], [6], [-18], [50], [3], [-43], [4], [36], [-23], [45], [-2], [14], [52], [-48], [14], [18], [-24], [-42], [-52], [43], [-58], [57], [-43], [-24], [67], [-51], [12], [18], [59], [-46], [12], [-51], [-51], [-26], [-4], [26], [42], [-21], [-56], [48], [-6], [-17], [41], [-27], [-26], [42], [24], [17], [-38], [42], [24], [9], [-4], [-50], [24], [46], [42], [-28], [42], [-48], [34], [18], [-10], [55], [34], [42], [25], [-27], [-49], [45], [-48], [60], [6], [61], [4], [2], [-36], [-27], [-38], [66], [-47], [-36], [-58], [18], [-9], [-46], [-30], [-60], [-16], [-5], [-45], [-10], [-44], [-24], [-22], [68], [24], [-41], [-39], [6], [-20], [-15], [-10], [-41], [41], [40], [2], [16], [-60], [50], [35], [42], [48], [16], [0], [-28], [-32], [-72], [-61], [9], [-80], [54], [-3], [6], [54], [-66], [-64], [54], [46], [-6], [-18], [-8], [5], [81], [-26], [-24], [-80], [-1], [54], [14], [27], [38], [-27], [54], [-30], [31], [75], [-10], [-36], [81], [-67], [-78], [-35], [-22], [3], [-80], [-24], [59], [52], [64], [48], [57], [-10], [-63], [-56], [48], [-47], [24], [56], [6], [-70], [-20], [44], [18], [3], [-74], [3], [-66], [56], [31], [-21], [-33], [55], [-70], [-45], [-8], [50], [84], [-39], [66], [-72], [27], [44], [90], [72], [96], [-29], [83], [75], [-2], [-7], [-90], [76], [48], [-33], [-50], [2], [24], [-27], [-25], [6], [-73], [45], [-36], [-50], [-24], [4], [21], [-26], [62], [-83], [33], [-103], [-42], [30], [-65], [57], [14], [-50], [60], [97], [42], [-16], [24], [-74], [-42], [18], [100], [44], [90], [-23], [60], [50], [45], [-48], [-44], [-19], [-21], [-57], [82], [-96], [-96], [81], [-46], [-39], [-30], [26], [-18], [36], [-72], [25], [51]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3888_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3888_2_a_b();".
// 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_3888_2_a_b(:prec:=1)
    chi := MakeCharacter_3888_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_3888_2_a_b();".
// 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_3888_2_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3888_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![3, 1]>,<7,R![2, 1]>,<11,R![0, 1]>,<13,R![4, 1]>],Snew);
    return Vf;
end function;