
// Make newform 1170.2.m.d in Magma, downloaded from the LMFDB on 30 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1170_m();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1170_m_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_1170_2_m_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_1170_2_m_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
        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_1170_m();"
function MakeCharacter_1170_m()
    N := 1170;
    order := 4;
    char_gens := [911, 937, 1081];
    v := [4, 3, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1170_m_Hecke();"
function MakeCharacter_1170_m_Hecke(Kf)
    N := 1170;
    order := 4;
    char_gens := [911, 937, 1081];
    char_values := [[1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, -1]];
    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 := [[-1, 0, 0, 0], [0, 0, 0, 0], [0, -2, 1, 2], [0, 0, 0, 1], [1, 2, 2, 1], [0, 4, 0, -1], [4, 3, -3, -4], [2, -4, -4, 2], [3, -2, -2, 3], [1, 0, -2, 5], [-5, 0, 0, 5], [-2, 0, 4, -1], [-4, -6, 6, 4], [-4, 9, 9, -4], [1, 0, -2, 2], [-3, 4, -4, 3], [2, -2, 2, -2], [2, -8, 0, 4], [9, 2, 0, -1], [-6, -7, 7, 6], [0, 0, 0, 0], [3, 0, -6, 5], [3, 0, -6, 3], [-2, 6, -6, 2], [-5, 6, 0, -3], [-4, 0, 8, -6], [9, -10, -10, 9], [5, 0, 0, 5], [-3, 1, 1, -3], [3, -6, 6, -3], [-7, 4, -4, 7], [9, 4, 0, -2], [-5, 0, 10, 3], [1, 0, -2, 8], [3, -10, -10, 3], [12, -3, -3, 12], [-10, -4, -4, -10], [1, -2, 0, 1], [-2, 0, 4, -10], [-1, 2, 2, -1], [-11, -12, 0, 6], [-3, 0, 6, 1], [-1, -14, 0, 7], [-13, 2, 0, -1], [-12, 10, 0, -5], [-9, -18, 0, 9], [12, -2, 0, 1], [-7, 0, 14, -6], [-6, 0, 0, 0], [9, 3, -3, -9], [-2, -9, -9, -2], [-4, 15, 15, -4], [-16, 4, 4, -16], [-4, 0, 8, 6], [15, 3, -3, -15], [18, 6, -6, -18], [0, 0, 0, -20], [-9, 21, 21, -9], [0, 4, -4, 0], [-8, 10, 10, -8], [-5, 10, 10, -5], [11, 16, 0, -8], [6, 0, -12, -2], [0, 0, 0, 10], [17, -5, 5, -17], [-4, 32, 0, -16], [9, 0, 0, -9], [1, 1, -1, -1], [6, -1, -1, 6], [-16, -11, 11, 16], [13, 0, -26, -7], [11, 24, -24, -11], [7, 10, 10, 7], [8, 0, 0, -8], [-19, 0, 0, -19], [-2, 0, 4, -9], [10, 4, 0, -2], [-4, 0, 8, -22], [5, 6, 6, 5], [-15, 6, 6, -15], [1, 0, -2, 14], [15, 3, -3, -15], [9, 9, -9, -9], [1, 1, 1, 1], [-2, 20, 0, -10], [-9, -25, 25, 9], [7, 12, -12, -7], [14, 0, 0, 0], [4, 3, -3, -4], [-10, -4, 0, 2], [13, 16, -16, -13], [-8, -23, 23, 8], [-2, -16, 0, 8], [-7, 0, 14, -26], [-8, 18, 18, -8], [2, -2, 2, -2], [15, -10, -10, 15], [17, -12, 0, 6], [-17, -4, 4, 17], [-18, 21, 21, -18], [12, 1, 1, 12], [-11, 0, 22, -14], [-8, 15, 15, -8], [-29, 8, 0, -4], [8, 0, -16, -25], [2, 12, 0, -6], [3, -10, 0, 5], [13, 2, 0, -1], [12, 0, -24, 4], [32, -2, 0, 1], [16, -14, -14, 16], [12, 0, -24, -4], [16, -24, 0, 12], [20, 28, -28, -20], [-4, -3, -3, -4], [2, 0, -4, 36], [5, 0, -10, -5], [-22, -16, 16, 22], [0, -6, 6, 0], [6, 0, -12, 10], [15, -16, -16, 15], [2, -3, -3, 2], [17, -38, -38, 17], [9, -26, 0, 13], [18, 24, -24, -18], [-15, 0, 30, -15], [-1, -14, 14, 1], [9, 38, 0, -19], [5, 2, -2, -5], [6, 0, -12, -5], [6, 20, -20, -6], [-22, 0, 44, 9], [-14, 0, 28, 2], [-3, -16, -16, -3], [-20, 6, 6, -20], [8, -26, -26, 8], [21, 0, -42, -12], [-18, 0, 36, -6], [30, -4, 4, -30], [6, 0, -12, -15], [-12, 14, -14, 12], [-15, -13, 13, 15], [18, 0, 0, 18], [12, 0, -24, -34], [-15, -14, 0, 7], [-23, -20, 20, 23], [4, 10, 0, -5], [-11, -6, 6, 11], [-22, 0, 44, -8], [15, 0, -30, 26], [-6, -34, 0, 17], [-15, 0, 30, -8], [-9, 7, 7, -9], [2, -20, -20, 2], [-20, -29, 29, 20], [-21, 30, 0, -15], [-22, 0, 44, 2], [-16, 10, 10, -16], [-3, 6, 6, -3], [-5, 13, -13, 5], [-25, 0, 50, -17], [2, -33, -33, 2], [-6, -46, 0, 23], [0, 26, 0, -13], [-17, -10, 0, 5], [0, -2, 0, 1], [16, 8, 0, -4], [9, 8, 8, 9], [-12, 6, -6, 12], [-19, 6, 6, -19], [-23, -2, -2, -23], [-25, 17, 17, -25], [22, 0, -44, 4], [-6, 0, 12, 40], [47, -14, 0, 7], [6, 0, -12, 19], [24, -34, -34, 24], [35, -14, -14, 35], [42, -6, -6, 42], [17, 0, -34, -3], [20, 0, -40, -8], [22, 0, -44, -6], [29, 16, -16, -29], [0, 28, 0, -14], [20, -8, 0, 4], [2, 20, 0, -10], [-32, -16, 16, 32], [4, 0, -8, -58], [-22, -20, 20, 22], [-17, -6, -6, -17], [-25, -17, 17, 25], [-14, 0, 28, 4], [-16, 34, 0, -17], [-15, 10, 10, -15], [-10, 9, -9, 10], [-21, 26, 26, -21], [-28, -6, 6, 28], [-19, -14, -14, -19], [-3, 0, 6, 15], [26, 20, -20, -26], [-42, -9, 9, 42], [-7, 42, 0, -21], [20, 30, 0, -15], [21, 0, -42, 4], [-6, 4, -4, 6], [34, -12, -12, 34], [-5, 1, 1, -5], [15, -6, 6, -15], [31, -22, -22, 31], [13, 0, -26, 20], [19, 18, -18, -19], [-5, -54, 0, 27], [-29, 14, -14, 29], [-10, 0, 20, -6], [11, -25, -25, 11], [25, -22, -22, 25], [24, -20, -20, 24], [-26, -34, 0, 17], [54, 12, 0, -6], [15, 52, 0, -26], [22, 16, 0, -8], [17, -13, 13, -17], [-6, -12, -12, -6], [31, 0, -62, -6], [-32, -9, 9, 32], [-4, 16, 0, -8], [-20, 9, -9, 20], [1, 0, -2, 29], [-8, -14, 14, 8], [-1, 16, 16, -1], [12, 18, 18, 12], [0, 0, 0, -16], [-31, -32, 32, 31], [10, 0, -20, -39], [6, 9, -9, -6], [-1, -4, 0, 2], [24, 4, -4, -24], [-12, -54, 0, 27], [-6, -8, 0, 4], [27, -2, 0, 1], [2, 0, -4, 0], [-3, 0, 6, -70], [-18, 26, -26, 18], [24, 17, 17, 24], [1, 0, -2, 47], [21, -26, 0, 13], [19, 0, -38, -24], [8, 22, 22, 8], [-1, 40, 40, -1], [0, 6, 6, 0], [7, 0, -14, -24], [29, 10, -10, -29], [-4, 0, 8, 39], [-10, 6, 0, -3], [9, 22, -22, -9], [-9, -10, 10, 9], [39, 6, 0, -3], [-34, -44, 0, 22], [13, -4, 4, -13], [26, -40, 0, 20], [40, -14, -14, 40], [-1, -3, -3, -1], [-10, -19, -19, -10], [25, 12, -12, -25], [28, 0, -56, -12], [6, 0, -12, -29], [-17, -15, -15, -17], [-25, -46, 46, 25], [-22, 4, 0, -2], [14, 2, 2, 14], [-3, 0, 6, -35], [46, 0, 0, 0], [13, 54, 0, -27], [-21, -50, 0, 25], [7, 22, 22, 7], [-8, 0, 16, -64], [30, -24, 0, 12], [-15, 2, -2, 15], [26, -46, -46, 26], [-6, 0, 12, -39], [-31, -16, 16, 31], [-1, 19, 19, -1], [-5, 22, 22, -5], [-37, 14, -14, 37], [11, 0, -22, -39], [-18, 0, 36, 20], [-6, -29, 29, 6], [25, 12, 0, -6], [0, -17, 17, 0], [24, 48, 0, -24], [6, -12, 0, 6], [-30, -3, -3, -30], [8, 0, -16, -44], [-33, -12, -12, -33], [-13, 4, -4, 13], [44, -40, 0, 20], [-75, 6, 0, -3], [-6, -2, -2, -6], [-30, 0, 60, -3], [3, 0, -6, -47], [-28, -1, -1, -28], [-10, 0, 20, 27], [-31, -34, 0, 17]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1170_m_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1170_2_m_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_1170_2_m_d(:prec:=4)
    chi := MakeCharacter_1170_m();
    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_1170_2_m_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_1170_2_m_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1170_m();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![1, 0, 1]>,<11,R![4, -16, 32, -8, 1]>],Snew);
    return Vf;
end function;