
// Make newform 2695.2.a.g 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_g();".
// 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_g();".
// 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], [-1, 1, -2], [-1, 3, 0], [-2, 0, 2], [-3, -1, -1], [-4, 2, 2], [4, -2, -1], [-5, -1, -3], [0, 0, 3], [-1, 1, 5], [7, -1, 2], [-3, -3, -1], [-6, 4, -1], [-4, 2, 5], [-1, 1, -5], [-10, 6, 2], [1, -7, 0], [1, 5, 5], [2, 4, -4], [-8, 4, 4], [2, -6, -6], [-2, -2, -5], [1, -1, -4], [-6, 6, 2], [0, 6, 4], [-6, 0, -2], [-14, 2, 0], [4, -4, 0], [-9, 7, 5], [2, 6, 0], [8, -10, 0], [7, -1, -7], [8, 4, 2], [1, -5, -3], [-2, 4, -2], [-1, -9, -2], [-14, 6, -2], [-4, -8, 2], [-4, -8, 2], [-1, -9, -7], [7, -9, -3], [2, -6, 1], [6, -2, -8], [13, -1, -4], [12, -8, -8], [6, 0, 14], [-3, 5, 1], [-10, -6, -12], [-2, -2, 5], [-2, -8, -7], [-10, -2, -12], [-2, -10, 0], [10, -2, -4], [2, 2, 4], [-7, -7, -7], [-10, 8, 8], [-2, 6, 6], [-11, -7, 2], [-8, -2, 8], [2, 10, 5], [-16, -2, -10], [2, 0, 8], [10, -2, -4], [7, 3, -11], [3, -15, -11], [-14, 12, 3], [-8, -10, 6], [-17, -1, 7], [13, 9, 4], [13, 13, -9], [-6, -14, 6], [5, 11, 10], [-6, 12, 6], [6, 10, 4], [14, -8, -4], [4, -2, 7], [4, -8, -9], [9, 3, -9], [-19, 5, 1], [12, -18, -12], [4, 4, 2], [23, -15, -3], [1, -9, -1], [3, -1, -3], [-12, -8, 7], [-5, -7, 11], [-1, -7, -4], [16, -10, -12], [5, -5, 3], [3, 11, -9], [20, 4, 8], [-10, 16, 8], [28, -2, -4], [-4, -8, -6], [-12, -14, 8], [0, -2, 12], [-8, -4, 14], [-9, -1, -1], [8, -8, -6], [-12, 10, -4], [26, 2, 12], [20, 8, 4], [-7, 3, -2], [7, -7, 6], [-8, -4, 8], [-6, -6, -11], [-10, 12, 6], [-15, -15, 9], [3, 15, -7], [-10, 14, -1], [-8, 4, -8], [11, 9, 13], [11, 11, 0], [-9, -5, -20], [26, -8, -6], [5, -11, -1], [10, 10, -10], [-25, 3, 5], [-19, 15, 4], [1, -21, 1], [10, -6, -3], [6, -12, 10], [-6, -8, -4], [-16, -8, -11], [3, 15, 4], [-13, 7, 4], [36, 0, 4], [-26, -2, 2], [-6, 18, 16], [-8, 22, 0], [-14, 20, 13], [-2, 10, -17], [-6, -2, 22], [8, 4, -2], [8, -12, 10], [-12, -14, -14], [-34, 12, 0], [6, 0, -2], [3, -3, -1], [-3, 15, 7], [-2, 0, 4], [8, 12, 29], [-21, -7, -6], [-17, -5, -10], [8, -6, -5], [3, -11, -7], [-3, 1, 13], [20, 16, -10], [-13, 1, -21], [22, -26, -8], [-7, 7, 19], [-26, 6, 2], [26, 14, 0], [-16, 0, -6], [3, -11, 6], [24, -2, 1], [-23, 19, -1], [37, 1, 1], [-17, 5, 17], [-4, 8, 9], [-42, 4, 6], [19, -9, -10], [32, -8, -10], [-43, 5, 0], [-18, -12, -6], [38, -2, 6], [22, -10, 8], [6, -10, -22], [-33, 11, 5], [-5, -5, 3], [20, 8, -1], [8, 14, 32], [-19, -15, -15], [-19, -17, 3], [2, 0, -16], [24, -12, 1], [9, 15, -1], [-8, 2, -4], [-24, -10, 8], [-37, -7, 0], [5, -9, 13], [-28, -8, 10], [31, -13, -9], [-5, -5, 20], [6, -8, 8], [12, 6, 6], [2, 20, -2], [-28, 20, 8], [-4, 20, 10], [8, -16, 8], [-3, 3, -13], [-26, -6, 16], [-32, 18, 6], [-45, 15, 1], [-5, 13, 6], [50, -6, -4], [-38, 12, 2], [-6, 20, -16], [2, -12, 14], [-30, 28, 5], [20, -2, 19], [18, -20, -12], [-20, -18, -15], [-10, 2, 24], [-8, -2, 20], [-22, 28, 19], [-9, -13, 11], [-26, -12, -6], [-15, -9, -21], [-25, -9, 6], [4, 10, 8], [18, 2, -10], [-15, 7, -13], [-10, -2, 23], [-17, -11, 19], [2, -12, -2], [42, -8, 6], [-16, -18, -16], [-13, -7, -11], [41, 3, 9], [26, 16, 14], [2, 16, -10], [-22, 8, 14], [20, 4, -20], [-34, -2, 0], [-13, -1, -11], [3, 3, 13], [-4, 16, 8], [-4, -8, 12], [-4, 22, 10], [21, -15, -14], [-8, -30, 18], [-8, 6, -24], [-5, 27, 33], [22, -10, 22], [6, -14, -17], [25, 19, -7], [-44, 0, -6], [31, 3, -4], [-3, 31, 1], [-13, -19, 8], [-30, 4, -20], [-3, 1, 10], [-44, 16, -1], [48, -4, 0], [14, -22, -24], [15, -9, -19], [16, 18, 19], [29, 15, -1], [10, 22, -10], [-23, -19, -6], [-8, 4, -20], [-21, 17, 19], [12, -22, -26], [-20, 38, 14], [-13, 1, 20], [-5, -3, -15], [20, -4, 28], [4, -16, -33], [15, -5, 34], [-14, 2, -8], [-18, 26, -5], [-29, 9, -5], [-4, -2, 0], [11, 17, -19], [3, 23, 21], [52, 10, -10], [-7, 27, -3], [-4, 6, -28], [12, -36, -12], [-39, 1, -16], [-29, 5, -18], [-19, -25, -15], [-24, -10, -22], [38, 8, -18], [8, 28, 2], [-26, 24, -10], [4, -28, -10], [-32, -6, -6], [36, -6, 11], [12, 14, -10], [-48, 20, 12], [1, -15, -17], [29, -3, 27], [-6, 6, -3], [14, -32, -25], [-59, 11, 1], [5, -1, -30], [7, -5, 7], [2, 22, -8], [29, 13, 19], [32, 16, 27], [12, 14, 31], [0, -4, -36], [34, -22, 4], [-20, 0, 2], [3, 17, 6], [5, 37, -17], [-13, 19, 9], [61, 7, 11], [10, -6, -12], [-33, 3, 13], [-7, -21, 7], [20, -10, -10], [-10, 22, 30], [-3, -3, -39], [-8, 8, 16], [30, 0, -6], [-26, -8, 0], [-5, 33, 15], [-17, 17, -23], [-36, -8, 13], [18, -14, 27], [10, -10, 12], [22, 24, 18], [-30, 0, 6], [-14, -14, -26], [10, 8, 6], [-2, -8, 23], [39, -27, -7], [39, -13, 1], [-58, 12, 4], [-4, -12, -26], [9, 19, 26], [11, -35, 5], [31, 3, 27], [-24, 6, -16], [-29, 7, -11], [-22, 40, 8], [30, 18, 4], [-45, 7, -11], [-15, -7, -10], [-17, 21, 27], [-29, -3, -16], [40, 6, 18], [22, -44, 4], [24, -14, -8], [-13, 15, -31], [-22, 8, -3], [10, -10, -32], [-28, 14, -14], [-24, 16, -20], [46, -26, -8], [13, -21, 11], [46, -12, -16], [-14, 36, 14], [24, -30, -24], [-23, 13, -21], [54, 0, 10], [52, -26, -10], [24, 18, -2], [-19, 31, 26], [-20, 36, 15], [2, 34, 38], [21, 21, 7], [-17, 45, 9], [23, 7, -3], [4, 4, -5], [-17, -31, -3], [29, -3, 1], [19, 15, 32], [-25, -1, -23], [-29, 19, 10], [22, -2, -4], [34, 0, 16], [8, 32, 0], [12, -30, -19], [2, 38, 12], [4, -14, -22], [0, 14, 2], [-19, -7, -41], [46, -42, -5], [-41, -21, 13], [-9, 27, -16], [-10, 32, 31], [51, -29, 0], [-22, 0, -8], [37, -55, -29], [23, -43, 1], [-1, 19, 23], [14, -40, -42], [9, -1, -8], [-30, -2, 32], [22, -20, 20], [-62, 2, -16], [39, 1, -26], [-15, 39, -13], [8, 28, -32], [2, -26, -44], [51, -31, -4], [-2, -26, -24], [-27, 5, 19], [12, -28, -26], [-50, -8, -8], [26, -2, 16], [4, -2, -12], [0, 16, -9], [8, -10, 14], [-4, -4, 12], [-54, -16, 8], [-2, 6, -1], [24, 20, 8], [-30, -8, -16], [-2, -28, -26], [-31, 55, 12], [38, -6, 1], [9, -17, 0], [5, 41, 15], [-51, 23, 13], [17, 5, 37], [41, -15, 11], [-36, -8, -4], [-52, 4, -28], [49, 7, 22], [38, -8, -24], [8, -28, -12], [50, 0, -24], [-45, -5, 0], [47, -11, 11], [-8, -18, -38], [-12, -18, -46], [-12, -4, 20], [27, -31, -37], [16, 2, -38], [4, -10, -11], [-30, -24, 10]];
    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_g();".
// 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_g(: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_g();".
// 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_g( : 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, -2, 1]>],Snew);
    return Vf;
end function;