
// Make newform 1932.2.a.d in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1932_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_1932_2_a_d();".
// 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_1932_2_a_d();".
// 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, -1, 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_1932_a();"
function MakeCharacter_1932_a()
    N := 1932;
    order := 1;
    char_gens := [967, 1289, 829, 925];
    v := [1, 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_1932_a_Hecke(Kf)
    return MakeCharacter_1932_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 := [[0, 0], [-1, 0], [0, 1], [-1, 0], [-1, -2], [1, 1], [-1, 2], [1, -4], [1, 0], [3, -4], [-3, -2], [-3, 4], [5, -4], [-7, 9], [-2, -2], [-4, 5], [-4, -1], [1, -7], [-4, -1], [-9, 3], [-3, -8], [-7, 2], [-3, 8], [-1, 3], [1, 2], [-2, -1], [-4, 8], [-11, -1], [-6, 1], [2, -9], [-9, -3], [5, 8], [1, 2], [-4, 13], [6, -14], [-6, -6], [-16, 2], [-2, -9], [-5, 16], [15, -8], [4, 11], [-3, 2], [10, -18], [-8, -6], [-7, -1], [-10, -7], [-1, 2], [12, -23], [-2, -5], [14, -1], [-6, 5], [-14, 13], [-21, 6], [16, -10], [22, -6], [-3, 8], [15, 5], [-1, 20], [7, 1], [0, 14], [-16, 5], [12, 8], [7, 2], [-3, 21], [4, -4], [26, -13], [6, 8], [-9, 9], [13, -10], [20, -5], [13, 8], [4, -7], [-5, 11], [21, -8], [12, -24], [3, 4], [7, 12], [22, -10], [1, 20], [-3, 2], [26, -23], [7, -17], [-17, 9], [-20, 6], [13, 10], [-4, 16], [6, -5], [-2, 3], [10, -9], [-27, 16], [7, -12], [1, -10], [23, 4], [1, 3], [8, 15], [-10, -9], [6, 6], [6, -4], [-10, 12], [-6, -6], [0, -5], [-4, -14], [-27, 17], [24, -4], [7, 6], [-26, 8], [-9, 13], [4, 2], [17, -33], [18, -27], [19, -35], [-19, -2], [-19, -5], [-1, -13], [-7, 4], [-33, 3], [7, -21], [-34, -5], [-2, 13], [-25, 26], [-15, -10], [-27, 12], [-9, 21], [-17, -2], [-3, -9], [-32, 23], [-1, -15], [-3, -2], [43, -4], [-28, 22], [11, -22], [-36, -11], [-30, 13], [35, 0], [-4, -24], [24, -10], [9, 4], [-2, 25], [10, -30], [17, 1], [13, 12], [30, -18], [40, -15], [-18, 9], [-9, 18], [-17, 29], [-20, 14], [12, 18], [-10, 8], [-8, -18], [-20, 44], [-32, 6], [-21, 19], [-15, 9], [26, 13], [14, -30], [1, 12], [-20, 17], [29, -4], [28, 0], [34, 16], [-19, -9], [14, -4], [-25, 7], [-49, -5], [3, -32], [9, 31], [-1, 18], [-10, -5], [-9, 5], [25, 9], [2, 20], [-29, 5], [23, -40], [4, 16], [-23, 48], [5, -25], [-30, -5], [10, 15], [2, -9], [20, -29], [11, -39], [-16, -11], [-7, -17], [13, -38], [25, -3], [2, 12], [-47, -2], [-36, -7], [-11, 16], [-36, 15], [-42, -7], [28, -38], [31, -36], [-5, 13], [-45, 7], [-31, -9], [-8, 14], [18, -32], [38, -13], [-2, 4], [-16, -24], [44, -27], [1, -35], [-7, 14], [22, 0], [35, 18], [-14, 25], [30, 13], [-45, 12], [22, -38], [-12, 31], [-13, -6], [-36, 32], [27, -17], [-22, 7], [51, 10], [19, 3], [-31, 0], [-27, 46], [-3, -35], [22, 4], [31, -55], [-20, 20], [23, 6], [42, 13], [-33, 8], [-44, 20], [11, -21], [43, 14], [-7, 12], [-15, 1], [44, -13], [0, -40], [-9, 37], [23, -25], [-14, -30], [-3, 42], [15, -22], [-43, 40], [-9, -14], [-8, -31], [4, -38], [-15, 10], [-29, 16], [69, -11], [20, -28], [32, 0], [-5, -16], [-29, -24], [17, -28], [-38, -16], [-11, 50], [19, 24], [23, -18], [44, -26], [-21, -24], [-29, 12], [57, -7], [17, -22], [41, -5], [26, -36], [28, 23], [9, -16], [41, -39], [-13, 6], [-2, 0], [-7, -16], [35, 10], [34, -39], [15, -6], [55, 4], [-25, -1], [-2, -14], [35, 26], [-26, 44], [5, 18], [-7, 10], [-43, 36], [43, -20], [-10, 14], [59, -27], [47, 12], [3, -6], [-22, 31], [-11, -34], [-3, 8], [2, 0], [61, 11], [12, 36], [-17, -27], [23, -15], [-9, -31], [-33, 14], [44, -36], [29, 12], [-24, 8], [31, -3], [-11, -38], [31, -14], [-15, -13], [10, 4], [51, -10], [34, -25], [36, 4], [27, -38], [6, -47], [35, -56], [-40, -26], [13, -17], [35, 22], [11, -18], [-34, 51], [27, -16], [17, 16], [-56, 44], [19, -26], [17, -10], [-11, -8], [-42, 2], [-2, 16], [-61, 29], [-12, -13], [29, -68], [-23, 4], [-30, 61], [-31, 6], [-22, -43], [-42, 18], [4, -18], [-68, 32], [-49, 62], [-17, 3], [18, 31], [2, -58], [-58, -4], [-28, -2], [-42, -18], [-16, 53], [40, -13], [37, 24], [26, 16], [21, -5], [39, -28], [-10, -44], [47, -55], [44, -39], [6, -31], [-40, 17], [-79, -6], [-3, 23], [1, 12], [-53, 26], [-34, 53], [-41, -22], [24, 20], [36, 6], [-65, -6], [-55, -12], [57, -2], [51, -10], [13, -16], [-41, -14], [20, 40], [22, 2], [-36, 12], [-35, 49], [-10, 50], [27, -19], [-17, 31], [-69, 6], [-80, -8], [64, 18], [40, -8], [-19, -28], [-56, 65], [-38, -7], [-74, -2], [-18, -12], [3, 22], [-27, -14], [-39, 3], [2, 30], [-5, -47], [-26, -25], [59, 15], [-17, 49], [22, -40], [-59, 4], [-12, -26], [13, 26], [-4, -1], [-10, 36], [-58, -18], [25, 31], [22, 33], [-31, -8], [-1, 30], [-27, 27], [-35, 38], [5, -2], [7, -39], [20, -42], [-43, 45], [55, -45], [-5, -49], [-24, -36], [64, 14], [-72, 16], [-20, 1], [17, -39], [-6, 42], [-72, 16], [-55, -1], [-13, 19], [-18, 4], [-37, 28], [5, -6], [-81, 8], [14, 34], [-43, -6], [-61, 10], [-2, 5], [37, -55], [35, -5], [34, -54], [47, -53], [-36, 50], [-44, -23], [25, 5]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1932_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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