
// Make newform 1728.2.a.i in Magma, downloaded from the LMFDB on 02 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1728_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_1728_2_a_i();".
// 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_1728_2_a_i();".
// 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_1728_a();"
function MakeCharacter_1728_a()
    N := 1728;
    order := 1;
    char_gens := [703, 325, 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_1728_a_Hecke( : Kf := Kf)
    return MakeCharacter_1728_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], [-1], [-3], [-5], [-4], [8], [2], [2], [6], [7], [6], [6], [-2], [6], [5], [4], [8], [-10], [-8], [1], [-16], [11], [-6], [-1], [9], [-4], [-9], [-10], [6], [11], [-1], [18], [12], [7], [-5], [20], [12], [-6], [-21], [9], [0], [12], [-19], [-3], [11], [10], [-16], [12], [2], [22], [22], [6], [-16], [-4], [26], [-2], [13], [8], [-16], [14], [-6], [24], [-30], [21], [9], [14], [-6], [-27], [-30], [-22], [-30], [11], [-8], [20], [0], [-1], [4], [-12], [-9], [36], [-8], [34], [13], [-9], [-4], [-14], [-1], [-1], [1], [3], [-26], [8], [9], [6], [6], [21], [-28], [-8], [-36], [32], [-1], [-11], [28], [-12], [-10], [19], [22], [6], [-5], [40], [-14], [-6], [28], [-43], [22], [12], [16], [3], [21], [-38], [13], [-22], [-44], [-4], [-3], [4], [20], [-3], [46], [-40], [20], [-45], [46], [32], [-7], [30], [-32], [35], [38], [-14], [54], [43], [32], [-34], [0], [10], [24], [-24], [-52], [-42], [-52], [-46], [4], [58], [38], [47], [-4], [-21], [-45], [-3], [36], [-35], [51], [18], [6], [-19], [-28], [59], [26], [33], [42], [46], [10], [-5], [38], [-22], [-45], [-43], [-8], [19], [-25], [-6], [12], [-12], [3], [2], [0], [-29], [-30], [-14], [9], [-38], [-61], [-60], [-28], [-65], [2], [44], [36], [-53], [43], [-56], [-59], [-63], [30], [4], [-45], [38], [-32], [33], [-42], [65], [5], [40], [41], [40], [-50], [18], [-6], [58], [-36], [-24], [4], [63], [40], [-24], [18], [48], [28], [-30], [-8], [-32], [-44], [-66], [-20], [14], [2], [-31], [68], [-60], [38], [-19], [-40], [0], [28], [-73], [39], [46], [-20], [12], [-48], [-2], [1], [9], [15], [-20], [40], [69], [-47], [-43], [-27], [-22], [-24], [4], [-28], [-50], [-70], [-28], [-38], [-40], [-16], [-11], [65], [1], [19], [-21], [-32], [-41], [-20], [-28], [23], [74], [46], [2], [-46], [59], [63], [-56], [32], [-70], [-45], [28], [21], [66], [-46], [67], [69], [-9], [-46], [26], [7], [37], [19], [-30], [-73], [-12], [-62], [-8], [40], [36], [45], [14], [52], [56], [74], [-57], [-12], [50], [42], [4], [-11], [49], [17], [40], [15], [18], [24], [8], [27], [86], [-54], [-45], [-24], [72], [-33], [-58], [-66], [-31], [-63], [14], [48], [9], [0], [77], [52], [-18], [-50], [-78], [22], [-48], [11], [2], [-21], [-14], [14], [-10], [-79], [94], [-54], [-80], [0], [-12], [-55], [-38], [-66], [30], [-1], [-23], [83], [84], [-74], [-43], [11], [52], [48], [-18], [43], [30], [-82], [-57], [-22], [96], [-24], [100], [-66], [-60], [76], [-86], [-60], [49], [98], [-60], [-78], [-60], [-2], [-24], [30], [-70], [59], [76], [-6], [-16], [-40], [-79], [-25], [38], [-12], [92], [45], [71], [83], [23], [-20], [-15], [-19], [66], [-32], [-42], [58], [94], [-26], [28], [-1], [13], [-35], [31], [42], [72], [-52]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1728_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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