
// Make newform 1728.2.a.j in Magma, downloaded from the LMFDB on 23 April 2026.
// 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_j();".
// 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_j();".
// 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], [3], [0], [-4], [6], [6], [-2], [-9], [2], [10], [6], [6], [13], [12], [-8], [6], [12], [9], [0], [3], [-14], [-9], [-7], [12], [15], [18], [10], [3], [-9], [2], [-12], [-17], [3], [-4], [-24], [18], [11], [-15], [0], [-24], [13], [5], [3], [6], [24], [-12], [18], [14], [-6], [-18], [0], [8], [6], [14], [-3], [0], [-20], [-6], [10], [12], [-18], [-19], [-7], [30], [18], [-3], [-26], [-2], [18], [-21], [4], [36], [-36], [7], [16], [-28], [-9], [-12], [0], [-6], [-11], [-9], [12], [22], [-9], [7], [-15], [3], [-42], [-24], [-15], [6], [-6], [37], [32], [-36], [36], [36], [-41], [-3], [20], [24], [-34], [27], [14], [6], [19], [24], [-38], [-26], [0], [-27], [2], [-36], [24], [35], [21], [14], [-19], [2], [-12], [12], [13], [36], [36], [21], [18], [-12], [24], [27], [-18], [-8], [41], [-50], [0], [-37], [-50], [-18], [38], [27], [48], [-18], [36], [26], [52], [0], [12], [-50], [32], [-18], [0], [6], [30], [39], [20], [-29], [19], [45], [-4], [-51], [-21], [10], [-42], [-51], [-8], [-45], [-46], [9], [-22], [6], [18], [-45], [10], [54], [-5], [21], [44], [-21], [15], [54], [4], [48], [-61], [-18], [36], [-45], [-42], [-54], [9], [42], [-29], [36], [-28], [23], [-54], [-20], [-36], [-37], [-21], [-36], [45], [-15], [14], [36], [51], [38], [36], [-7], [-10], [-39], [-27], [0], [1], [-48], [-2], [18], [-46], [-18], [12], [8], [-12], [63], [8], [-16], [-42], [24], [-60], [-54], [0], [-72], [44], [6], [36], [-18], [-14], [-15], [-60], [-36], [-66], [69], [20], [44], [-24], [15], [-33], [-6], [48], [36], [-4], [-42], [9], [-7], [63], [0], [48], [13], [25], [45], [21], [18], [-52], [-44], [-36], [14], [-34], [-24], [-62], [-68], [-24], [-27], [33], [9], [3], [27], [-44], [-25], [12], [-12], [-9], [6], [-62], [-54], [42], [-45], [-17], [0], [-32], [74], [-69], [-44], [-27], [-10], [82], [27], [29], [39], [-30], [-14], [-41], [45], [51], [-30], [63], [-12], [-18], [48], [52], [24], [5], [34], [12], [48], [18], [-9], [-24], [18], [26], [36], [13], [-23], [-63], [-16], [63], [42], [-36], [84], [-85], [18], [26], [3], [-24], [60], [-9], [74], [-46], [9], [-15], [-82], [-56], [17], [-48], [61], [36], [18], [-30], [30], [-50], [-60], [27], [-46], [-69], [-22], [50], [-30], [-39], [-46], [-6], [8], [-20], [12], [57], [-18], [-82], [-2], [15], [-7], [3], [36], [90], [-83], [-45], [-36], [-48], [-6], [43], [-58], [-18], [-97], [10], [-72], [-52], [-48], [-6], [-60], [-72], [-18], [48], [9], [74], [36], [18], [12], [54], [-48], [34], [78], [-37], [40], [22], [48], [-8], [49], [15], [54], [-88], [84], [-27], [-73], [43], [39], [-84], [-63], [-59], [18], [-24], [-14], [18], [-2], [74], [-12], [87], [-83], [37], [87], [14], [-96], [72]];
    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_j();".
// 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_j(: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_j();".
// 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_j( : 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![-3, 1]>],Snew);
    return Vf;
end function;