
// Make newform 96.4.d.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_96_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_96_d_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_96_4_d_a();".
// 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_96_4_d_a();".
// 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 := [64, 0, 4, -12, 1, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [-1, 12, 3, 0, -1, 0], [-96, 24, 6, 9, -6, -3], [96, -184, 90, -17, 6, -5], [-672, -56, 90, 111, 6, -5], [8, -36, 18, -3, 6, -3]];
    Rf_basisdens := [1, 1, 32, 32, 32, 2];
    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_96_d();"
function MakeCharacter_96_d()
    N := 96;
    order := 2;
    char_gens := [31, 37, 65];
    v := [2, 1, 2];
    // 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_96_d_Hecke();"
function MakeCharacter_96_d_Hecke(Kf)
    N := 96;
    order := 2;
    char_gens := [31, 37, 65];
    char_values := [[1, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 4;
    raw_aps := [[0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, -1, 1, 0, 0], [-5, 1, 0, 0, 0, 0], [0, 0, 0, 2, -2, 0], [0, 0, 6, 3, -1, 0], [8, 2, 0, 0, 0, -2], [0, 0, 4, 6, 2, 0], [-54, -2, 0, 0, 0, 0], [0, 0, 19, -5, 2, 0], [105, 3, 0, 0, 0, 4], [0, 0, -32, -3, 11, 0], [44, -14, 0, 0, 0, -2], [0, 0, 28, -18, 10, 0], [70, -6, 0, 0, 0, -4], [0, 0, -123, -11, -10, 0], [0, 0, -20, 8, 8, 0], [0, 0, 172, 3, 9, 0], [0, 0, -68, 48, 0, 0], [282, 6, 0, 0, 0, -12], [154, 16, 0, 0, 0, -8], [5, 7, 0, 0, 0, -4], [0, 0, 128, 14, 2, 0], [-38, 4, 0, 0, 0, -4], [-406, -4, 0, 0, 0, -12], [0, 0, -307, 37, 30, 0], [225, -13, 0, 0, 0, -32], [0, 0, -84, 20, -20, 0], [0, 0, 290, -33, 7, 0], [862, -12, 0, 0, 0, -4], [-65, -59, 0, 0, 0, -12], [0, 0, -268, -40, 8, 0], [8, 78, 0, 0, 0, 34], [0, 0, -244, -72, 56, 0], [0, 0, -333, -83, 32, 0], [-733, -7, 0, 0, 0, -16], [0, 0, 360, -33, -79, 0], [0, 0, -340, -78, -74, 0], [1540, 44, 0, 0, 0, -16], [0, 0, 405, 43, 32, 0], [0, 0, 332, 32, -16, 0], [0, 0, -250, 165, 109, 0], [-1672, 160, 0, 0, 0, 4], [-1478, 64, 0, 0, 0, 40], [0, 0, -215, 157, -182, 0], [-2399, -29, 0, 0, 0, 72], [0, 0, 1212, -48, 64, 0], [3175, -3, 0, 0, 0, 36], [0, 0, -792, 290, 78, 0], [0, 0, 730, -207, 13, 0], [-446, -140, 0, 0, 0, -100], [-1732, -180, 0, 0, 0, -44], [854, 36, 0, 0, 0, 84], [0, 0, 128, -310, -74, 0], [-2054, 72, 0, 0, 0, -40], [2508, 44, 0, 0, 0, 156], [0, 0, -1229, -437, 50, 0], [1343, 53, 0, 0, 0, 140], [0, 0, 702, 321, -71, 0], [3158, -72, 0, 0, 0, 88], [0, 0, 612, -192, 256, 0], [0, 0, 757, -131, 254, 0], [0, 0, 1404, 144, -96, 0], [6048, -152, 0, 0, 0, -36], [-2658, 0, 0, 0, 0, 56], [0, 0, -613, 487, 78, 0], [0, 0, -116, -36, -92, 0], [-3362, 128, 0, 0, 0, -104], [0, 0, 808, 890, -138, 0], [0, 0, -1468, -297, -67, 0], [2918, 252, 0, 0, 0, 148], [6490, -26, 0, 0, 0, -124], [593, -37, 0, 0, 0, -172], [0, 0, 556, 333, -113, 0], [0, 0, 820, -534, -82, 0], [-6424, 48, 0, 0, 0, 4], [0, 0, 1663, 409, 136, 0], [0, 0, -1300, 471, -299, 0], [-3188, -186, 0, 0, 0, 122], [3782, -484, 0, 0, 0, -204], [0, 0, -1384, -958, 238, 0], [0, 0, 1590, -543, 289, 0], [-3630, -66, 0, 0, 0, -276], [-2874, -456, 0, 0, 0, 56], [-7243, -145, 0, 0, 0, 32], [0, 0, 1832, -310, 262, 0], [-1848, -510, 0, 0, 0, 30], [3726, -252, 0, 0, 0, -244], [0, 0, -279, -425, 224, 0], [3787, -359, 0, 0, 0, 60], [0, 0, 3304, 26, -42, 0], [1578, -274, 0, 0, 0, 312], [1111, 69, 0, 0, 0, -312], [0, 0, -3964, 212, 188, 0], [0, 0, 2020, -240, -144, 0], [-3822, -498, 0, 0, 0, 132], [0, 0, 1251, -209, -34, 0], [-9684, -150, 0, 0, 0, -234], [0, 0, 564, 378, 510, 0], [0, 0, 1930, 555, -13, 0], [0, 0, -996, 174, -310, 0], [0, 0, 3117, 1087, -268, 0], [0, 0, 2328, -610, -542, 0], [5996, 306, 0, 0, 0, 94], [0, 0, 1508, 1620, -292, 0], [2118, -464, 0, 0, 0, 56], [0, 0, 2516, -508, -244, 0], [-66, 276, 0, 0, 0, -420], [-8346, 514, 0, 0, 0, -24], [1818, 456, 0, 0, 0, 368], [-8233, 445, 0, 0, 0, 188], [0, 0, -3124, 957, -833, 0], [-11178, -376, 0, 0, 0, 72], [0, 0, -4636, 312, 168, 0], [6271, 445, 0, 0, 0, 456], [-15152, 338, 0, 0, 0, 62], [0, 0, -3876, -1146, 274, 0], [5442, -282, 0, 0, 0, -96], [0, 0, 3717, -209, -52, 0], [0, 0, 1716, 596, 508, 0], [0, 0, 648, -1455, 815, 0], [6558, -240, 0, 0, 0, 128], [0, 0, -4409, -275, -340, 0], [0, 0, -2432, -154, -214, 0], [0, 0, 2076, -222, 230, 0], [0, 0, 695, -989, -714, 0], [0, 0, -6198, 501, 313, 0], [3766, 946, 0, 0, 0, 8], [5927, -955, 0, 0, 0, -304], [0, 0, 2934, 255, 179, 0], [0, 0, 2084, -132, -812, 0], [-6440, 8, 0, 0, 0, 224], [-13455, -117, 0, 0, 0, 316], [0, 0, -4590, -1251, 9, 0], [9432, -490, 0, 0, 0, -54], [-10174, -40, 0, 0, 0, -144], [0, 0, 489, -587, 978, 0], [0, 0, -188, -1230, -378, 0], [0, 0, 3337, -509, 1300, 0], [-12288, 1302, 0, 0, 0, -6], [0, 0, -2956, 318, 490, 0], [0, 0, 1389, 673, -990, 0], [4707, 729, 0, 0, 0, -944], [0, 0, -148, 356, 796, 0], [0, 0, -1438, 903, -1313, 0], [-27762, -286, 0, 0, 0, 276], [0, 0, 3472, -1923, -1125, 0], [21524, 522, 0, 0, 0, -26], [0, 0, 2076, 690, -458, 0], [20448, 72, 0, 0, 0, 396], [0, 0, 1372, -2205, -1223, 0], [26146, 64, 0, 0, 0, -160], [0, 0, -6100, 714, 94, 0], [-2452, -756, 0, 0, 0, 28], [0, 0, 5676, -1878, -130, 0], [17524, -300, 0, 0, 0, -700], [9395, -871, 0, 0, 0, -280], [268, -1786, 0, 0, 0, -742], [12966, -1200, 0, 0, 0, -16], [0, 0, -11223, -569, 752, 0], [0, 0, -9060, -1312, 880, 0], [20988, 138, 0, 0, 0, 630], [18993, -1197, 0, 0, 0, 88], [0, 0, 6960, -682, 346, 0], [18684, -346, 0, 0, 0, 378], [-36564, -244, 0, 0, 0, -516], [-11367, 243, 0, 0, 0, 676], [0, 0, 412, -2211, 15, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_96_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_96_4_d_a();".
// 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_96_4_d_a(:prec:=6)
    chi := MakeCharacter_96_d();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_96_4_d_a();".
// 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_96_4_d_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_96_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;