
// Make newform 1170.2.bp.d in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1170_bp();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1170_bp_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_bp_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_bp_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_bp();"
function MakeCharacter_1170_bp()
    N := 1170;
    order := 6;
    char_gens := [911, 937, 1081];
    v := [6, 3, 2];
    // 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_bp_Hecke();"
function MakeCharacter_1170_bp_Hecke(Kf)
    N := 1170;
    order := 6;
    char_gens := [911, 937, 1081];
    char_values := [[1, 0, 0, 0], [-1, 0, 0, 0], [-1, 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, -1], [0, 0, 0, 0], [0, -2, 1, 2], [-1, 1, -1, 0], [0, -1, -1, -1], [0, 3, -2, -3], [2, -1, 2, 0], [3, 1, -3, -2], [6, -1, -3, 1], [0, -2, 3, -2], [4, 0, 0, 0], [8, -1, -4, 1], [0, 3, -4, 3], [1, 5, 1, 0], [5, 0, -10, -1], [-1, 0, 2, -6], [2, -6, -2, 12], [-2, -7, 2, 14], [10, 1, -5, -1], [3, 1, -3, -2], [-5, 0, 10, 4], [-12, 0, 0, 0], [1, 0, -2, -7], [0, -4, -2, -4], [0, -10, 0, 0], [0, -4, 7, -4], [-1, 0, 2, 11], [2, 3, -1, -3], [-10, 0, 0, 0], [0, 9, 0, 0], [0, -4, 0, 4], [0, -16, 0, 8], [2, -15, 2, 0], [-8, -4, 8, 8], [-13, 4, 13, -8], [7, 14, 0, -7], [-6, 0, 12, 1], [-2, 10, -2, 0], [16, 0, -8, 0], [12, 2, 12, 0], [0, 3, -13, 3], [-4, 14, 0, -7], [-6, 2, 6, -4], [10, -2, -5, 2], [-16, -4, 8, 4], [-9, 11, 9, -22], [0, -2, 18, -2], [12, 10, -6, -10], [-3, -1, -3, 0], [-8, 24, 0, -12], [-6, 0, 12, -2], [11, 18, 0, -9], [-1, -6, 1, 12], [-18, 2, 18, -4], [0, -3, 0, 3], [-14, 5, 7, -5], [6, 6, -6, -12], [0, 8, 8, 8], [-10, -5, -10, 0], [0, 2, 0, -1], [-10, -1, 5, 1], [-1, 12, -1, 0], [-1, 0, 2, 21], [9, 14, 0, -7], [0, 0, 0, -14], [1, 0, -2, 28], [8, -12, -8, 24], [-11, 0, 22, 8], [-5, -3, -5, 0], [0, -4, -26, -4], [-28, 1, 14, -1], [21, 14, 0, -7], [30, -7, -15, 7], [-2, -27, -2, 0], [0, -14, 2, -14], [-4, 20, -4, 0], [-31, -8, 0, 4], [10, -2, 10, 0], [0, 11, 10, 11], [23, 4, -23, -8], [0, 2, 10, 2], [-2, -22, 0, 11], [0, -3, -13, -3], [3, 20, 3, 0], [0, 3, 15, 3], [-20, 0, 40, 0], [-6, -8, 6, 16], [6, 14, -3, -14], [33, 4, -33, -8], [5, 0, -10, -15], [-11, 0, 22, -3], [0, 0, 16, 0], [-17, 9, -17, 0], [0, 3, 27, 3], [-30, 12, 0, -6], [3, 27, 3, 0], [0, -16, 3, -16], [-10, -34, 0, 17], [34, -7, -17, 7], [4, 6, 0, -3], [3, 0, -6, -31], [10, -6, -5, 6], [0, 8, 0, 0], [0, -8, -32, -8], [-17, 10, 0, -5], [-15, 0, 30, 2], [16, 24, -8, -24], [-6, 0, 12, -9], [-12, -24, 0, 12], [0, 0, -17, 0], [-6, 38, -6, 0], [-24, 1, 12, -1], [-16, 5, -16, 0], [-2, -44, 0, 22], [4, 8, -4, -16], [-10, -11, 10, 22], [-12, -12, -12, 0], [20, -6, -10, 6], [40, 2, -20, -2], [38, -2, -38, 4], [0, -13, 16, -13], [2, 12, -1, -12], [-20, 0, 40, -14], [4, -20, 4, 0], [0, 9, -25, 9], [10, -4, 0, 2], [18, -11, -18, 22], [22, -6, -22, 12], [-1, 0, 2, 15], [6, 0, -12, 35], [0, 8, 16, 8], [-4, 18, 2, -18], [0, 11, -17, 11], [-44, 2, 22, -2], [30, 4, -30, -8], [0, -2, 42, -2], [-20, 6, -20, 0], [10, -2, 10, 0], [4, 8, 4, 0], [0, 15, 24, 15], [-20, 16, 0, -8], [0, -14, -14, -14], [-6, 30, -6, 0], [12, 0, -24, 28], [0, 7, 30, 7], [-10, 22, 10, -44], [4, 0, -8, -19], [4, 0, -8, -3], [1, -50, 0, 25], [-7, 0, 14, -9], [-2, -13, -2, 0], [0, 7, 30, 7], [-14, 0, 28, 6], [8, 36, -4, -36], [8, 0, -4, 0], [-6, 44, 0, -22], [-54, 2, 54, -4], [-24, 9, 24, -18], [11, 0, -22, -2], [-2, 12, 0, -6], [-32, 0, 16, 0], [16, -10, 16, 0], [9, 0, -18, 1], [-48, 4, 48, -8], [-28, -3, 14, 3], [16, 0, -32, 4], [0, 11, 11, 11], [4, -9, 4, 0], [34, 12, 0, -6], [-23, 0, 46, 12], [9, 2, 0, -1], [-18, -17, 18, 34], [8, -4, -8, 8], [-5, 40, -5, 0], [26, -12, 0, 6], [30, -11, -30, 22], [0, -11, 31, -11], [-21, 16, 0, -8], [0, 16, 0, -16], [0, 20, 2, 20], [-3, 0, 6, -31], [-4, -24, 0, 12], [-18, 0, 36, -13], [-8, 0, 16, 42], [-38, -23, 19, 23], [-39, -14, 39, 28], [22, 0, -44, 26], [-16, 0, 32, 20], [0, -6, -1, -6], [-47, -1, 47, 2], [-1, -6, -1, 0], [-1, 1, -1, 0], [13, -26, 0, 13], [0, -8, -6, -8], [11, -39, 11, 0], [12, 6, -6, -6], [9, 4, 0, -2], [2, 27, 2, 0], [-8, 0, 16, 21], [-10, 0, 20, -2], [-51, 6, 51, -12], [6, 6, -6, -12], [12, 39, -6, -39], [-19, -12, 0, 6], [0, 9, 13, 9], [14, -6, -7, 6], [9, -30, 0, 15], [0, -44, 0, 0], [0, -5, -4, -5], [-10, -14, 10, 28], [26, -32, -13, 32], [54, 20, 0, -10], [-10, -19, 5, 19], [31, -15, 31, 0], [-28, -4, 28, 8], [7, 0, 0, 0], [-8, 0, 16, -32], [-50, 3, 50, -6], [36, 38, -18, -38], [4, 0, -8, -10], [0, 21, -12, 21], [-4, 0, 0, 0], [30, -18, 0, 9], [4, -8, 4, 0], [46, 9, -23, -9], [24, 14, 0, -7], [-8, -1, 4, 1], [38, -10, -38, 20], [10, -46, 10, 0], [28, 0, 0, 0], [48, -7, -24, 7], [0, 22, -26, 22], [0, -30, -2, -30], [18, 30, 0, -15], [-20, 0, 40, 4], [16, 0, -32, -44], [-6, -18, 6, 36], [34, -14, -17, 14], [-18, 22, 18, -44], [0, -21, -15, -21], [26, 15, -13, -15], [0, -15, -17, -15], [-23, -13, -23, 0], [0, -21, -14, -21], [-6, 43, -6, 0], [30, -20, 0, 10], [-36, 0, -36, 0], [0, 16, -12, 16], [29, -1, -29, 2], [-18, 23, 9, -23], [20, 6, -10, -6], [0, -40, 8, -40], [6, 0, -12, -46], [0, 4, 37, 4], [4, 0, -8, 64], [9, -31, -9, 62], [-10, -32, 10, 64], [22, 55, -11, -55], [8, 0, -16, -46], [-11, -4, -11, 0], [-6, 0, 12, -18], [-36, 22, 18, -22], [-22, 26, 0, -13], [4, -19, -2, 19], [0, 21, 0, 0], [-19, 19, 19, -38], [6, 0, -6, 0], [-20, -46, 0, 23], [3, 23, 3, 0], [-5, 18, -5, 0], [62, -22, 0, 11], [-10, 0, 20, 46], [6, 14, -3, -14], [-8, -12, 8, 24], [-36, -2, -36, 0], [-78, -1, 39, 1], [8, -44, 8, 0], [52, -6, 0, 3], [43, 18, -43, -36], [3, 19, -3, -38], [-18, -21, 9, 21], [0, 10, -38, 10], [0, 0, 0, -52], [0, -11, 32, -11], [-17, 0, 34, -47], [-47, 6, 0, -3], [29, 0, -58, 0], [-19, 0, 38, 26], [23, 31, -23, -62], [10, 1, -10, -2], [0, 30, -22, 30], [37, -9, 37, 0], [8, 33, -4, -33], [12, 20, -12, -40], [-18, 26, -18, 0], [-15, 20, 0, -10], [24, 32, 0, -16], [-2, 18, 1, -18], [0, -22, -26, -22], [-42, -21, 21, 21], [-15, -20, -15, 0], [-1, 0, 2, 30], [0, 15, -37, 15]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1170_bp_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1170_2_bp_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_bp_d(:prec:=4)
    chi := MakeCharacter_1170_bp();
    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_bp_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_bp_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1170_bp();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![4, 12, 14, 6, 1]>],Snew);
    return Vf;
end function;