
// Make newform 288.4.d.d in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_288_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_288_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_288_4_d_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_288_4_d_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 := [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, -104, 42, -13, 6, -1], [288, 40, -42, -51, -6, 1], [96, -24, -6, -9, 6, 3], [7, -24, 21, -3, 5, -3]];
    Rf_basisdens := [1, 1, 16, 16, 8, 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_288_d();"
function MakeCharacter_288_d()
    N := 288;
    order := 2;
    char_gens := [127, 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_288_d_Hecke();"
function MakeCharacter_288_d_Hecke(Kf)
    N := 288;
    order := 2;
    char_gens := [127, 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, 0, 0, 0, 0], [0, 0, -1, 0, 0, 0], [-5, -1, 0, 0, 0, 0], [0, 0, -2, -2, 0, 0], [0, 0, 3, 1, -2, 0], [-8, 3, 0, 0, 0, 1], [0, 0, 6, -2, -3, 0], [54, -2, 0, 0, 0, 0], [0, 0, 5, 2, 4, 0], [105, -1, 0, 0, 0, 2], [0, 0, -3, -11, 6, 0], [-44, -13, 0, 0, 0, 1], [0, 0, -18, -10, -5, 0], [-70, -4, 0, 0, 0, 2], [0, 0, 11, -10, -36, 0], [0, 0, -8, 8, -1, 0], [0, 0, 3, -9, -46, 0], [0, 0, 48, 0, 5, 0], [-282, 12, 0, 0, 0, 6], [154, -20, 0, 0, 0, -4], [5, -9, 0, 0, 0, -2], [0, 0, -14, 2, 36, 0], [38, 6, 0, 0, 0, 2], [-406, -2, 0, 0, 0, -6], [0, 0, -37, 30, -60, 0], [225, -3, 0, 0, 0, -16], [0, 0, -20, -20, -21, 0], [0, 0, -33, -7, -66, 0], [-862, -10, 0, 0, 0, 2], [-65, 53, 0, 0, 0, -6], [0, 0, 40, 8, -75, 0], [-8, 61, 0, 0, 0, -17], [0, 0, -72, -56, 65, 0], [0, 0, 83, 32, -96, 0], [-733, -1, 0, 0, 0, -8], [0, 0, -33, 79, -62, 0], [0, 0, -78, 74, 123, 0], [-1540, 52, 0, 0, 0, 8], [0, 0, -43, 32, 120, 0], [0, 0, -32, -16, 87, 0], [0, 0, 165, -109, -6, 0], [1672, 158, 0, 0, 0, -2], [-1478, -44, 0, 0, 0, 20], [0, 0, -157, -182, -60, 0], [-2399, 65, 0, 0, 0, 36], [0, 0, -48, -64, -307, 0], [3175, 21, 0, 0, 0, 18], [0, 0, -290, 78, -106, 0], [0, 0, -207, -13, -134, 0], [446, -90, 0, 0, 0, 50], [1732, -158, 0, 0, 0, 22], [854, 6, 0, 0, 0, 42], [0, 0, 310, -74, -64, 0], [2054, 92, 0, 0, 0, 20], [-2508, -34, 0, 0, 0, -78], [0, 0, 437, 50, -404, 0], [1343, 17, 0, 0, 0, 70], [0, 0, 321, 71, -238, 0], [-3158, -116, 0, 0, 0, -44], [0, 0, -192, -256, -169, 0], [0, 0, 131, 254, 220, 0], [0, 0, 144, 96, -363, 0], [-6048, -134, 0, 0, 0, 18], [-2658, 28, 0, 0, 0, 28], [0, 0, -487, 78, -12, 0], [0, 0, -36, 92, 61, 0], [-3362, -180, 0, 0, 0, -52], [0, 0, -890, -138, 390, 0], [0, 0, -297, 67, 458, 0], [-2918, 178, 0, 0, 0, -74], [-6490, 36, 0, 0, 0, 62], [593, -49, 0, 0, 0, -86], [0, 0, 333, 113, -194, 0], [0, 0, -534, 82, -51, 0], [6424, 46, 0, 0, 0, -2], [0, 0, -409, 136, 552, 0], [0, 0, 471, 299, 282, 0], [3188, -247, 0, 0, 0, -61], [3782, 382, 0, 0, 0, -102], [0, 0, 958, 238, -526, 0], [0, 0, -543, -289, -334, 0], [3630, 72, 0, 0, 0, 138], [-2874, 484, 0, 0, 0, 28], [-7243, 161, 0, 0, 0, 16], [0, 0, 310, 262, 446, 0], [1848, -525, 0, 0, 0, -15], [3726, 130, 0, 0, 0, -122], [0, 0, 425, 224, -120, 0], [3787, 389, 0, 0, 0, 30], [0, 0, -26, -42, 822, 0], [-1578, -430, 0, 0, 0, -156], [1111, -225, 0, 0, 0, -156], [0, 0, -212, 188, -891, 0], [0, 0, -240, 144, -409, 0], [3822, -564, 0, 0, 0, -66], [0, 0, 209, -34, 252, 0], [9684, -33, 0, 0, 0, 117], [0, 0, 378, -510, -363, 0], [0, 0, 555, 13, -618, 0], [0, 0, 174, 310, 283, 0], [0, 0, -1087, -268, 984, 0], [0, 0, 610, -542, 294, 0], [-5996, 259, 0, 0, 0, -47], [0, 0, 1620, 292, -709, 0], [2118, 492, 0, 0, 0, 28], [0, 0, 508, -244, 441, 0], [66, 486, 0, 0, 0, 210], [8346, 526, 0, 0, 0, 12], [1818, -272, 0, 0, 0, 184], [-8233, -351, 0, 0, 0, 94], [0, 0, 957, 833, 750, 0], [11178, -412, 0, 0, 0, -36], [0, 0, 312, -168, 1039, 0], [6271, -217, 0, 0, 0, 228], [15152, 307, 0, 0, 0, -31], [0, 0, -1146, -274, 1187, 0], [-5442, -234, 0, 0, 0, 48], [0, 0, 209, -52, 864, 0], [0, 0, -596, 508, 705, 0], [0, 0, -1455, -815, -2, 0], [6558, 304, 0, 0, 0, 64], [0, 0, 275, -340, -1256, 0], [0, 0, 154, -214, -700, 0], [0, 0, -222, -230, -521, 0], [0, 0, 989, -714, -252, 0], [0, 0, 501, -313, 1346, 0], [-3766, 942, 0, 0, 0, -4], [5927, 803, 0, 0, 0, -152], [0, 0, 255, -179, -842, 0], [0, 0, -132, 812, -285, 0], [6440, -104, 0, 0, 0, -112], [-13455, 275, 0, 0, 0, 158], [0, 0, -1251, -9, 1458, 0], [-9432, -463, 0, 0, 0, 27], [-10174, -32, 0, 0, 0, -72], [0, 0, 587, 978, 220, 0], [0, 0, -1230, 378, 449, 0], [0, 0, 509, 1300, 1032, 0], [12288, 1305, 0, 0, 0, 3], [0, 0, 318, -490, 537, 0], [0, 0, -673, -990, 268, 0], [4707, -1201, 0, 0, 0, -472], [0, 0, -356, 796, 251, 0], [0, 0, 903, 1313, 462, 0], [27762, -424, 0, 0, 0, -138], [0, 0, -1923, 1125, -106, 0], [-21524, 535, 0, 0, 0, 13], [0, 0, 690, 458, -577, 0], [-20448, -126, 0, 0, 0, -198], [0, 0, -2205, 1223, 514, 0], [-26146, 144, 0, 0, 0, 80], [0, 0, 714, -94, 1323, 0], [2452, -770, 0, 0, 0, -14], [0, 0, -1878, 130, -917, 0], [-17524, 50, 0, 0, 0, 350], [9395, 731, 0, 0, 0, -140], [-268, -1415, 0, 0, 0, 371], [12966, 1192, 0, 0, 0, -8], [0, 0, 569, 752, -2760, 0], [0, 0, 1312, 880, -2373, 0], [-20988, -177, 0, 0, 0, -315], [18993, 1241, 0, 0, 0, 44], [0, 0, 682, 346, 1656, 0], [-18684, -535, 0, 0, 0, -189], [36564, 14, 0, 0, 0, 258], [-11367, 95, 0, 0, 0, 338], [0, 0, -2211, -15, 446, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_288_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_288_4_d_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_288_4_d_d(:prec:=6)
    chi := MakeCharacter_288_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_288_4_d_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_288_4_d_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_288_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![10816, 0, 28976, 0, 428, 0, 1]>],Snew);
    return Vf;
end function;