
// Make newform 336.3.be.d in Magma, downloaded from the LMFDB on 12 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_336_be();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_336_be_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_336_3_be_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_336_3_be_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 := [972, 0, 364, 0, 35, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [36, 22, 0, 17, 0, 1], [-396, -542, -36, -121, 0, -5], [12, 0, 1, 0, 0, 0], [72, 118, 6, 23, 0, 1], [56, 2, 19, 0, 1, 0]];
    Rf_basisdens := [1, 72, 72, 1, 12, 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_336_be();"
function MakeCharacter_336_be()
    N := 336;
    order := 6;
    char_gens := [127, 85, 113, 241];
    v := [3, 6, 6, 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_336_be_Hecke();"
function MakeCharacter_336_be_Hecke( : Kf := false)
    N := 336;
    order := 6;
    char_gens := [127, 85, 113, 241];
    char_values := [[-1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [-1, 1, 0, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), 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]];
    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], [-2, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0], [-2, 0, 1, -1, 1, -1], [1, -1, 1, -1, 0, -1], [-7, 1, -1, -1, -1, 2], [1, 1, -1, 2, -3, -1], [-3, -5, 0, 2, -1, -2], [5, 0, 0, -4, 2, -5], [8, -1, 1, -7, 1, -2], [-7, 2, 3, -4, -1, -3], [4, -1, -6, 0, -3, 3], [-22, -4, 4, -2, 4, -8], [-1, 0, 2, -3, 8, 0], [-27, -30, 0, -4, 2, -3], [0, -30, 0, 1, -1, 0], [14, -8, 2, -1, 1, -2], [-18, 22, -8, 0, 8, 4], [78, -39, 0, -1, -1, 0], [-6, 19, -7, -2, -3, 0], [-3, 14, 3, 3, 0, 3], [-6, 3, 0, 20, -10, 9], [0, 2, -2, -7, 12, 0], [-72, 60, 24, 0, 2, -12], [-42, -1, 1, -7, 1, -2], [0, 102, 0, 8, -8, 0], [-25, -9, 0, -6, 3, 16], [16, 18, 0, -10, 5, 2], [-5, -108, 5, 7, -2, 5], [36, -15, 15, -4, 15, -30], [-19, 33, 5, -10, 25, 0], [-83, -84, 0, 10, -5, -1], [-2, -146, 2, 22, -20, 2], [51, -110, 8, -3, 14, 0], [6, -12, 12, 0, 26, -6], [141, -71, 1, 9, 10, -1], [2, 72, -2, -38, 36, -2], [14, 4, 0, 8, -4, -10], [18, -13, -23, 6, -35, 0], [-95, 106, -22, 0, -34, 11], [-35, 5, 25, -12, 13, -25], [-79, 7, -7, 31, -7, 14], [-75, -66, 0, -16, 8, 9], [8, -183, -8, -2, -6, -8], [46, 19, -19, 12, -19, 38], [-174, 74, 26, -16, 10, -26], [-8, 30, -14, -2, -10, 0], [54, -121, 13, 23, -33, 0], [85, -61, 37, -23, 14, -37], [-216, 209, 14, 0, 27, -7], [-83, 100, -34, 0, -2, 17], [-174, 346, 2, -14, 30, 0], [21, -67, -21, -21, 0, -21], [54, -144, 36, 11, 14, 0], [-13, 32, -38, 0, 24, 19], [44, -20, -4, 14, 10, 4], [15, 219, -15, 5, -20, -15], [117, 74, 0, 22, -11, -43], [5, -266, -5, -11, 6, -5], [26, 23, -23, -8, -23, 46], [-130, 71, -12, 13, 1, 12], [-84, 15, -15, 5, -15, 30], [169, -290, -48, -19, -10, 0], [150, -60, -30, -14, -44, 30], [-253, 267, -28, 0, -18, 14], [21, -12, -18, 0, -15, 9], [39, 77, 0, -42, 21, 38], [37, 6, -6, -24, -6, 12], [-345, 177, -9, 18, 9, 9], [-94, -30, 30, -44, 30, -60], [-1, 65, 1, -16, 17, 1], [16, 48, 0, 100, -50, 32], [-219, 124, -29, 28, -1, 29], [-4, -33, 74, 0, 89, -37], [189, -396, 18, 17, -16, 0], [-187, -120, 0, 16, -8, 67], [-23, 7, 23, 26, -3, 23], [-300, 271, 58, 0, 21, -29], [-107, 130, -46, 0, -44, 23], [-34, -131, 34, 98, -64, 34], [-30, -4, 64, 58, -52, 0], [1, 9, -9, -79, -9, 18], [83, -5, -73, -4, -77, 73], [-9, -11, 11, 7, 11, -22], [129, 210, 0, 94, -47, 81], [390, 402, 0, 10, -5, 12], [-408, -3, 3, 24, 3, -6], [105, -43, -124, 0, -50, 62], [-268, -34, 34, -74, 34, -68], [17, -24, -10, 57, -124, 0], [-313, -366, 0, -72, 36, -53], [463, -223, -17, 40, 23, 17], [127, -66, 5, -36, -31, -5], [-78, 127, 29, -27, 83, 0], [115, 143, 0, 46, -23, 28], [-318, 666, -30, -34, 38, 0], [422, -436, 28, 0, -105, -14], [12, 60, -12, -46, 34, -12], [149, 81, 0, -66, 33, -68], [44, -71, 54, 0, 93, -27], [244, -444, -44, 16, -76, 0], [15, 375, -15, -97, 82, -15], [420, -228, 36, -83, -47, -36], [206, -262, 112, 0, 154, -56], [-298, 111, 76, -3, 73, -76], [0, -11, 0, 0, 0, 0], [-30, 139, -79, 47, -173, 0], [522, -522, 0, 0, -110, 0], [-222, 78, 66, 2, 68, -66], [95, 48, -48, 36, -48, 96], [232, 155, 0, -144, 72, -77], [-56, 398, 56, 110, -54, 56], [-566, 28, -28, -32, -28, 56], [-50, 29, -8, 55, 47, 8], [254, -571, 63, 63, -63, 0], [25, -83, -25, 88, -113, -25], [107, -290, 76, 49, -22, 0], [38, -32, 26, -80, -54, -26], [-479, 466, 26, 0, 25, -13], [-252, 511, -7, 50, -107, 0], [-7, 48, 7, -23, 30, 7], [-281, -4, 4, -74, 4, -8], [1009, -1028, 38, 0, 59, -19], [-844, 430, -16, 13, -3, 16], [259, 361, 0, 102, -51, 102], [-206, -80, 80, -137, 80, -160], [382, -318, -128, 0, -96, 64], [4, 54, 0, 48, -24, 50], [-149, 329, -31, -94, 157, 0], [-34, 37, -6, 0, 81, 3], [-900, 481, -62, 25, -37, 62], [-78, 148, 8, 36, -64, 0], [-570, -539, 0, -44, 22, 31], [-370, 40, -40, 112, -40, 80], [165, -234, 138, 0, 56, -69], [-133, -48, 48, -42, 48, -96], [-62, -212, 62, 112, -50, 62], [812, -376, -60, -30, -90, 60], [-10, 32, -32, 13, -32, 64], [11, 353, -11, 4, -15, -11], [132, -228, -36, 78, -192, 0], [-520, 536, -32, 0, -61, 16], [128, -52, -24, 40, 16, 24], [156, -240, -72, -79, 86, 0], [-63, -562, 63, 73, -10, 63], [-204, 304, 104, 24, 56, 0], [971, 27, -27, 55, -27, 54], [-54, 366, 54, 146, -92, 54], [48, 148, 0, 124, -62, 100], [-70, -30, 0, 256, -128, 40], [574, -574, 0, 0, 2, 0], [354, -51, 51, 60, 51, -102], [-175, 404, -54, -107, 160, 0], [-40, -126, 0, 140, -70, -86], [-358, 193, -28, -7, -35, 28], [-324, 583, 65, -60, 185, 0], [-193, -119, 0, 206, -103, 74], [-55, 32, 46, 0, 20, -23], [-205, 0, 0, 60, 0, 0], [44, -22, -44, -45, 1, -44], [276, 138, 0, -140, 70, -138], [-282, -27, 27, 36, 27, -54], [543, -989, -97, -38, -21, 0], [-308, -162, 0, -50, 25, 146], [-68, -794, 68, -28, 96, 68], [-943, 427, 89, -38, 51, -89], [89, -110, 131, 40, 171, -131], [101, -600, -101, -175, 74, -101]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_336_be_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_336_3_be_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_336_3_be_d(:prec:=6)
    chi := MakeCharacter_336_be();
    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_336_3_be_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_336_3_be_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_336_be();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![7056, 3696, 1852, 212, 45, -1, 1]>,<11,R![432, 4032, 12580, 336, -109, -3, 1]>],Snew);
    return Vf;
end function;