
// Make newform 2268.2.a.d in Magma, downloaded from the LMFDB on 18 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_2268_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_2268_2_a_d();".
// 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_2268_2_a_d();".
// 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_2268_a();"
function MakeCharacter_2268_a()
    N := 2268;
    order := 1;
    char_gens := [1135, 1541, 325];
    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_2268_a_Hecke( : Kf := Kf)
    return MakeCharacter_2268_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], [2], [-1], [1], [0], [-2], [2], [4], [2], [6], [5], [6], [5], [0], [-9], [2], [0], [7], [-11], [4], [15], [10], [-12], [10], [-16], [14], [3], [-2], [11], [-3], [-4], [5], [-2], [15], [1], [20], [11], [2], [-16], [-12], [-6], [9], [-10], [-5], [20], [-1], [-10], [-18], [10], [10], [-15], [-4], [0], [12], [21], [32], [0], [-25], [25], [16], [0], [10], [-16], [10], [-30], [-4], [-15], [-27], [-8], [-30], [23], [32], [19], [-29], [-20], [-10], [-12], [-15], [-10], [-30], [-21], [-24], [-34], [-12], [-20], [-13], [-5], [-4], [-29], [38], [-38], [-25], [-36], [28], [0], [6], [30], [20], [-9], [-15], [35], [10], [-27], [-36], [28], [10], [-6], [-3], [-46], [0], [-15], [10], [40], [-4], [49], [20], [42], [-15], [19], [4], [-31], [-42], [-15], [-10], [-19], [-19], [42], [-20], [-6], [33], [-39], [45], [30], [16], [-2], [50], [18], [0], [-37], [-56], [-29], [16], [-15], [28], [-2], [44], [-30], [8], [-31], [25], [-54], [-31], [0], [33], [24], [13], [12], [8], [20], [-28], [-50], [8], [-6], [-30], [-24], [-19], [38], [23], [36], [8], [4], [24], [-39], [30], [8], [0], [-11], [20], [62], [45], [58], [1], [-28], [35], [-48], [27], [26], [33], [-60], [16], [-15], [28], [34], [-60], [4], [-19], [25], [12], [30], [18], [6], [68], [-42], [6], [30], [2], [45], [15], [20], [17], [14], [0], [-70], [12], [-16], [37], [46], [37], [1], [-59], [-68], [18], [-5], [48], [62], [34], [-16], [-60], [27], [6], [-2], [-20], [-57], [-10], [-42], [52], [66], [-15], [-4], [-44], [-70], [-10], [15], [-20], [-18], [-30], [10], [-7], [0], [-5], [-54], [60], [58], [-20], [-20], [-19], [12], [38], [8], [25], [-55], [22], [10], [-60], [-8], [15], [56], [-20], [-51], [6], [65], [-30], [-37], [-32], [-60], [7], [3], [-65], [12], [30], [-15], [-72], [-10], [-72], [-41], [-30], [-5], [-52], [30], [-21], [-30], [-51], [-64], [11], [-18], [26], [24], [78], [72], [34], [78], [-83], [51], [-64], [-7], [-13], [68], [-8], [50], [24], [77], [74], [5], [83], [-52], [-12], [41], [-40], [-18], [-82], [22], [24], [64], [-10], [14], [-43], [-56], [25], [46], [-61], [-35], [12], [64], [31], [80], [78], [-4], [14], [-50], [-10], [-27], [42], [-75], [-39], [60], [-4], [20], [-36], [0], [-64], [35], [-18], [24], [-38], [-14], [-52], [-36], [-17], [-5], [70], [64], [23], [-68], [-20], [-70], [-60], [0], [-26], [19], [-20], [24], [-73], [-74], [-38], [48], [-29], [-50], [-38], [-52], [72], [-61], [55], [-33], [82], [-64], [47], [-8], [-44], [22], [65], [30], [55], [50], [71], [-75], [52], [-20], [-15], [-11], [62], [15], [97], [92], [-72], [-70], [82], [-30], [-40], [22], [34], [22], [31], [-84], [5], [-62], [-32], [28], [48], [-34], [-35], [80], [-65], [-42], [50], [-40], [20], [-51], [-84], [70]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2268_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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