
// Make newform 3610.2.a.x in Magma, downloaded from the LMFDB on 04 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3610_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_3610_2_a_x();".
// 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_3610_2_a_x();".
// 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, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, 0, 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_3610_a();"
function MakeCharacter_3610_a()
    N := 3610;
    order := 1;
    char_gens := [2167, 3251];
    v := [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_3610_a_Hecke(Kf)
    return MakeCharacter_3610_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, 0], [0, 1, 0], [1, 0, 0], [0, 0, -2], [-4, -1, 1], [-2, -2, 0], [-1, 0, 2], [0, 0, 0], [-4, -2, 0], [-2, 0, 4], [-4, -4, 2], [-4, 0, 0], [0, 4, -5], [1, 2, 4], [-4, 2, 4], [-2, 0, -2], [8, -1, 1], [-6, 0, -2], [2, 8, -7], [4, -4, 6], [-2, 3, -1], [2, 2, -4], [-2, 8, -9], [-1, 8, -8], [-4, -6, 3], [-12, 2, 2], [10, -4, 10], [-1, -2, 0], [2, -6, -6], [6, -1, -1], [-4, -2, -2], [-2, 5, 0], [-10, 1, 0], [-2, -6, -1], [0, 4, -8], [-4, 4, -2], [10, 0, 2], [4, 1, 0], [-2, 8, 6], [-12, 0, -6], [6, -2, 1], [-4, 12, -6], [2, 4, 6], [15, 0, -2], [2, -6, 8], [-4, -14, 4], [11, 6, -6], [2, 4, -8], [6, 4, 7], [-14, 4, -6], [-2, -13, 0], [-10, -2, 0], [-4, 9, 0], [6, 13, -8], [-14, 7, -4], [-4, 6, 2], [-6, -4, 2], [-10, 0, -6], [-16, -4, -4], [-4, -17, 12], [2, -13, 11], [8, -8, 18], [2, -1, -1], [-6, -4, 2], [-10, -19, 8], [-16, 0, 8], [-4, -3, 3], [-22, 7, 4], [6, -12, 3], [-4, -20, 16], [12, -6, -3], [-14, -10, 6], [-2, -6, 2], [20, -2, 4], [-16, 8, -16], [14, -12, -4], [-24, 4, -8], [14, 2, 2], [-12, 3, 9], [20, 3, -3], [-21, 6, -6], [-4, 6, 0], [2, 0, 8], [-2, -16, 16], [-2, -12, 20], [24, 5, -4], [20, 17, -8], [12, -6, -5], [16, -4, 12], [2, 20, -16], [-14, -8, 5], [0, -10, 8], [-4, -4, -4], [5, 10, -6], [-8, 3, -7], [16, 10, -4], [22, -4, 6], [-12, 1, -20], [0, -12, -8], [-6, -6, -2], [5, 2, -16], [-10, -2, -12], [18, 1, -11], [-11, -4, 12], [18, 5, 0], [14, 7, -5], [-3, -2, -20], [-2, 3, 7], [12, -18, 18], [-20, -11, 3], [4, 16, -18], [26, -10, -4], [-18, 11, -13], [-15, 6, -14], [10, -10, 22], [-8, -16, 15], [0, -23, 20], [16, -20, -4], [-14, -12, 16], [33, 6, -6], [8, -14, -2], [-5, 16, -18], [0, -6, 18], [-7, -22, 4], [-1, 22, -14], [16, 18, -20], [-6, -14, 8], [-22, 0, -4], [8, 4, 10], [-16, -26, 22], [6, -6, 31], [-2, 26, -6], [-10, 16, 4], [-6, -12, 22], [0, -11, 16], [1, 8, 4], [-2, 14, 12], [30, 7, -13], [-10, -22, 16], [-4, 23, -23], [-4, -12, 12], [28, -8, 26], [26, -2, -14], [2, -9, -1], [10, 8, -2], [-16, -8, 0], [32, -2, 10], [-30, 9, -12], [20, -19, -1], [2, 8, -8], [-12, 26, 12], [-4, -4, -23], [6, 4, -7], [12, 16, -8], [-10, 7, 19], [-4, -24, -4], [14, -8, -2], [-12, -1, 5], [30, 3, 4], [4, 8, -12], [-20, 16, 8], [-18, -11, 25], [-20, 0, 14], [-14, 21, -20], [6, 17, -4], [2, 16, -6], [-12, -28, 30], [30, -12, -14], [-22, -20, 16], [-22, 16, -24], [-10, 1, -12], [-14, -14, 0], [-18, -8, 10], [30, 3, 4], [14, -14, -2], [8, 29, -17], [-4, -25, 5], [-18, 2, -16], [10, -20, 6], [-16, 18, 6], [2, -24, 6], [15, 14, -10], [-34, 6, -12], [-6, 3, 15], [16, 36, -26], [-18, -28, 14], [-16, 22, 10], [7, 14, 4], [-4, 16, 7], [16, 2, -12], [0, 10, 17], [-32, 8, -24], [6, -1, 24], [16, 30, -20], [-4, 29, 4], [13, -28, 18], [-4, 12, 21], [40, -4, -8], [-34, 15, -1], [-2, -4, 24], [-34, -2, 6], [-10, 22, -8], [2, 6, 6], [20, -17, 4], [-22, -34, 25], [4, -2, 20], [-28, 10, 10], [-24, 11, -16], [-4, 4, 9], [40, -11, 27], [4, 18, -13], [-26, -10, 18], [-22, 16, -20], [14, 0, -19], [-14, -8, -16], [-23, 8, 16], [-22, 2, -4], [-11, 0, -8], [14, -24, 32], [6, -4, -28], [12, 6, -26], [-34, 20, 8], [4, -9, 1], [24, 10, 8], [-2, -32, 35], [-22, -14, -8], [-4, -14, -3], [-30, 10, -32], [-16, 10, 22], [-36, 8, -28], [-6, 10, 2], [36, 9, -17], [14, -10, -10], [-12, 19, 16], [2, 21, -15], [16, 20, 0], [-20, 8, -17], [16, -24, 4], [-38, 2, -3], [8, -20, -6], [20, -9, 20], [14, 49, -20], [-24, 16, -22], [-10, 26, -46], [9, 40, -38], [-24, 16, -14], [20, -14, 34], [-10, -26, -3], [14, -19, -16], [28, 32, -12], [0, 2, -12], [23, -20, -12], [10, -12, 16], [20, -11, -5], [-16, -26, 12], [5, -18, 2], [12, -12, -8], [-30, -28, 15], [-28, 14, -20], [3, -24, -2], [0, -4, 6], [38, -3, -7], [34, -18, 20], [12, -28, 54], [8, 10, -9], [30, 11, -24], [12, 4, -2], [-12, 7, 28], [33, 2, 12], [-44, -8, -4], [24, -16, 6], [-1, -2, -20], [-4, -6, 9], [8, -2, 10], [1, -4, -2], [36, 10, 2], [-4, 17, 4], [-2, -24, 14], [-20, 17, -5], [-28, 12, -28], [42, -8, 4], [-28, -2, 22], [12, 36, -18], [2, -18, 0], [23, -18, 0], [-54, -6, 12], [-10, 21, -15], [-22, 10, 12], [-10, 6, -36], [-21, 4, -20], [-34, -8, -6], [9, 38, -40], [-44, -26, 17], [23, -2, -18], [-14, 0, -40], [-20, -20, -10], [-10, 18, 18], [-22, 2, 22], [-29, 6, -26], [-2, -8, 9], [-10, -7, -16], [-4, -2, 18], [-14, -54, 38], [10, 24, -5], [-26, -38, 15], [14, 21, -12], [6, 21, 9], [0, 20, 24], [-4, 10, -24], [10, 12, -22], [-14, -8, -4], [16, -26, 20], [-20, -13, 21], [30, -20, 23], [-16, 38, -44], [35, -4, -28], [10, -6, -35], [-14, -14, -10], [20, 6, -39], [-13, -40, 40], [26, 14, 5], [38, -11, -20], [-2, -4, 12], [8, 28, -32], [-25, 20, -38], [10, -4, 28], [58, -6, 17], [16, -3, 8], [10, -4, -24], [-16, -50, 48], [-32, 26, -8], [36, 0, -18], [20, -2, -14], [-44, 16, -4], [-34, 22, 13], [-21, -18, 0], [12, -22, 24], [-2, 15, 31], [7, -32, 36], [-6, -38, 32], [14, -38, -2], [6, 49, -35], [12, 42, -6], [-58, 0, 12], [-8, 20, -36], [-10, 6, 5], [-34, -12, -18], [-31, -22, -16], [-56, 20, 0], [-20, -20, -16], [-54, -9, 16], [10, -7, 13], [-18, 52, 4], [2, -6, 0], [8, 24, 18], [-2, 3, -5], [-8, -18, -20], [8, 9, 35], [-32, -46, 27], [16, -14, 14], [-46, 24, -18], [24, 15, 12], [46, 2, -18], [-10, 1, 0], [-31, 6, -24], [-19, -32, 34], [14, -14, -6], [58, 16, -6], [-8, 48, -25], [-8, -45, 49], [0, 20, -24], [10, 54, -20], [-54, 10, -8], [-10, 34, 28], [12, -8, 2], [-7, -2, 6], [22, -44, -22], [-4, -30, 33], [20, 27, -43], [-6, 29, -51], [28, 18, -20], [-21, 4, 10], [-16, -20, 4], [-8, -22, 9], [52, 3, 5], [-10, -44, 18], [-38, 32, -44], [-22, 18, -6], [32, -23, 28], [-30, 0, -12], [8, 29, -1], [0, 2, 32], [26, -10, 55], [-14, 7, 27], [-32, 26, -36], [8, -2, 43], [-8, 46, -42], [16, -16, -33], [44, -21, 33], [42, 2, -4], [-6, 26, 30], [-16, -14, -21], [2, -42, 42], [15, -12, 42], [10, -18, 16], [-6, 0, -56], [18, -30, 46], [-32, -1, 21], [5, -38, 28], [-14, 2, 33], [50, -9, -21], [34, -34, 54], [2, 24, -1], [10, -3, -40], [-16, -14, 1], [6, 12, -18], [-28, 20, -14], [-34, 30, -42], [42, 64, -44], [-44, 20, -60], [0, 20, -58], [-50, -10, 4], [-32, -12, 22], [30, -15, 24], [30, -8, -16], [6, 30, -6], [-10, -12, 17], [10, 16, 20], [29, -14, 10], [26, 8, 16]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3610_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3610_2_a_x();".
// 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_3610_2_a_x(:prec:=3)
    chi := MakeCharacter_3610_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_3610_2_a_x();".
// 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_3610_2_a_x( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3610_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-1, -3, 0, 1]>,<7,R![-8, -12, 0, 1]>,<13,R![-8, 0, 6, 1]>],Snew);
    return Vf;
end function;