
// Make newform 1110.2.x.b in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1110_x();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1110_x_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_1110_2_x_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_1110_2_x_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
        poly := [1, 0, -1, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_1110_x();"
function MakeCharacter_1110_x()
    N := 1110;
    order := 6;
    char_gens := [371, 667, 631];
    v := [6, 6, 5];
    // 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1110_x_Hecke();"
function MakeCharacter_1110_x_Hecke(Kf)
    N := 1110;
    order := 6;
    char_gens := [371, 667, 631];
    char_values := [[1, 0, 0, 0], [1, 0, 0, 0], [0, 0, 1, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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, 1, 0, 0], [0, 0, 1, 0], [0, 1, 0, -1], [0, -1, 1, -1], [2, -2, 0, 1], [2, 0, -1, 0], [3, 2, 3, 0], [0, 2, 0, -2], [0, 0, 0, 2], [1, 0, -2, 6], [-4, 0, 8, 0], [-4, 0, 7, 0], [0, -3, -3, -3], [-2, 0, 4, -4], [0, -2, 0, 1], [3, 3, -3, -6], [-2, 3, -2, 0], [-2, 3, 1, -3], [0, -5, -2, -5], [0, -3, -3, -3], [-2, -12, 0, 6], [-8, 2, 4, -2], [1, 3, -1, -6], [4, 6, 4, 0], [-2, 0, 4, 8], [5, 4, 0, -2], [3, 0, -6, -5], [0, -3, 7, -3], [-1, 5, -1, 0], [-5, -6, -5, 0], [1, -1, -1, 2], [-6, 1, -6, 0], [11, 0, 0, 0], [-6, -6, 6, 12], [-3, 8, 0, -4], [0, -4, 12, -4], [19, 2, -19, -4], [-2, -19, -2, 0], [24, -3, -12, 3], [9, 5, -9, -10], [4, 0, -8, -2], [0, 0, 2, 0], [3, 0, -6, 5], [3, 0, -6, -5], [-2, 4, 2, -8], [10, 0, -20, 9], [-6, -20, 0, 10], [-18, 4, 0, -2], [2, -3, -1, 3], [0, 11, -3, 11], [-6, 4, 0, -2], [-2, 18, -2, 0], [-2, -2, 1, 2], [10, 0, -20, 9], [-5, 2, -5, 0], [0, -10, -6, -10], [-8, 8, 0, -4], [14, -5, -14, 10], [6, 10, -3, -10], [-2, 0, -2, 0], [-4, -27, 2, 27], [0, 2, 0, 2], [-16, -4, 0, 2], [-1, -3, -1, 0], [4, -2, 4, 0], [7, -1, -7, 2], [5, 19, 5, 0], [0, -5, -1, -5], [-4, 0, 8, 22], [6, -6, -6, 12], [-8, -6, -8, 0], [18, 0, 0, 0], [0, -6, 10, -6], [0, 6, -26, 6], [1, -13, -1, 26], [32, 5, -16, -5], [-12, -12, 6, 12], [-15, 4, 0, -2], [7, 0, -14, -21], [7, -10, 7, 0], [-24, 8, 24, -16], [-5, 0, 10, 21], [-26, 13, 13, -13], [20, 8, 0, -4], [0, -37, 0, 37], [1, -42, 0, 21], [24, 4, -12, -4], [20, -2, -10, 2], [9, -20, 9, 0], [4, -4, -2, 4], [-8, 0, 16, 2], [14, -8, 14, 0], [-4, 0, 8, -18], [16, 0, 0, 0], [34, -1, -17, 1], [-12, 3, -12, 0], [-14, 12, 14, -24], [0, 6, -6, 6], [-12, -16, 6, 16], [9, 0, -18, 23], [-4, 0, 8, -22], [0, 42, 0, 0], [-5, 0, 10, 15], [-15, 0, 30, -15], [22, -4, -22, 8], [1, -27, 1, 0], [-30, 1, 15, -1], [-25, 8, 0, -4], [0, 9, -9, 9], [-19, 8, 19, -16], [2, 0, 2, 0], [-1, 6, 1, -12], [3, -14, -3, 28], [21, 6, 0, -3], [12, -7, 12, 0], [15, -11, -15, 22], [6, 0, -12, 25], [-24, -21, 12, 21], [16, 32, -8, -32], [0, 7, 14, 7], [-4, 34, 2, -34], [0, -7, 29, -7], [9, -10, 0, 5], [8, 22, 8, 0], [-4, -6, 4, 12], [7, 4, 7, 0], [-5, 0, 10, 5], [3, -27, -3, 54], [-12, 2, 6, -2], [0, 0, -29, 0], [-10, 0, 0, 0], [0, 13, -16, 13], [18, -34, 0, 17], [20, 0, 20, 0], [-17, -3, 17, 6], [3, 0, -6, 18], [0, 9, 1, 9], [-12, -42, 0, 21], [-12, -12, -12, 0], [-40, 6, 20, -6], [0, -5, 15, -5], [0, 20, 9, 20], [-21, 17, 21, -34], [36, 0, -18, 0], [-7, 23, -7, 0], [5, 21, -5, -42], [3, 44, 3, 0], [7, 0, -14, 6], [15, 0, -30, 1], [12, -5, -12, 10], [-13, 36, 0, -18], [0, 8, 16, 8], [16, 13, -8, -13], [-36, 24, 0, -12], [-16, -14, 8, 14], [-24, 0, 48, 6], [14, 0, -28, -31], [0, -16, 0, -16], [29, 9, -29, -18], [54, 0, -54, 0], [10, 28, 10, 0], [-15, 10, 15, -20], [18, 29, -9, -29], [6, -2, -6, 4], [-5, -36, -5, 0], [4, 4, -4, -8], [18, 0, -36, -15], [-3, 20, -3, 0], [-27, -24, 0, 12], [-5, 0, 10, -27], [-26, -12, -26, 0], [-11, 5, -11, 0], [-30, -1, 15, 1], [0, 2, -28, 2], [0, -18, -26, -18], [-54, -9, 27, 9], [2, 18, 2, 0], [30, -6, -30, 12], [-18, 48, 0, -24], [0, -1, 29, -1], [-13, 0, 26, -35], [4, 25, -2, -25], [-18, 28, -18, 0], [14, -22, -7, 22], [0, -7, 28, -7], [-19, -28, 0, 14], [0, 2, 1, 2], [28, -11, -14, 11], [22, -16, -11, 16], [0, 19, -23, 19], [-14, 0, 28, 10], [45, -7, -45, 14], [4, -28, -2, 28], [0, 4, 9, 4], [0, 9, 13, 9], [15, -10, -15, 20], [3, -32, 3, 0], [-20, 0, 40, 26], [0, -4, -53, -4], [0, 63, 0, 0], [-13, 0, 26, -22], [-26, -18, 0, 9], [43, -6, -43, 12], [-22, 10, 22, -20], [-14, 14, 0, -7], [0, -18, 0, 18], [28, 5, -28, -10], [20, 24, -20, -48], [17, 0, -34, -15], [0, -1, 11, -1], [17, 29, 17, 0], [7, 0, -14, 32], [1, 0, -2, -35], [18, 4, -18, -8], [0, -2, 0, 2], [11, -4, 0, 2], [-26, 35, 13, -35], [10, 0, -20, -36], [4, 21, 4, 0], [0, 2, 6, 2], [4, -20, -4, 40], [0, -2, -38, -2], [0, 2, 30, 2], [18, 26, 18, 0], [-21, 25, 21, -50], [0, 0, 0, 18], [31, 44, 0, -22], [0, 2, 44, 2], [0, 2, 20, 2], [8, 0, -16, -4], [-46, 20, 0, -10], [-23, -1, 23, 2], [16, 21, -16, -42], [-27, 10, 0, -5], [0, 3, 36, 3], [0, 35, -6, 35], [14, -2, -14, 4], [-6, -37, 3, 37], [48, 19, -24, -19], [-24, 0, 48, -6], [-2, 0, 4, -40], [-39, 0, 78, 7], [-3, -50, 0, 25], [-48, -22, 24, 22], [-36, 0, 0, 0], [26, -37, -13, 37], [14, -11, -7, 11], [20, -1, 20, 0], [-2, 0, 2, 0], [-22, 0, 44, 37], [17, 0, -34, 18], [15, -30, 0, 15], [52, 4, -52, -8], [-6, -50, 3, 50], [-36, -10, -36, 0], [0, 9, 0, -18], [0, 23, -3, 23], [8, 26, 0, -13], [-19, -1, 19, 2], [10, 0, -20, 2], [-26, -34, -26, 0], [15, 45, 15, 0], [0, -9, 47, -9], [-31, 2, 31, -4], [22, -40, -11, 40], [0, 25, 35, 25], [0, -18, 9, -18], [12, 18, -6, -18], [-16, 11, 16, -22], [-11, 0, 22, -9], [-17, 43, -17, 0], [-28, 0, 56, 9], [-45, 0, 90, -1], [-26, 19, -26, 0], [-44, -24, 0, 12], [0, 4, 36, 4], [28, -32, 0, 16], [12, 72, -6, -72], [9, 0, -9, 0], [-4, -5, -4, 0], [54, -6, 0, 3], [-36, 25, 18, -25], [0, -7, 28, -7], [-26, 64, 0, -32], [-14, 5, -14, 0], [14, -16, -14, 32], [21, 0, -42, -21], [31, 38, 0, -19], [-10, 0, 20, -53], [-29, 15, -29, 0], [-24, 0, 48, 34], [-23, -13, -23, 0], [27, 4, 0, -2], [0, 0, -48, 0], [-67, -8, 67, 16], [-11, -18, 11, 36], [-32, 24, 0, -12], [15, -19, -15, 38], [8, 16, -4, -16], [-52, -2, 0, 1], [-14, -49, 7, 49], [-55, -6, 0, 3], [8, -34, 0, 17]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1110_x_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1110_2_x_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_1110_2_x_b(:prec:=4)
    chi := MakeCharacter_1110_x();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(1999) - 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_1110_2_x_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_1110_2_x_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1110_x();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![4, 4, 6, -2, 1]>],Snew);
    return Vf;
end function;