
// Make newform 2695.2.a.h in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2695_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_2695_2_a_h();".
// 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_2695_2_a_h();".
// 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, -3, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, -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_2695_a();"
function MakeCharacter_2695_a()
    N := 2695;
    order := 1;
    char_gens := [2157, 1816, 981];
    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_2695_a_Hecke(Kf)
    return MakeCharacter_2695_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 := [[-1, 0, -1], [1, 1, 0], [1, 0, 0], [0, 0, 0], [1, 0, 0], [3, -1, 0], [5, -1, 0], [0, -2, -4], [-1, -3, 1], [0, 2, -2], [0, 4, 3], [1, 5, -1], [4, -2, 1], [-1, 1, -3], [9, -1, 0], [3, -5, 1], [2, 2, 3], [2, 2, 1], [-3, 3, 5], [-6, -2, -2], [3, -3, -4], [-1, -5, -5], [-4, 2, -6], [6, -2, -2], [0, 0, 4], [-2, 4, 1], [5, -3, -4], [-6, -2, 2], [-4, 6, -4], [6, -4, -2], [-2, -10, 4], [4, 4, 0], [5, 5, 7], [-6, 2, 4], [4, -6, -8], [-7, 1, 7], [-6, 2, 4], [-9, 5, -1], [12, -6, -4], [-7, 11, 2], [6, 2, 10], [6, 2, 12], [-4, 0, 2], [7, -13, -3], [-9, 11, 9], [-4, 6, 3], [14, -2, -4], [-11, -7, 4], [-8, 4, -4], [6, -4, -10], [-7, 1, -3], [-6, -2, 4], [-6, -4, 7], [-2, -6, -7], [12, 0, 2], [-10, -2, 8], [0, 4, 6], [-10, -6, -4], [5, -7, 9], [10, 0, 12], [2, 2, -10], [11, -3, 6], [10, 8, 10], [8, -14, -1], [4, 2, 6], [6, 4, -4], [10, -10, -12], [-5, 15, 1], [15, 5, -7], [4, -8, -9], [-4, 2, 2], [-7, 9, 1], [3, -11, 2], [-7, -11, -1], [10, 6, -2], [5, -7, 6], [6, 0, -6], [-8, 0, 2], [2, -4, 0], [18, -14, -5], [22, -4, -7], [9, -17, -9], [-29, 3, -1], [4, 10, 16], [-4, 8, 6], [5, -1, 15], [-11, -9, 11], [-5, -13, -7], [12, -22, -3], [13, -1, -7], [-17, 15, 8], [-14, 4, -2], [-9, -7, -3], [17, -15, -3], [-24, 4, 4], [8, 6, 18], [16, -18, -4], [2, -2, 4], [6, -4, 14], [-24, -10, 0], [-4, -8, -6], [19, 7, -1], [16, 4, 14], [-12, 6, 8], [-10, -10, 4], [6, -6, 6], [-7, 1, -18], [-9, -13, -12], [-12, -4, -4], [-2, 16, -9], [20, -22, -4], [1, 9, 1], [9, -3, 3], [-12, 10, 9], [0, 4, 8], [-5, 5, 5], [5, -9, -6], [-7, -17, -2], [18, -8, -10], [19, -13, -15], [-40, 4, 4], [3, 15, 1], [29, -7, -2], [-5, 5, -21], [-28, -2, 3], [-18, 0, 6], [-10, 4, -8], [-2, -12, -13], [5, 3, -18], [21, 7, -4], [-12, 0, -4], [-14, 10, -2], [-6, 14, 8], [-4, 10, -8], [-40, 0, 5], [18, -4, 5], [12, -8, 4], [4, 4, -14], [2, -6, 4], [20, 2, -14], [-12, -6, 2], [6, 0, 18], [-15, -13, 5], [-11, 15, 15], [-18, 0, -20], [-10, 8, 7], [11, -5, -4], [-31, 7, -10], [-36, 0, -5], [-11, 23, -1], [17, -19, -15], [2, 14, 24], [29, 3, 13], [10, 14, 8], [7, -7, 25], [-38, -2, -10], [-2, 18, 16], [-18, -10, 8], [-5, 15, -8], [-6, -6, -19], [-17, 9, -15], [5, -3, -19], [11, 9, 5], [6, 0, -17], [-14, -8, -2], [41, -5, 0], [-16, -4, 6], [-5, -11, -20], [6, 12, -10], [-36, 20, 8], [26, 10, -8], [28, -16, 0], [-3, 25, 7], [-9, -1, -1], [-38, 0, -3], [24, 10, 12], [11, 15, 31], [1, -1, -1], [0, -14, -14], [4, -10, 7], [3, 1, -11], [-22, 16, 18], [-12, 2, 0], [11, 7, -2], [-13, -11, -5], [30, -22, -4], [-1, -9, 3], [-11, 23, 10], [-10, -12, 0], [34, 12, 8], [-6, -8, 2], [-12, -4, 16], [52, -16, -6], [-22, -10, -2], [9, 15, -1], [16, -8, -14], [-20, -14, 2], [-3, 9, 15], [3, 7, -8], [30, -14, 0], [-6, -12, 6], [-8, 2, 14], [-22, 0, -2], [28, -20, -3], [-40, 12, -5], [26, 4, 16], [-20, -12, 1], [14, -6, -24], [32, 6, -8], [18, 2, -9], [7, -5, -21], [6, 0, 6], [-13, -7, 9], [21, -37, -12], [10, 20, -22], [4, 8, -20], [-43, 3, -9], [34, 0, 9], [21, -25, -11], [38, -8, -2], [-10, -24, -10], [-14, 4, -14], [-13, -11, -35], [-1, -15, -33], [-16, -18, -20], [-22, -20, 18], [-10, 24, -2], [-24, 32, 8], [10, 6, 24], [-7, 29, -1], [29, -11, 3], [-52, 0, -4], [-8, 4, 24], [0, 18, -10], [-21, 1, 8], [-10, 20, -8], [-28, -10, 4], [3, 7, -3], [-14, 22, 2], [32, 10, -7], [-5, 17, 7], [-4, 4, -6], [-63, 7, 2], [-39, 15, 13], [-9, -17, -22], [4, 14, 10], [-17, 29, -4], [-10, -12, -23], [-4, 8, -4], [-42, -6, 8], [-25, 3, 9], [14, -2, 15], [23, -27, -7], [-28, -20, 0], [23, 1, 2], [16, -4, 28], [47, -15, -1], [-34, -8, -16], [-20, -10, -2], [27, 15, 10], [-13, 13, 1], [-44, -4, 12], [-8, 14, 5], [37, 11, -2], [-16, 4, 14], [-36, -2, 17], [7, -7, -17], [-8, 38, 0], [7, -3, -23], [11, -9, 21], [12, -14, 10], [-53, 9, 11], [-4, 2, 8], [0, 16, -8], [35, 5, -8], [59, -1, -6], [27, -19, -17], [-56, -2, -6], [-6, 20, 14], [20, -4, -14], [0, 2, 4], [-20, 32, 30], [-18, -4, -12], [42, 14, -1], [26, -8, 4], [-28, 20, 8], [-17, -1, 17], [-43, 17, -9], [-12, -14, 3], [0, -4, -33], [49, -21, -19], [53, 5, 22], [67, -1, 3], [-14, -14, 12], [-23, 5, 11], [-20, 14, -3], [-12, 0, 19], [10, -2, -30], [18, -34, -4], [0, 16, -2], [31, -17, -20], [21, -3, -1], [1, 1, 19], [-33, 37, 21], [-10, 18, -24], [33, 13, -5], [-1, 1, 1], [28, 22, 6], [22, -26, 6], [-23, 37, 9], [-48, -16, -4], [-42, -8, 10], [18, -16, 28], [13, 3, 1], [-33, -23, -7], [-8, 10, 7], [8, 14, 21], [-50, 2, -12], [22, 12, 26], [-42, 24, 6], [2, 10, 10], [34, 8, -14], [0, -4, 19], [-51, 3, 3], [-5, 11, -31], [-2, 20, 8], [-20, -8, 6], [1, 17, 26], [7, 9, 17], [19, 7, 31], [-48, 14, 4], [29, 17, -21], [-20, 18, 2], [-10, 14, -4], [57, 5, 7], [11, 13, 32], [35, 5, 15], [7, -25, 18], [-4, -6, -18], [-20, 6, 26], [44, -18, -16], [53, 9, 7], [48, 4, -3], [-18, 10, 20], [-28, 14, 2], [-4, -28, -24], [-4, 36, 22], [-25, 25, 21], [24, -2, -6], [-14, -8, 30], [-22, 24, -18], [35, -41, -7], [6, 16, 2], [26, 0, 0], [-28, 6, 10], [21, -3, 24], [-14, 12, 25], [6, 6, 2], [5, -15, 11], [29, 27, 11], [-21, 15, 13], [-28, 22, -7], [9, -13, 27], [19, -37, -9], [17, -17, -6], [41, -15, -17], [-19, 15, -10], [-30, -6, -8], [-38, 24, 0], [-36, 16, 4], [16, -4, -27], [10, 22, -12], [24, -10, -10], [-22, 24, 16], [-9, 27, 5], [36, -30, -11], [-3, 25, -17], [69, -9, -12], [-40, 12, 7], [13, -5, 16], [18, -8, -20], [-25, 43, 1], [23, -19, -7], [43, -5, -1], [-32, 6, 16], [13, 29, -24], [-62, 6, 0], [-22, 0, -40], [-22, 34, 40], [-33, -13, -22], [-11, -1, -9], [-14, 22, -26], [-6, -6, -4], [15, -37, -12], [-42, 38, 24], [21, -3, 27], [24, -44, 2], [42, 4, 0], [6, -10, -12], [0, 14, 4], [-4, 6, -15], [48, -18, -2], [-60, 4, -4], [38, 20, 40], [14, 4, -27], [24, -20, 4], [58, -16, -16], [18, -16, -2], [33, 1, 0], [-40, 46, 27], [1, 9, 14], [25, 37, -21], [39, -15, 7], [-5, -1, 15], [29, 5, 7], [-34, -10, -10], [-8, -32, -24], [1, 13, -18], [-42, 0, 4], [4, 24, 0], [2, 8, 48], [-23, -1, 32], [-55, 3, 17], [14, -44, -40], [28, 6, 18], [-14, -14, -10], [-27, 15, 1], [28, -22, -34], [-4, -4, -7], [-24, -22, 32]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2695_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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