
// Make newform 2775.2.a.p in Magma, downloaded from the LMFDB on 04 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2775_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_2775_2_a_p();".
// 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_2775_2_a_p();".
// 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 := [-2, 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_2775_a();"
function MakeCharacter_2775_a()
    N := 2775;
    order := 1;
    char_gens := [926, 1777, 76];
    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_2775_a_Hecke(Kf)
    return MakeCharacter_2775_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, 1], [1, 0], [0, 0], [2, 0], [0, 2], [-2, -2], [-2, 4], [3, -3], [3, 1], [-2, -2], [6, 0], [1, 0], [-5, 4], [3, -3], [6, 2], [3, -4], [9, -1], [-12, 0], [-2, -4], [4, -8], [-3, -6], [5, 5], [4, -4], [-10, 2], [0, 6], [-7, -4], [3, -3], [0, 6], [14, -4], [0, -6], [4, -10], [-6, 0], [2, 4], [12, 0], [-5, -2], [16, -2], [1, -8], [-7, 9], [-5, -5], [-2, -8], [-6, -12], [1, -6], [15, 1], [16, -8], [23, -2], [-1, 9], [0, -6], [-2, 10], [9, 3], [-3, 0], [15, 4], [-1, -1], [-26, 2], [-5, 1], [6, -12], [16, -2], [-21, -2], [-8, -6], [20, 8], [-12, 4], [25, -3], [-21, 0], [8, 6], [1, 5], [0, 6], [-23, -2], [-6, 0], [9, 18], [15, 3], [-27, -6], [-12, -16], [-24, 6], [-2, -6], [2, 24], [0, -6], [-1, 7], [-12, -14], [-17, -14], [-12, 18], [-2, -18], [-8, 10], [22, -2], [25, 1], [10, 16], [-1, 23], [10, -14], [4, 22], [-2, 2], [-6, -12], [2, 12], [2, 4], [-14, -8], [-6, 12], [-6, 18], [-11, 1], [14, -16], [-11, -10], [-5, 8], [-6, 0], [40, -2], [14, 12], [-2, -22], [-15, 5], [16, 14], [14, 8], [-2, 2], [-5, 1], [1, 14], [0, 10], [7, 0], [14, 12], [23, -6], [6, 16], [4, 16], [2, 0], [9, 14], [-2, -4], [21, -5], [-12, -4], [-6, 30], [-16, -18], [-1, 16], [25, 14], [18, -4], [26, 6], [-6, -10], [-18, 12], [-22, -20], [-22, 16], [-14, 20], [-22, -18], [12, 12], [-12, -18], [-22, -14], [-9, 10], [-20, 24], [-30, -8], [22, 2], [0, 26], [6, 14], [14, 18], [-17, -8], [0, -24], [30, 12], [20, 20], [-18, -20], [10, 12], [-2, -10], [15, 9], [50, -2], [-7, 20], [-25, -2], [-2, -24], [-38, -4], [-13, 15], [19, -11], [6, -24], [14, -4], [-6, 24], [42, -12], [-15, -15], [-9, -30], [21, -21], [14, 16], [-24, 16], [-36, -8], [7, 9], [-16, 16], [-9, -6], [26, 16], [-30, 8], [14, 28], [18, 32], [39, 0], [10, -20], [24, -18], [33, 21], [-15, 16], [22, 30], [22, 0], [-9, -9], [27, -9], [44, 0], [48, -6], [6, 8], [21, -14], [-35, -18], [23, -11], [-8, -18], [6, 14], [8, -22], [-14, 16], [21, -15], [-54, 8], [-24, 12], [-23, 4], [26, 0], [-10, 0], [-34, 16], [10, -28], [18, 0], [52, 12], [-51, 0], [34, 8], [0, -44], [32, 2], [4, -16], [-30, 28], [-22, -16], [-26, -14], [14, 0], [-32, 2], [-14, -8], [24, -22], [-11, -5], [-1, -4], [11, -15], [18, 20], [-5, -11], [-10, 28], [-35, 4], [-10, 30], [-18, -32], [5, 23], [24, 0], [20, -6], [27, -14], [-12, -42], [-2, 0], [-3, -31], [17, 4], [-26, -16], [28, -14], [-7, -16], [34, -22], [42, 2], [19, 14], [-6, 14], [13, 11], [-14, 20], [-7, -17], [38, 0], [-16, 0], [-20, 20], [43, -2], [-33, -9], [-22, -12], [37, 23], [22, 14], [-27, -33], [12, 6], [-6, -20], [4, -40], [12, 36], [-44, -16], [14, 2], [-45, 0], [-28, 34], [-18, 0], [4, 18], [10, 16], [-9, -35], [-29, 24], [31, -36], [12, 0], [-56, -18], [34, -4], [8, 38], [-10, 32], [-10, 32], [38, 6], [31, 31], [32, -20], [23, 41], [-1, 30], [-16, -4], [-32, 16], [-10, 30], [-15, -18], [-14, -20], [24, -18], [-49, 11], [-20, -34], [-45, -24], [2, 20], [38, 16], [-38, 4], [53, -4], [11, -15], [36, 8], [36, 16], [43, 7], [42, 12], [-46, 16], [30, 0], [10, -16], [12, 42], [-45, 8], [15, 27], [26, 34], [8, -50], [17, -22], [20, -18], [-23, 35], [-53, 9], [22, 14], [-17, -37], [-2, -18], [16, -4], [-28, 20], [-4, 26], [-5, 8], [-14, 44], [-24, 42], [-6, 32], [-22, -48], [-60, 20], [-22, 40], [-35, 20], [-30, -22], [-2, -36], [-19, -18], [36, -22], [2, 22], [-15, -20], [42, -12], [26, -26], [34, 12], [-7, 61], [-14, 32], [-46, -16], [26, 8], [13, -3], [13, -47], [22, 8], [-66, -4], [21, 30], [29, -14], [10, -4], [2, -2], [15, -24], [-21, -16], [48, -20], [-31, -29], [-10, -40], [-39, 3], [-11, -22], [14, -16], [6, 0], [-65, -10], [10, 8], [-57, -24], [14, 2], [-9, -27], [-37, 18], [-2, 8], [-51, -1], [-3, -17], [-31, -10], [-63, 17], [-8, -32], [7, -34], [-66, -4], [-43, 35], [-50, -20], [-20, -4], [-48, -16], [39, 33], [16, -22], [43, -35], [59, 23], [-12, 6], [-1, 38], [10, -28], [6, 24], [90, 0], [30, -14], [42, -12], [30, -42], [-6, -12], [-54, 18], [64, 22], [19, -21], [3, -26], [-19, -21], [-54, -16], [-6, -6], [-60, -6], [-49, -27], [-45, -35], [-86, 0], [-22, -2], [-15, 25], [-50, -28], [12, -10], [-34, 12], [-25, -15], [-41, -26], [74, -8], [-27, -40], [67, -24], [36, -26], [-29, -53], [36, -16], [-4, -2], [-2, -2], [-2, -20], [-15, -30], [-64, 14], [64, 2], [-70, 20], [57, -4], [18, 4], [-18, 36], [26, 30], [-22, 16], [-8, -32], [32, 34], [15, 46], [-33, -43], [24, 24], [-44, -20], [6, 14], [8, 16], [49, -26], [-21, -38], [-18, 8], [-15, -40], [26, -26], [25, -5]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2775_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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