
// Make newform 1734.2.a.q in Magma, downloaded from the LMFDB on 11 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1734_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_1734_2_a_q();".
// 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_1734_2_a_q();".
// 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_1734_a();"
function MakeCharacter_1734_a()
    N := 1734;
    order := 1;
    char_gens := [1157, 1159];
    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_1734_a_Hecke(Kf)
    return MakeCharacter_1734_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], [1, 0, 0], [2, -1, 0], [1, 2, -2], [2, 3, -1], [2, -2, 0], [0, 0, 0], [-2, 2, 2], [6, 0, 0], [0, 2, -5], [-2, -2, -1], [2, -4, 6], [2, -6, 4], [2, -4, 8], [0, -2, 6], [2, -1, 3], [4, -1, 0], [-10, -2, 2], [4, -2, -4], [-2, 6, 4], [-8, 0, -3], [0, 5, 3], [-5, -2, -4], [8, -2, 8], [-4, 3, -7], [-2, -1, 4], [-2, 10, 1], [2, 4, 3], [-6, -2, 2], [6, -4, -2], [-5, 2, -2], [1, -2, -8], [0, -2, -2], [-8, -8, 4], [14, 1, -3], [16, 3, 1], [4, 4, -4], [-8, -2, -4], [0, 8, -6], [-2, -1, -1], [11, -2, 0], [-6, 8, -6], [2, -8, 4], [4, -5, -4], [7, 8, -10], [2, -7, 12], [4, 10, -8], [-8, 9, -13], [-3, 2, 0], [14, 4, 2], [4, -4, 6], [18, 4, 0], [-4, 13, 0], [-6, 8, -1], [0, 0, -12], [-4, -6, 8], [-2, 1, -7], [-14, -6, 5], [0, 12, -14], [6, -8, 10], [-8, 6, 0], [-6, 3, 4], [-6, -4, 8], [2, 8, -8], [6, 0, -8], [-17, 0, -6], [-2, -4, -2], [-9, 12, -24], [-16, -7, 12], [-2, -10, -6], [-16, -4, -4], [-2, -4, -6], [2, -11, 16], [-2, -16, 14], [14, -6, -2], [-10, -16, 6], [4, 10, -17], [-4, -6, -2], [-2, -4, -6], [4, -11, 7], [-12, -7, 8], [-4, -14, 2], [2, -14, 8], [-20, 5, 0], [16, -8, 4], [-19, 10, 0], [0, 16, 2], [-4, 8, -15], [-4, 10, 7], [-22, -11, 4], [10, 0, 7], [-6, -12, -2], [2, 7, 4], [-4, -5, -4], [-4, 6, 10], [-14, 2, -2], [24, 18, -11], [-4, -4, -18], [-12, 16, 0], [-26, 10, -10], [-4, 10, -8], [11, -4, 14], [-22, 4, -11], [-8, 10, -22], [2, 8, -18], [7, 16, -4], [-8, -9, 4], [-12, -20, 22], [-2, 14, -14], [-20, -4, 7], [10, -14, 3], [-4, 4, -12], [-8, -30, 10], [6, 6, -14], [14, 2, -1], [-10, 12, -12], [0, -6, 4], [-6, 10, -12], [-22, 0, 4], [2, 25, -15], [10, 14, -16], [22, 4, 12], [-3, 28, -6], [8, -13, 16], [12, -6, -2], [38, -9, -1], [12, 14, -2], [2, 10, -6], [6, 19, 0], [-2, -4, -24], [6, 2, 14], [-6, 0, -16], [6, 13, 0], [12, 16, -16], [-4, -2, 2], [8, -3, 0], [22, -5, 11], [-16, -26, 6], [27, -20, -6], [-4, 10, 4], [-2, 12, -14], [-26, -16, 12], [-4, -17, 9], [4, 11, 4], [18, -16, 20], [-10, 10, -24], [14, 8, -12], [12, 8, 10], [10, -2, 30], [18, -10, 32], [-10, -12, 2], [26, -2, -10], [2, 10, -26], [6, -12, 6], [34, -10, 18], [-18, 18, -10], [-17, 2, 14], [24, -2, -12], [-16, -9, 16], [-26, -20, 20], [-14, -25, 27], [-8, -2, -26], [-6, -31, 16], [30, 1, 5], [8, -2, 4], [4, -20, 24], [-13, -2, 2], [16, -8, 0], [-7, -12, 20], [10, -21, -5], [34, 8, 5], [-8, -2, -8], [-18, -20, 0], [-7, 28, -16], [-22, 11, -4], [26, -10, 6], [8, 8, -16], [4, 2, -3], [-21, -2, 2], [-10, -26, 22], [15, 30, -18], [-4, 19, -8], [2, 6, 22], [26, 14, -14], [-4, 14, -20], [22, 24, -16], [22, 6, -6], [4, 32, -16], [24, 11, -7], [-38, 10, 2], [14, -16, 0], [-15, -2, 24], [-8, 14, -32], [10, 29, -15], [-17, -18, 4], [4, -16, -12], [-28, 7, -19], [-18, -8, 18], [2, 4, 12], [-24, -34, 20], [-3, 20, -34], [17, -26, -2], [-10, 12, 4], [-32, -12, 19], [8, 32, -36], [-3, -28, 10], [23, -2, 22], [-26, -27, 17], [-20, -6, 0], [6, -6, 26], [8, 19, -8], [30, 21, -15], [-12, -16, 16], [-6, 31, 7], [-4, -24, 14], [4, 13, -5], [12, -33, -3], [12, -28, 2], [8, -4, -20], [-21, 24, -6], [-44, 2, -8], [-10, 10, 9], [28, 6, -18], [13, 10, -18], [-30, -5, 23], [-14, -26, 16], [-14, 26, -26], [20, -14, 38], [35, -18, -6], [2, 5, -7], [28, -14, 16], [6, -16, 18], [14, 21, -4], [-20, 12, 8], [-28, 4, -8], [56, -6, 4], [16, -4, -5], [-10, -33, 36], [-2, 0, 13], [-26, 18, 22], [6, -40, 3], [6, -24, 4], [4, 1, -9], [16, 32, -26], [42, -2, -8], [-38, 24, 6], [-18, 15, 4], [22, 20, -3], [30, 8, -18], [-42, -8, 4], [12, -12, 2], [40, 2, 2], [-10, 2, -2], [12, -5, -20], [-30, 27, 8], [-18, -39, 9], [-6, -28, 12], [-14, 24, -24], [14, 21, -19], [17, 32, -24], [-6, 29, 16], [24, 0, -8], [-24, -2, -8], [-30, -6, 16], [8, -14, 34], [-8, 30, -40], [0, -2, -9], [-14, 32, 8], [-18, 4, 14], [43, 28, -22], [-14, -18, -14], [68, -4, 12], [17, -36, -12], [-4, 36, -12], [-31, -12, -8], [12, 40, -16], [18, 52, -39], [24, -36, 2], [-12, -49, 32], [6, 21, -35], [-20, 28, 2], [18, -1, 24], [14, -14, -18], [-38, 14, 2], [-54, 0, -4], [-22, -34, 14], [-56, 3, -3], [-22, 7, -21], [34, 37, -28], [40, -18, 2], [-30, 24, 12], [-11, 34, -4], [12, -12, 40], [20, -27, 48], [16, -30, -8], [-10, -1, -32], [6, -25, 28], [-11, 16, 34], [15, -34, 32], [-14, 14, 10], [-32, 19, -23], [12, -2, 31], [-10, 2, -45], [48, 11, -12], [22, -10, 10], [-48, 15, -11], [14, 20, -7], [32, -24, 22], [44, -16, 16], [0, 14, -16], [-12, 24, -8], [34, 9, -3], [32, -6, -18], [-14, 8, -20], [-8, 4, -2], [-8, -5, 25], [5, -18, 20], [14, 18, -2], [-36, 13, 7], [-30, 32, -30], [-14, -30, -6], [-57, -4, 0], [-11, -4, -6], [23, 10, -2], [-4, -2, 36], [-12, -36, 45], [12, -44, 10], [-66, 6, -6], [-46, -12, 0], [-31, -44, 14], [18, 16, 8], [-23, 8, -22], [-16, -31, 23], [15, 42, -32], [48, -2, 20], [26, 8, -19], [36, 8, -22], [42, -22, 8], [-29, 8, 20], [30, -17, -8], [-26, 16, 4], [-56, 2, 20], [12, 30, 7], [0, -5, 13], [16, -22, -23], [-4, 24, -20], [-34, -14, -20], [-8, -22, -10], [6, -28, 6], [72, 18, -9], [22, -4, 44], [0, -40, 35], [-18, 11, -28], [38, 2, -9], [42, 10, -24], [18, -12, 6], [24, -14, 12], [42, 0, -23], [-30, 2, -16], [30, -24, 52], [-8, 12, -4], [-18, 36, -10], [-10, 52, -12], [24, 12, -32], [24, 6, 32], [-41, -8, 20], [-4, 14, -5], [30, -31, -24], [-40, 11, 8], [17, 6, -36], [8, -46, 26], [-18, 4, 24], [-14, -8, 20], [26, 15, -12], [-26, -12, -22], [-22, -7, -23], [56, -6, -4], [-60, -28, 17], [26, 20, -4], [-37, -28, 20], [34, -5, -13], [0, -30, 46], [-16, 15, 13], [-18, -42, 0], [6, 26, -48], [38, -8, -14], [50, 1, 8], [-14, 0, -6], [20, -34, 24], [60, 16, -14], [6, -20, 4], [14, 11, 7], [-30, 33, -15], [48, 28, -26], [12, 10, -38], [-28, 24, -25], [0, -1, -11], [-60, 10, -14], [14, 24, 18], [23, -20, 6], [44, 32, -36], [6, -22, -30], [-16, -33, 1], [-2, 36, -14], [-30, 16, -28], [4, -17, 53], [64, -10, 14], [-30, -4, 0], [30, -40, 22], [64, -16, 20], [-39, 16, 24], [34, -19, 12], [8, 35, -36], [26, -10, 48], [-24, 24, 19], [24, -10, 31], [-20, 4, -4], [72, -17, -7], [20, 34, -32], [38, 8, 4], [14, -19, -8], [-48, -2, -20], [16, 40, -10], [-12, 33, -44], [-40, -49, 20], [24, 38, -23], [-58, 12, 17], [-42, 26, -22], [-2, 10, -26], [-26, 30, 22]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1734_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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