
// Make newform 384.3.i.b in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_384_i();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_384_i_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_384_3_i_b();".
// 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_384_3_i_b();".
// 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 := [16, 0, -8, 0, 2, 0, -2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0], [0, 8, 24, 10, 0, 2, 0, 1], [-4, 0, -2, 0, 2, 0, 1, 0], [0, 4, 0, -10, 0, 4, 0, -1], [0, 10, 0, 2, 0, 1, 0, -1], [-32, -8, 8, -10, -8, -2, 8, -1], [32, -8, -8, -10, 8, -2, -8, -1]];
    Rf_basisdens := [1, 1, 24, 12, 12, 6, 24, 24];
    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_384_i();"
function MakeCharacter_384_i()
    N := 384;
    order := 4;
    char_gens := [127, 133, 257];
    v := [4, 3, 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_384_i_Hecke();"
function MakeCharacter_384_i_Hecke(Kf)
    N := 384;
    order := 4;
    char_gens := [127, 133, 257];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, -1, 0, 0, 0, 0], [-1, 0, 0, 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 := 3;
    raw_aps := [[0, 0, 0, 0, 0, 0, 0, 0], [0, -1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 3, 0, -1, -1], [1, 0, -1, -1, 0, 0, -1, 0], [0, 0, 0, 0, 2, 0, 0, 0], [11, 0, 2, 13, 0, 0, 1, 1], [0, 1, 0, 0, -1, -9, -8, -8], [-2, 0, 8, 6, 0, 0, 4, 4], [0, 2, 0, 0, 2, -10, 0, 0], [0, -7, 0, 0, 0, -7, -7, -7], [-9, 0, -1, -1, 0, 0, 0, -1], [-9, 0, 0, 19, 0, 0, -5, 5], [0, 1, 0, 0, 1, 7, 0, 0], [-34, 0, 0, 26, 0, 0, 4, -4], [0, -14, 0, 0, 14, 24, 10, 10], [0, 0, 0, 0, 7, 0, -15, -15], [0, 0, 0, 0, 10, 0, 5, 5], [-31, 0, 10, -21, 0, 0, 5, 5], [-44, 0, 30, -14, 0, 0, 15, 15], [0, 16, 0, 0, 16, 26, 0, 0], [-14, 0, 14, -22, 0, 0, 14, 0], [17, 0, 13, 13, 0, 0, 0, 13], [0, 38, 0, 0, 0, -2, 18, 18], [0, -18, 0, 0, -18, 10, 0, 0], [-60, 0, -8, -8, 0, 0, 0, -8], [0, 0, 0, 0, -15, 0, -7, -7], [-9, 0, 9, -75, 0, 0, 9, 0], [0, 0, 0, 0, 54, 0, -35, -35], [-31, 0, 46, 15, 0, 0, 23, 23], [0, 6, 0, 0, -6, 18, 24, 24], [61, 0, -51, -51, 0, 0, 0, -51], [0, -46, 0, 0, 0, 124, 39, 39], [0, 17, 0, 0, 17, 19, 0, 0], [66, 0, 0, -124, 0, 0, 29, -29], [0, 0, 0, 0, 43, 0, -21, -21], [11, 0, -11, 1, 0, 0, -11, 0], [71, 0, -134, -63, 0, 0, -67, -67], [154, 0, -56, 98, 0, 0, -28, -28], [0, 42, 0, 0, 42, -10, 0, 0], [0, 31, 0, 0, 0, 47, 39, 39], [0, 66, 0, 0, 0, -56, 5, 5], [-39, 0, 0, 109, 0, 0, -35, 35], [0, 14, 0, 0, -14, 48, 62, 62], [128, 0, -30, -30, 0, 0, 0, -30], [0, 0, 0, 0, -59, 0, 51, 51], [-43, 0, 43, 31, 0, 0, 43, 0], [-200, 0, 2, -198, 0, 0, 1, 1], [71, 0, 115, 115, 0, 0, 0, 115], [0, 22, 0, 0, 0, -122, -50, -50], [149, 0, 0, -143, 0, 0, -3, 3], [0, 92, 0, 0, 92, -44, 0, 0], [0, -78, 0, 0, 78, -24, -102, -102], [88, 0, 134, 134, 0, 0, 0, 134], [0, 0, 0, 0, -74, 0, 26, 26], [0, -64, 0, 0, 64, -12, -76, -76], [0, 8, 0, 0, 8, -130, 0, 0], [0, 107, 0, 0, 0, -49, 29, 29], [-279, 0, -19, -19, 0, 0, 0, -19], [-141, 0, 0, 7, 0, 0, 67, -67], [0, 54, 0, 0, 54, -86, 0, 0], [-126, 0, 0, 44, 0, 0, 41, -41], [0, 0, 0, 0, -163, 0, 7, 7], [-56, 0, 186, 130, 0, 0, 93, 93], [0, -28, 0, 0, -28, 2, 0, 0], [146, 0, -146, -104, 0, 0, -146, 0], [0, -57, 0, 0, 0, 227, 85, 85], [-146, 0, 0, -4, 0, 0, 75, -75], [106, 0, 14, 14, 0, 0, 0, 14], [0, 0, 0, 0, -10, 0, -36, -36], [-61, 0, -74, -135, 0, 0, -37, -37], [0, 60, 0, 0, -60, 48, 108, 108], [0, -96, 0, 0, -96, 74, 0, 0], [-47, 0, -111, -111, 0, 0, 0, -111], [-55, 0, 0, -167, 0, 0, 111, -111], [294, 0, 0, -262, 0, 0, -16, 16], [0, -50, 0, 0, 50, -156, -206, -206], [0, 0, 0, 0, 75, 0, 113, 113], [41, 0, 222, 263, 0, 0, 111, 111], [0, 75, 0, 0, -75, 117, 192, 192], [88, 0, -88, 188, 0, 0, -88, 0], [0, 82, 0, 0, 0, -62, 10, 10], [-123, 0, 0, -47, 0, 0, 85, -85], [0, -38, 0, 0, 38, -24, -62, -62], [272, 0, -156, -156, 0, 0, 0, -156], [-37, 0, 37, 337, 0, 0, 37, 0], [0, 0, 0, 0, -110, 0, -58, -58], [0, -117, 0, 0, 117, 105, -12, -12], [-52, 0, 52, -152, 0, 0, 52, 0], [0, 109, 0, 0, 0, 125, 117, 117], [523, 0, 123, 123, 0, 0, 0, 123], [0, -30, 0, 0, 0, -14, -22, -22], [0, 76, 0, 0, -76, 144, 220, 220], [-149, 0, 149, -571, 0, 0, 149, 0], [0, 0, 0, 0, -234, 0, -53, -53], [-152, 0, -122, -274, 0, 0, -61, -61], [0, 212, 0, 0, 212, -22, 0, 0], [0, -53, 0, 0, 0, 59, 3, 3], [0, -165, 0, 0, -165, 37, 0, 0], [-338, 0, 0, 482, 0, 0, -72, 72], [-55, 0, -14, -69, 0, 0, -7, -7], [-86, 0, 48, -38, 0, 0, 24, 24], [0, -119, 0, 0, 0, -115, -117, -117], [0, -294, 0, 0, 0, -122, -208, -208], [0, 55, 0, 0, 55, 193, 0, 0], [-38, 0, 0, 80, 0, 0, -21, 21], [-38, 0, -202, -202, 0, 0, 0, -202], [0, 0, 0, 0, -102, 0, 151, 151], [0, 4, 0, 0, -4, -252, -248, -248], [0, -194, 0, 0, -194, 2, 0, 0], [-74, 0, 74, 110, 0, 0, 74, 0], [-291, 0, 149, 149, 0, 0, 0, 149], [439, 0, 0, -497, 0, 0, 29, -29], [0, 46, 0, 0, 46, -242, 0, 0], [-250, 0, 0, 68, 0, 0, 91, -91], [-355, 0, 355, -5, 0, 0, 355, 0], [0, -249, 0, 0, 249, 153, -96, -96], [742, 0, -64, 678, 0, 0, -32, -32], [0, -178, 0, 0, -178, 86, 0, 0], [0, -387, 0, 0, 0, 173, -107, -107], [0, 294, 0, 0, 0, -188, 53, 53], [-213, 0, 0, 499, 0, 0, -143, 143], [800, 0, 108, 108, 0, 0, 0, 108], [0, 0, 0, 0, 389, 0, -311, -311], [0, 0, 0, 0, 174, 0, -158, -158], [-566, 0, 80, -486, 0, 0, 40, 40], [0, -15, 0, 0, 0, -451, -233, -233], [-9, 0, 0, -221, 0, 0, 115, -115], [0, 276, 0, 0, -276, 12, 288, 288], [121, 0, -121, -469, 0, 0, -121, 0], [491, 0, -242, 249, 0, 0, -121, -121], [-320, 0, 262, -58, 0, 0, 131, 131], [0, 78, 0, 0, 78, 338, 0, 0], [-389, 0, -153, -153, 0, 0, 0, -153], [265, 0, 0, 325, 0, 0, -295, 295], [0, -107, 0, 0, -107, -245, 0, 0], [0, 0, 334, 334, 0, 0, 0, 334], [0, 0, 0, 0, -131, 0, -243, -243], [-50, 0, -400, -450, 0, 0, -200, -200], [0, -167, 0, 0, 0, 197, 15, 15], [0, -43, 0, 0, -43, 139, 0, 0], [90, 0, 0, -490, 0, 0, 200, -200], [0, 0, 0, 0, 9, 0, 113, 113], [53, 0, -53, 1411, 0, 0, -53, 0], [0, 0, 0, 0, -50, 0, -25, -25], [239, 0, -262, -23, 0, 0, -131, -131], [0, 4, 0, 0, 4, -22, 0, 0], [329, 0, 0, -431, 0, 0, 51, -51], [0, 341, 0, 0, 341, 199, 0, 0], [42, 0, 0, -154, 0, 0, 56, -56], [0, -102, 0, 0, 102, -240, -342, -342], [-961, 0, 198, -763, 0, 0, 99, 99], [0, -130, 0, 0, 130, 318, 188, 188], [-230, 0, -88, -318, 0, 0, -44, -44], [0, -24, 0, 0, -24, 446, 0, 0], [-582, 0, 0, 638, 0, 0, -28, 28], [0, 338, 0, 0, -338, 252, 590, 590], [421, 0, -421, -373, 0, 0, -421, 0], [0, 201, 0, 0, -201, 195, 396, 396], [-28, 0, 28, -962, 0, 0, 28, 0], [0, -495, 0, 0, 0, -151, -323, -323], [0, 534, 0, 0, 0, 352, 443, 443], [0, -197, 0, 0, -197, 469, 0, 0], [235, 0, -235, -1075, 0, 0, -235, 0], [0, 0, 0, 0, 318, 0, -92, -92], [0, 43, 0, 0, -43, -447, -404, -404], [0, -188, 0, 0, -188, -262, 0, 0], [37, 0, 369, 369, 0, 0, 0, 369], [319, 0, 0, -53, 0, 0, -133, 133]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_384_i_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_384_3_i_b();".
// 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_384_3_i_b(:prec:=8)
    chi := MakeCharacter_384_i();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    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_384_3_i_b();".
// 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_384_3_i_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_384_i();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![153664, 0, 0, 0, 6272, 0, 0, 0, 1]>,<19,R![46656, 1728, 32, -8, 1]>],Snew);
    return Vf;
end function;