
// Make newform 1035.2.a.l in Magma, downloaded from the LMFDB on 10 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1035_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_1035_2_a_l();".
// 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_1035_2_a_l();".
// 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 := [-3, 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_1035_a();"
function MakeCharacter_1035_a()
    N := 1035;
    order := 1;
    char_gens := [461, 622, 856];
    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_1035_a_Hecke( : Kf := Kf)
    return MakeCharacter_1035_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]];
    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], [0, 0], [-1, 0], [-3, 0], [1, 1], [1, 3], [4, -1], [-5, 1], [-1, 0], [2, 1], [-3, -4], [5, -4], [2, 1], [-8, -2], [1, -5], [4, 1], [-2, -3], [1, -7], [-3, -2], [2, 1], [1, -5], [0, 4], [12, 1], [-6, 2], [-4, 0], [0, -3], [2, 8], [6, -7], [5, -1], [4, -3], [7, 3], [-12, -4], [0, 12], [5, 0], [11, -3], [-8, 6], [-7, 4], [14, 0], [15, 5], [12, -8], [-8, 2], [2, 6], [5, -5], [14, -2], [12, -6], [-8, -2], [-1, -12], [2, 0], [-16, -4], [6, 10], [-12, 8], [-2, 11], [-29, 1], [-6, 8], [-3, -5], [-10, -1], [-20, 5], [-5, -6], [-6, -12], [-3, -11], [-3, 2], [6, -1], [19, -3], [12, 0], [-1, -4], [5, -13], [3, 10], [-2, 12], [10, 10], [13, -10], [-3, -1], [15, -7], [-15, 0], [22, -6], [4, 0], [18, 9], [0, 2], [4, -12], [12, 10], [-1, 6], [-13, -1], [13, -5], [6, -6], [31, 4], [-26, 0], [3, 13], [10, -11], [-17, 4], [24, -2], [9, -5], [14, 1], [9, -17], [-1, -5], [-4, -17], [25, 6], [14, 5], [28, -4], [11, -1], [-20, 0], [12, 8], [28, -4], [12, 9], [-18, -13], [0, -10], [-1, -9], [-4, 4], [-6, 8], [11, 9], [-10, 10], [-1, -2], [25, -7], [34, 8], [18, -13], [20, -12], [-5, 7], [3, -13], [-9, 20], [13, 5], [-25, -9], [-11, -3], [-8, -10], [15, -5], [0, 23], [9, 11], [-20, -10], [-7, -13], [1, 5], [0, 3], [-19, 18], [11, 22], [31, -10], [28, 0], [7, 1], [-29, -6], [12, 5], [-7, -3], [-12, 2], [-17, 0], [-4, 15], [2, 7], [3, 0], [12, -16], [-40, 4], [4, 21], [-21, 4], [2, 8], [12, -2], [-2, -4], [43, 4], [-4, -6], [24, 2], [19, -3], [-25, 11], [0, -2], [9, -18], [28, -4], [-20, 8], [-4, 15], [-12, -28], [5, 31], [-42, -6], [-26, -8], [11, 3], [-6, -2], [4, -7], [-12, -15], [-25, 0], [-54, 2], [-4, -16], [29, -9], [-60, 0], [13, 8], [-30, 16], [-3, 14], [4, 4], [3, -11], [-6, 28], [12, 27], [-13, -22], [-5, -11], [-25, -11], [-49, -7], [-8, -10], [-31, 9], [42, 3], [37, 13], [9, 3], [-5, 6], [-1, -24], [-2, 25], [13, -5], [-26, 0], [-15, 3], [28, -17], [-24, 14], [-4, 19], [-17, -15], [48, 4], [30, 0], [26, -8], [15, -27], [-12, 6], [3, -23], [25, 11], [21, 7], [-12, -2], [-19, 17], [-11, -27], [-30, -23], [32, -14], [44, 2], [32, -10], [18, -28], [-20, 2], [48, -13], [-43, 17], [28, -10], [-6, -3], [-34, 3], [-27, -7], [-5, -4], [8, -6], [0, -25], [-29, 6], [5, -31], [-43, 6], [24, 6], [14, 3], [4, 8], [48, -13], [45, -1], [13, 15], [20, -6], [10, -11], [-13, 12], [0, 26], [-21, -5], [38, -16], [36, 23], [-60, 9], [-42, 19], [-3, 4], [40, -10], [-48, -4], [-12, 20], [10, -26], [-25, 11], [-17, 11], [32, -6], [-14, -21], [-8, 0], [-2, 36], [-42, -11], [-12, -6], [17, -15], [30, 1], [-23, 21], [-4, 28], [33, -3], [38, 4], [-35, -24], [44, -3], [17, -16], [3, 10], [-6, -42], [-17, -33], [13, 19], [2, 12], [-7, 42], [-20, 32], [-31, 18], [-17, 36], [-19, 16], [6, 4], [-27, 21], [-13, -19], [15, -39], [-3, 10], [-45, -13], [3, -3], [14, 28], [37, -11], [14, 10], [-48, -8], [-27, -21], [18, -17], [-11, -2], [-6, 8], [2, -28], [-24, -6], [-40, -18], [32, 15], [-6, -14], [63, -7], [29, -19], [-12, -4], [-31, -29], [-9, 35], [-48, 9], [-10, -24], [-21, -22], [28, -5], [-2, 18], [33, 7], [-20, -16], [-1, 27], [21, 21], [-10, 8], [3, -43], [-27, -19], [36, 16], [21, 9], [15, 25], [-28, -28], [-76, -1], [-59, 9], [60, -13], [-6, 19], [27, 0], [-48, 4], [29, 25], [-13, -8], [10, 24], [22, 12], [0, -39], [-5, 11], [-7, 17], [-5, 17], [48, 20], [-14, -29], [45, 10], [-41, 7], [-73, 0], [41, -3], [56, -8], [32, 32], [-52, 6], [-40, -26], [32, 0], [-33, 20], [-32, -6], [14, 0], [-12, -38], [27, -25], [34, 1], [54, -3], [-13, 12], [-17, -39], [-6, 20], [20, -11], [51, 20], [-33, -5], [-10, 11], [-53, 2], [33, 5], [42, -8], [41, -3], [-6, 12], [33, 25], [-20, -6], [31, 10], [22, 29], [-12, -38], [34, -14], [-4, 6], [28, -6], [-69, 1], [-9, -4], [8, -4], [0, -23], [39, -6], [46, -8], [-6, 54], [48, 12], [55, 9], [-20, 11], [-12, -22], [-13, 32], [-18, -10], [-8, 14], [20, 22], [-36, -22], [28, 24], [-19, -15], [-54, -2], [-26, 16], [-7, -14], [-1, -13], [27, -18], [54, -1], [-21, -19], [16, -42], [-2, -19], [-61, -17], [37, 13], [35, -8], [56, 18], [-66, 6], [-44, -24], [6, -19], [-41, 16], [18, -4], [-53, -24], [44, 9], [-70, -5], [-17, -28], [-31, -26], [-28, 10], [0, -38], [-36, 0], [15, -13], [-51, -11], [-32, -12], [66, 2], [-55, -12], [-2, 32], [62, 2], [-11, -15], [30, -35], [38, 18], [-43, -15], [-92, -4], [63, 15], [28, 36], [-13, -49], [-56, 12], [-46, 18], [72, -7], [-10, -8], [46, 27]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1035_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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