
// Make newform 384.3.e.c in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_384_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_384_e_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_e_c();".
// 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_e_c();".
// 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 := [81, 0, 170, 0, 99, 0, 18, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [63, -6, 70, 0, 16, 0, 1, 0], [0, 193, 0, 159, 0, 33, 0, 2], [18, 0, 11, 0, 1, 0, 0, 0], [0, 178, 0, 180, 0, 36, 0, 2], [-27, -63, -27, -70, -3, -16, 0, -1], [-27, 57, -27, 70, -3, 16, 0, 1], [61, 6, 70, 0, 16, 0, 1, 0]];
    Rf_basisdens := [1, 6, 9, 1, 9, 3, 3, 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_384_e();"
function MakeCharacter_384_e()
    N := 384;
    order := 2;
    char_gens := [127, 133, 257];
    v := [2, 2, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_384_e_Hecke();"
function MakeCharacter_384_e_Hecke(Kf)
    N := 384;
    order := 2;
    char_gens := [127, 133, 257];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [-1, 0, 0, -1, 0, 0, 0, 0], [0, 0, 0, 0, -1, -1, 1, 0], [-1, 1, 0, 0, 0, 1, 1, 1], [1, -3, 2, 0, 2, 1, -1, 1], [-3, 1, 0, -2, 0, -2, -2, -1], [0, 0, 4, 0, 0, 2, -2, 0], [2, -6, 3, 0, 0, 2, -2, 2], [9, -4, 0, 1, 0, 2, 2, 0], [1, -9, 0, 4, 0, 3, 3, -1], [-2, 6, 6, 0, 6, 2, -2, -2], [17, 1, 0, 2, 0, -2, -2, -1], [2, -6, 0, 0, -2, 2, -2, 2], [-4, 12, 1, 0, -4, 4, -4, -4], [-1, 3, 0, 0, -8, 0, 0, -1], [13, 11, 0, -4, 0, -1, -1, 3], [-37, 1, 0, 8, 0, 4, 4, 3], [2, -6, 4, 0, -10, -4, 4, 2], [-2, -12, 0, 4, 0, 0, 0, -4], [41, 16, 0, -3, 0, -2, -2, 4], [2, -6, 8, 0, -5, -1, 1, 2], [-5, 15, -16, 0, 8, -1, 1, -5], [5, 13, 0, -2, 0, -5, -5, 1], [-2, 6, -3, 0, -12, -10, 10, -2], [-69, 12, 0, 7, 0, 0, 0, 4], [1, -3, 8, 0, -6, 6, -6, 1], [-27, 11, 0, 12, 0, -1, -1, 3], [2, -6, 0, 0, 8, -6, 6, 2], [69, -28, 0, -3, 0, -10, -10, -16], [3, -9, 24, 0, -6, 6, -6, 3], [0, 0, 10, 0, -6, -12, 12, 0], [115, -7, 0, 16, 0, 8, 8, 3], [0, 0, -11, 0, -16, 0, 0, 0], [-89, -12, 0, -13, 0, -12, -12, -12], [71, -7, 0, 0, 0, -7, -7, -7], [-71, -7, 0, -14, 0, -10, -10, -9], [4, -12, -20, 0, -12, 2, -2, 4], [-4, 12, 3, 0, 12, 4, -4, -4], [-7, 21, -16, 0, -8, 8, -8, -7], [-37, 29, 0, 8, 0, 5, 5, 13], [-14, 42, 24, 0, 14, -2, 2, -14], [-14, -24, 0, 12, 0, 12, 12, 0], [6, -18, -7, 0, 0, 6, -6, 6], [-81, 20, 0, -21, 0, -4, -4, 4], [-177, 25, 0, 4, 0, 4, 4, 11], [57, -64, 0, -3, 0, 14, 14, -12], [-2, 6, 8, 0, 19, -9, 9, -2], [67, 21, 0, -24, 0, -3, -3, 5], [11, -33, 36, 0, 12, 23, -23, 11], [22, -66, 16, 0, 2, 6, -6, 22], [46, -52, 0, 36, 0, 8, 8, -12], [-10, 30, 24, 0, -3, -7, 7, -10], [-2, 6, 20, 0, 4, -2, 2, -2], [14, -42, 20, 0, 58, 16, -16, 14], [-8, 24, 15, 0, 8, 8, -8, -8], [73, 64, 0, -19, 0, -2, -2, 20], [-23, -1, 0, 36, 0, 11, 11, 7], [13, -39, -4, 0, -44, 1, -1, 13], [167, 49, 0, 12, 0, -8, -8, 11], [10, -30, 41, 0, 24, 26, -26, 10], [-1, -39, 0, 28, 0, 0, 0, -13], [-10, 30, -4, 0, -6, -12, 12, -10], [-49, 3, 0, -18, 0, 9, 9, 7], [4, -12, -13, 0, 64, 4, -4, 4], [11, -7, 0, -32, 0, -4, -4, -5], [-91, 21, 0, -38, 0, -9, -9, 1], [14, -42, 8, 0, 13, 17, -17, 14], [279, 1, 0, 16, 0, 1, 1, 1], [-4, 12, -8, 0, -64, 12, -12, -4], [6, -18, 36, 0, 2, 0, 0, 6], [9, 68, 0, -7, 0, -22, -22, 8], [-169, -23, 0, 16, 0, 25, 25, 9], [-75, -71, 0, 22, 0, 10, 10, -17], [-14, 42, 24, 0, 6, -10, 10, -14], [-24, 72, -67, 0, 36, 0, 0, -24], [-279, 71, 0, 20, 0, -13, -13, 15], [-9, 27, -74, 0, -10, 7, -7, -9], [102, -28, 0, 16, 0, -28, -28, -28], [-20, 60, 32, 0, -19, 29, -29, -20], [79, 25, 0, 0, 0, -23, -23, -7], [6, -18, -80, 0, -30, -42, 42, 6], [101, 29, 0, 14, 0, 11, 11, 17], [103, 12, 0, -37, 0, -36, -36, -20], [-24, 72, -64, 0, 67, -13, 13, -24], [17, -51, -26, 0, -2, -23, 23, 17], [-86, -80, 0, 8, 0, -8, -8, -32], [-6, 18, -41, 0, 40, -22, 22, -6], [93, 12, 0, -3, 0, 6, 6, 8], [36, -108, 48, 0, 17, 9, -9, 36], [-4, 12, 32, 0, 28, -44, 44, -4], [299, 16, 0, 35, 0, -20, -20, -8], [15, -45, 0, 0, 4, 20, -20, 15], [-105, -71, 0, -36, 0, -20, -20, -37], [-6, 18, 12, 0, 14, 40, -40, -6], [16, -48, -89, 0, -68, -8, 8, 16], [0, 0, -94, 0, -6, -44, 44, 0], [-383, -15, 0, 10, 0, -6, -6, -9], [425, 15, 0, -44, 0, -21, -21, -9], [273, -87, 0, 66, 0, 18, 18, -17], [42, -126, -5, 0, -36, -14, 14, 42], [-36, 108, 0, 0, -63, -15, 15, -36], [-20, 60, 86, 0, -18, 24, -24, -20], [135, -111, 0, -4, 0, 0, 0, -37], [-15, 73, 0, 66, 0, 19, 19, 37], [-11, 33, -72, 0, 46, 10, -10, -11], [24, -72, 68, 0, 52, 32, -32, 24], [8, -24, -28, 0, -80, 18, -18, 8], [134, 44, 0, -12, 0, 8, 8, 20], [157, 52, 0, -107, 0, -50, -50, -16], [265, -105, 0, 68, 0, 51, 51, -1], [-19, 57, -8, 0, 72, 9, -9, -19], [-397, 57, 0, 8, 0, 12, 12, 27], [443, 8, 0, 59, 0, 20, 20, 16], [-17, 51, -30, 0, -78, -9, 9, -17], [1, 89, 0, -14, 0, -70, -70, -17], [-4, 12, 28, 0, -76, -38, 38, -4], [26, -78, 143, 0, 16, 58, -58, 26], [17, -51, -64, 0, -8, -24, 24, 17], [-319, 127, 0, 4, 0, -5, -5, 39], [49, -47, 0, 6, 0, 55, 55, 21], [-14, 42, 45, 0, 52, -22, 22, -14], [-14, 42, -72, 0, -99, -39, 39, -14], [197, -127, 0, -18, 0, 26, 26, -25], [-42, 126, -65, 0, -36, 30, -30, -42], [17, -41, 0, 4, 0, 67, 67, 31], [-28, 84, 8, 0, -116, -24, 24, -28], [379, 36, 0, 15, 0, 24, 24, 28], [451, -11, 0, 8, 0, 61, 61, 37], [563, -47, 0, -104, 0, -32, -32, -37], [8, -24, 156, 0, -16, 46, -46, 8], [285, -144, 0, -55, 0, -30, -30, -68], [-281, 17, 0, -64, 0, -31, -31, -15], [30, -90, -70, 0, 26, -54, 54, 30], [-58, -76, 0, -92, 0, -16, -16, -36], [38, -114, -11, 0, -28, -2, 2, 38], [-299, 81, 0, -66, 0, 18, 18, 39], [-14, 42, 31, 0, -124, 10, -10, -14], [-14, 42, -82, 0, 94, -10, 10, -14], [-367, -47, 0, 154, 0, 58, 58, 23], [50, -150, 17, 0, 84, 10, -10, 50], [-21, 24, 0, -133, 0, -60, -60, -32], [-43, 129, 72, 0, -22, 38, -38, -43], [551, -39, 0, 32, 0, -39, -39, -39], [-50, 150, -44, 0, 2, 56, -56, -50], [3, 77, 0, -88, 0, 5, 5, 29], [0, 0, -66, 0, -114, -36, 36, 0], [517, 73, 0, -26, 0, 34, 34, 47], [82, -246, 136, 0, 78, 54, -54, 82], [-549, 45, 0, 40, 0, 21, 21, 29], [-82, 246, 16, 0, 16, -58, 58, -82], [717, -127, 0, 46, 0, -34, -34, -65], [10, -30, -84, 0, -138, -64, 64, 10], [-303, -95, 0, 34, 0, 46, 46, -1], [-70, 210, -176, 0, 86, -30, 30, -70], [515, 128, 0, -5, 0, 20, 20, 56], [3, -9, -102, 0, -78, -69, 69, 3], [183, 35, 0, 26, 0, -19, -19, -1], [-90, 270, -129, 0, -136, -74, 74, -90], [-37, 111, 72, 0, 110, -38, 38, -37], [16, -48, 14, 0, 38, 60, -60, 16], [-821, -40, 0, 59, 0, 20, 20, 0], [6, -18, 24, 0, 97, 109, -109, 6], [25, -75, -230, 0, 2, -71, 71, 25], [2, -6, -4, 0, 78, -32, 32, 2], [-283, 200, 0, -23, 0, -94, -94, 4], [-243, 27, 0, -132, 0, -81, -81, -45]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_384_e_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_384_3_e_c();".
// 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_e_c(:prec:=8)
    chi := MakeCharacter_384_e();
    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_e_c();".
// 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_e_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_384_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![-176, -368, -108, 4, 1]>,<13,R![7824, -256, -360, 0, 1]>],Snew);
    return Vf;
end function;