
// Make newform 2268.2.a.i in Magma, downloaded from the LMFDB on 19 April 2024.
// 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_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_2268_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
        poly := [1, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-3, -1, 1]];
    Rf_basisdens := [1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_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)
    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+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 := [[0, 0, 0], [0, 0, 0], [0, 1, 0], [-1, 0, 0], [1, 1, 2], [1, 2, 2], [1, -2, -1], [0, 2, -1], [4, 1, -1], [1, -3, -1], [0, -3, 0], [-2, 1, -2], [-1, 1, -2], [0, -1, -4], [8, -2, 1], [2, 1, 1], [11, -1, 1], [4, -7, -1], [3, -2, 1], [3, 5, -3], [0, -2, 1], [-4, 4, 1], [7, -2, -1], [5, 1, 4], [-1, -1, 5], [4, 0, -1], [-4, 3, 3], [9, -6, 0], [4, -6, 3], [0, -2, 6], [3, -3, 6], [1, 3, -1], [-8, 3, -4], [2, 2, -1], [3, -3, 0], [1, 3, -3], [-4, 0, -3], [3, 2, -1], [-1, -4, -2], [6, 1, -6], [0, 0, -3], [-6, -3, -6], [8, -5, -2], [-5, 1, -5], [-5, 7, -1], [4, -5, 7], [-15, -4, -4], [9, -4, -4], [19, -1, -1], [11, -4, -4], [-2, 7, 8], [5, -2, 10], [-12, -1, -7], [-7, 4, 7], [-2, -4, -10], [-2, -10, -1], [11, 5, 1], [11, 1, -2], [11, 0, 3], [-23, -2, -1], [2, -1, 2], [-7, 13, 1], [-7, 2, -7], [11, 5, 10], [1, 9, 9], [9, -3, 0], [-1, -6, 3], [15, 3, 9], [-8, 8, -7], [-24, -2, -2], [0, -9, 3], [9, -8, -9], [6, -7, -4], [-12, -5, 4], [15, -17, -5], [6, -1, -6], [-20, -6, -1], [-6, -3, -6], [-19, 7, -2], [-6, -4, 2], [-10, -5, -5], [-2, -4, -7], [-17, 11, 5], [21, 2, -4], [-5, 5, -1], [12, 8, 6], [-21, 4, -3], [-4, -10, -1], [-13, -4, 7], [4, -15, -9], [-4, -7, 10], [14, 0, -5], [11, 3, -3], [-28, 1, -2], [16, -6, 0], [-11, 5, -4], [16, -1, 11], [-9, -6, -12], [-13, 3, -3], [13, 2, 8], [2, -5, 7], [1, 9, 11], [21, -19, -6], [-15, -6, -12], [11, 7, 7], [-6, 13, -5], [-3, 5, -6], [0, 12, -3], [-2, 2, 2], [23, -3, 0], [3, 0, -6], [-9, -6, 6], [-23, 1, -4], [0, 13, 13], [-15, -7, 2], [-34, 3, -5], [-13, 15, 3], [30, -6, 3], [17, -8, 7], [-14, -8, -13], [23, 5, 5], [-17, -5, -2], [21, 9, 3], [2, -20, -2], [11, 3, 0], [-16, -4, -2], [6, 2, -10], [5, 7, -11], [-10, 11, 8], [-23, 2, -10], [7, 5, -1], [-9, -12, -3], [-28, 4, -5], [3, 6, -15], [-2, -2, 14], [-14, -9, -3], [21, -8, 0], [12, 3, -12], [11, 4, 1], [-17, 18, -1], [22, 3, 15], [-6, -4, 9], [16, 0, 0], [-5, -19, 5], [-8, 0, 3], [-19, -6, -14], [-2, -2, -11], [20, 7, 7], [-25, -6, 0], [27, 10, 3], [27, -14, 1], [-26, 5, 2], [-18, 11, -4], [-4, 13, 7], [-9, -12, 12], [1, 17, 5], [31, -3, 6], [25, -25, -7], [-21, 14, 5], [12, 1, -12], [34, 9, 5], [-2, -8, 8], [-15, 2, 5], [-17, 8, -7], [5, -8, -8], [22, -7, 5], [-30, 8, -7], [-38, -8, 4], [-9, 8, -13], [28, -22, -7], [9, -23, 9], [13, -27, 0], [3, 6, 0], [33, 0, 0], [1, 20, 8], [11, -19, 4], [4, -19, 8], [0, -25, 0], [30, -13, -1], [20, -9, -12], [-26, -1, -7], [-4, 12, 13], [32, -10, 2], [18, 4, -9], [2, 5, -17], [44, 4, 7], [-22, -5, -2], [-13, 0, -3], [-15, 15, 6], [24, 0, -3], [19, 3, 21], [-6, 3, 12], [-17, 15, 9], [23, -3, -2], [18, -15, -6], [2, 15, 1], [-2, -2, -5], [-12, 22, 7], [27, 6, 15], [-17, -16, -10], [5, -8, 10], [-9, 24, -6], [-27, 5, -13], [29, -5, 10], [25, -1, -4], [23, -5, 16], [-2, 10, 10], [26, 7, 7], [16, 14, 2], [7, -23, -8], [-1, -3, -12], [28, -6, -13], [-14, 2, 8], [-29, 3, 2], [1, 8, 11], [-25, 21, 9], [38, -1, 11], [-18, -7, 12], [31, 10, 5], [31, -17, -7], [-23, 21, 15], [-2, 0, -12], [-24, -12, 0], [0, 19, 16], [14, -14, -2], [-13, -12, -3], [-1, 27, -8], [0, 1, -9], [-1, 1, 4], [-12, -9, 0], [4, 29, -16], [-2, 6, 6], [26, -10, -4], [-38, 2, 5], [-36, 8, -10], [22, -13, -10], [-12, -14, 4], [-12, 21, 3], [-36, -9, -6], [-40, 2, 1], [17, -9, -8], [-15, -13, 11], [-13, -3, -6], [-1, 7, 13], [-6, 11, 15], [-17, 8, 17], [31, -13, 11], [-5, -17, 2], [-28, -18, 3], [-21, 12, 12], [-5, 27, 12], [4, -16, -10], [4, -7, -7], [-17, 6, 9], [-10, 0, -23], [-27, 20, -3], [-16, 12, 9], [12, -6, -15], [18, 7, 12], [-9, -16, -4], [6, 7, 25], [-13, -4, -11], [-7, 11, 2], [-13, 14, 2], [4, -4, -4], [4, 0, -6], [58, -10, -7], [-12, 13, -12], [-37, -7, 2], [-30, -15, -3], [21, 18, -15], [-18, -22, -1], [-19, -8, -14], [3, -10, 5], [47, -1, 5], [-7, -8, -8], [-14, -5, 5], [34, -10, -13], [32, -16, -10], [-38, -1, 2], [-21, 30, 0], [7, 17, -4], [-30, 9, 9], [-29, 13, -5], [1, -10, -7], [10, -26, -1], [-4, -26, -17], [35, 15, 13], [7, 1, 13], [-5, -22, 11], [0, 15, -9], [-2, 20, -4], [-36, -12, -3], [-16, -16, 1], [10, 31, -5], [-28, -17, -8], [-19, -15, -3], [22, -10, 26], [-48, 9, -12], [-23, -10, -4], [23, -4, -4], [6, -3, -3], [-5, 33, 3], [14, 4, 7], [11, 6, 6], [23, 15, 15], [24, 7, 3], [1, 13, -5], [-11, 10, -10], [-7, 27, 6], [0, 27, 18], [-17, 6, -13], [-30, 19, 6], [-3, 20, 17], [-31, 8, -23], [9, 5, 11], [28, 14, 8], [0, -11, 0], [67, 4, 16], [26, -8, -8], [-2, 31, 1], [-18, 22, -17], [-25, 19, -5], [-21, -8, -26], [-34, -7, -5], [-7, 24, -21], [6, -1, -1], [3, -32, -11], [29, -9, 4], [-4, 27, 1], [-50, -8, -26], [51, 8, 6], [11, -14, 28], [-16, -30, 19], [6, -17, 10], [-2, 9, 5], [-38, 11, 14], [-4, 2, 1], [-15, -4, 11], [28, 18, -9], [5, -6, 12], [-6, -15, -12], [42, 15, -6], [37, -1, -7], [-16, 25, 16], [21, 0, -15], [-5, 1, -8], [54, 14, 2], [-25, 4, -8], [12, -30, -9], [-36, 26, -1], [12, 26, 26], [16, 23, 35], [-50, -1, -1], [26, 11, 35], [33, -1, 9], [-30, 19, -15], [-35, 35, 20], [-22, -6, -26], [12, -10, 3], [-20, -6, -24], [15, -7, 33], [48, -41, -12], [-68, 16, 5], [28, -18, -6], [26, -36, -6], [32, -5, 13], [-62, -1, -7], [-6, -29, 7], [-9, 8, -15], [3, -5, -11], [15, -3, -21], [40, 6, 14], [-48, -14, -11], [52, -21, -6], [-12, -21, 0], [25, -11, -4], [36, -14, 13], [8, 15, -8], [-26, 10, 10], [-61, 7, -11], [36, 1, 24], [16, 3, 33], [-9, -27, -9], [-55, 20, -4], [-36, -8, 0], [21, 5, 11], [-22, -22, -10], [1, 6, 15], [9, 11, 0], [23, 6, 30], [41, -5, -11], [9, 20, -15], [-17, -5, 19], [-4, 5, -26], [-45, 24, -6], [-24, -11, 10], [12, 26, -21], [-13, 25, -5], [-18, -10, -30], [-24, 23, 14], [-16, -35, 16], [17, -7, -25], [3, -23, -21], [22, -7, 14], [-9, 29, 11], [19, 27, 12], [32, -35, -17], [31, 4, 19], [23, 9, 7], [26, -28, -4], [19, -29, 14], [-5, 25, -1], [-2, 14, 29], [-15, -28, -1], [24, 14, 24], [8, -33, -8], [83, 2, -1], [43, -1, -4], [-15, 1, 9], [9, 23, 36], [-49, 3, 3], [4, -5, -7], [-4, -29, -20], [66, -25, -10], [18, -14, 24], [0, 22, -12], [51, 9, 0], [-39, 18, 15], [-44, 34, 8]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2268_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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