
// Make newform 333.3.i.a in Magma, downloaded from the LMFDB on 05 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_333_i();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_333_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_333_3_i_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_333_3_i_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 := [16, 312, 3042, -2054, 761, 704, 884, -268, 42, 8, 18, -6, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-31702472561346, -223975926024, -2058770145142, 4003008870742, -1772032403269, 1415720244216, -347459699704, 103217914397, -30812713531, 30130260222, -7950477538, 1147429625], [-7096843485882, -6129189030810, 3180446772550, -5718445747758, -2132505137420, -1870181521220, 584367344120, -157651358049, -26728073300, -37789653290, 13065354770, -2383585029], [9609041030712, -3285624795304, -30457932400962, 53528615410220, 16613630415421, 16677564024461, -5666071639324, 1809457140907, 105672415293, 385593203213, -126631722778, 22666832839], [-9336516192680, -188498035148212, 84284962404332, -69761826548796, -34646222333720, -38001499467715, 11679677808741, -2669265690979, -410770163760, -725700954999, 245969084305, -43439014063], [12075070737780, 243612019339250, -171632096091566, 55086767085235, 51165880402360, 70113506286540, -21217111300198, 3222200422550, 548355278020, 1429983524890, -472718108508, 77991823075], [59127484519700, 1192855900832066, -838853769110166, 263996943930659, 251564391736960, 346827168390260, -104916821812750, 15795699396652, 2688320243500, 7074338317870, -2337459833000, 385191945317], [4240742854992, -1308312161398966, 835542395709902, -271406861062927, -241760697078188, -354818254597230, 106414526123590, -16082032345854, -2516643076144, -7214583139376, 2372313842020, -389618604143], [-133686977444264, -1303389767349798, 881281806178034, -349408005600287, -301302624098436, -378567917837796, 115214329896334, -18535854900044, -3346132563624, -7709610342782, 2566965018248, -428273927397], [16031325091000, 3075419736686360, -1942110853311394, 636887514045980, 549573999341355, 849207341670775, -251903358642361, 38199825975280, 5272546546659, 17364795575951, -5667654113167, 925851580180], [314224969405808, 3065270361059880, -2036749463080434, 791054534861082, 733111725298765, 893947278597160, -270924001980561, 42847483173135, 8526890490421, 18191287173440, -6083306132567, 1017662160901]];
    Rf_basisdens := [1, 1, 6472908901282, 6472908901282, 25891635605128, 25891635605128, 12945817802564, 12945817802564, 12945817802564, 12945817802564, 25891635605128, 25891635605128];
    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_333_i();"
function MakeCharacter_333_i()
    N := 333;
    order := 4;
    char_gens := [38, 298];
    v := [4, 3];
    // 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_333_i_Hecke();"
function MakeCharacter_333_i_Hecke(Kf)
    N := 333;
    order := 4;
    char_gens := [38, 298];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 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]];
    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 := [[1, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1], [0, -1, -1, -1, 0, 0, 0, 0, 0, 0, 1, -1], [0, 0, 0, 0, 0, 1, 3, 1, -1, -1, 0, 0], [0, 0, 1, -1, 0, 0, 1, -1, 0, -1, 0, 1], [-2, 0, 0, 0, 1, -1, -2, 0, 0, 1, 0, 4], [-1, 0, -1, -4, -1, 1, 3, 1, 0, 1, 0, 0], [-1, 0, -2, 5, -3, 3, -6, 2, 0, 0, 0, -3], [-9, 5, 1, 0, -2, -2, 8, 1, 0, 0, 1, 0], [6, -4, 1, 0, -3, -3, -7, 1, -1, 0, 1, 0], [-11, 0, 4, -7, 2, 6, -7, 3, -1, 1, 1, 1], [-6, 7, 0, -7, 0, 3, -10, 2, -1, -1, -1, -1], [5, 0, 4, 2, 3, -3, 3, -4, 0, 3, 0, 2], [32, 2, -3, 2, -2, 0, 0, 0, -1, 1, 0, 0], [3, -2, -1, -2, -8, 0, 0, 0, 2, -2, -1, 1], [-25, 0, 5, -14, -2, 2, -11, -5, 0, 2, 0, 0], [9, 8, 1, 0, 0, 0, -2, 1, -7, 0, -7, 0], [13, -9, 0, 9, 0, -9, -9, -4, -3, -3, -4, -4], [-3, -3, 7, -3, 10, 0, 0, 0, 5, -5, -6, 6], [-5, 6, 0, -6, 0, -3, 55, 11, 1, 1, -1, -1], [-16, 0, -1, -29, -5, 5, 13, 1, 0, -3, 0, 1], [-7, 11, -15, 11, -6, 0, 0, 0, -3, 3, -8, 8], [-22, -18, 1, 0, 6, 6, 2, 1, 3, 0, 20, 0], [-8, 0, -9, 18, -1, 1, -26, 9, 0, 2, 0, -2], [-20, 21, 0, -21, 0, -12, 18, -13, 2, 2, -1, -1], [7, 6, -12, 0, -3, -3, -14, -12, 6, 0, 7, 0], [-83, -23, 1, -23, -9, 0, 0, 0, -2, 2, -2, 2], [-59, 0, 2, -14, -10, 10, -45, -2, 0, 1, 0, 6], [22, -6, -8, 0, -3, -3, -40, -8, -4, 0, 18, 0], [34, -10, -1, -10, -2, 0, 0, 0, 10, -10, 2, -2], [52, -22, 1, 0, -14, -14, -50, 1, 7, 0, -2, 0], [-3, 19, -12, 19, -17, 0, 0, 0, -3, 3, 1, -1], [-29, 11, 0, -11, 0, -37, 94, -15, 4, 4, 18, 18], [11, 7, -11, 7, 20, 0, 0, 0, 2, -2, -12, 12], [-1, 17, 0, -17, 0, -2, 72, -4, 7, 7, -16, -16], [-91, -3, -1, -3, 6, 0, 0, 0, -2, 2, -16, 16], [-30, 12, -7, 0, 1, 1, 18, -7, -15, 0, 12, 0], [-46, 0, 11, -20, 1, -1, -26, -11, 0, -4, 0, -3], [-12, 20, 0, -20, 0, 30, 30, 15, -8, -8, -8, -8], [-34, 48, -19, 0, 8, 8, 48, -19, -2, 0, -14, 0], [84, -1, -19, -1, 18, 0, 0, 0, 3, -3, 7, -7], [-47, 0, 13, -2, -7, 7, -45, -13, 0, 13, 0, 9], [-1, 0, 11, 46, -4, 4, -47, -11, 0, 15, 0, 40], [-19, 14, -9, 14, 22, 0, 0, 0, -4, 4, 3, -3], [6, 44, 17, 0, 24, 24, 12, 17, 0, 0, -18, 0], [-109, 40, -5, 40, -23, 0, 0, 0, 3, -3, -12, 12], [39, 2, -35, 2, -36, 0, 0, 0, -1, 1, -15, 15], [-45, 0, 3, -48, 8, -8, 3, -3, 0, 8, 0, 28], [-86, -20, -19, -20, 18, 0, 0, 0, -6, 6, 18, -18], [-15, 8, 0, -8, 0, 59, 30, 9, 10, 10, 7, 7], [109, 0, 6, -30, -7, 7, 139, -6, 0, -3, 0, -19], [74, 0, 0, -28, -3, 3, 102, 0, 0, -14, 0, 14], [135, 14, 14, 0, -1, -1, -137, 14, 1, 0, 2, 0], [88, 0, 15, 66, 13, -13, 22, -15, 0, -4, 0, -12], [56, -23, 0, 23, 0, -28, -10, 57, 9, 9, -33, -33], [-97, -4, -16, -4, 32, 0, 0, 0, 10, -10, 25, -25], [22, -58, -5, -58, -24, 0, 0, 0, 11, -11, 18, -18], [-25, 48, 19, 0, 44, 44, 22, 19, -17, 0, 3, 0], [118, 0, -4, 28, 4, -4, 90, 4, 0, -34, 0, 10], [55, -76, -18, 0, 1, 1, -29, -18, 4, 0, -26, 0], [80, -51, 40, -51, 68, 0, 0, 0, -14, 14, -23, 23], [-8, -14, 0, 14, 0, -29, 60, 0, -9, -9, 22, 22], [42, 13, 7, 0, -1, -1, -19, 7, -19, 0, -23, 0], [78, 0, -11, -46, -23, 23, 124, 11, 0, -29, 0, -4], [-53, 16, 0, -16, 0, -22, 100, -8, 15, 15, 37, 37], [55, 0, -7, -8, 43, -43, 63, 7, 0, 30, 0, -38], [21, 8, 0, -8, 0, -19, 15, 21, 16, 16, -29, -29], [-113, 8, 40, 0, -22, -22, 137, 40, 4, 0, -24, 0], [68, 23, 36, 23, 18, 0, 0, 0, 2, -2, -3, 3], [49, -58, 10, 0, 50, 50, -67, 10, 7, 0, 18, 0], [-112, 0, 1, 0, 16, 0, 0, 0, -9, 9, -72, 72], [0, -6, 2, -6, 60, 0, 0, 0, 2, -2, 20, -20], [109, -107, 0, 107, 0, 14, 48, 27, -1, -1, -2, -2], [114, -24, 22, -24, -51, 0, 0, 0, -16, 16, 6, -6], [12, 0, -2, 8, 34, -34, 4, 2, 0, 24, 0, -52], [-229, 0, 16, -23, 16, -16, -206, -16, 0, 8, 0, -35], [-36, 36, 0, -36, 0, 4, 168, -23, -18, -18, 0, 0], [108, 20, -28, 0, -80, -80, -126, -28, 25, 0, 18, 0], [-47, 68, -8, 0, 17, 17, 47, -8, 6, 0, 0, 0], [134, -60, 66, -60, 11, 0, 0, 0, 12, -12, 20, -20], [320, 25, 0, 0, -26, -26, -327, 0, -25, 0, 7, 0], [-21, 60, -53, 0, 28, 28, 73, -53, 1, 0, -52, 0], [40, 149, 16, 149, 65, 0, 0, 0, -4, 4, -39, 39], [161, -127, 29, 0, -3, -3, -96, 29, 10, 0, -65, 0], [36, -66, 0, 66, 0, -37, 57, 25, -7, -7, 30, 30], [103, 0, 52, 28, 50, -50, 75, -52, 0, 11, 0, 2], [95, 0, -2, -6, 75, -75, 101, 2, 0, -3, 0, 2], [53, 0, -13, 34, 22, -22, 19, 13, 0, -59, 0, 28], [-11, 0, 20, -89, 49, -49, 78, -20, 0, -26, 0, 15], [134, 0, 28, 92, 107, -107, 42, -28, 0, 6, 0, 42], [89, 0, -22, -151, -45, 45, 240, 22, 0, 14, 0, -51], [-49, 0, 18, 60, 0, 0, -109, -18, 0, 31, 0, 34], [19, -109, 29, -109, 33, 0, 0, 0, -12, 12, 32, -32], [-186, 8, 4, 0, -62, -62, 134, 4, -16, 0, 52, 0], [260, 0, -13, 90, -73, 73, 170, 13, 0, 22, 0, 1], [79, -79, 0, 79, 0, -2, 270, 83, -24, -24, 0, 0], [-19, 11, 0, -11, 0, 124, -348, 43, -16, -16, 8, 8], [-225, 0, -54, 36, -33, 33, -261, 54, 0, -3, 0, 2], [-144, 0, 33, -32, 12, -12, -112, -33, 0, 33, 0, 85], [-83, -2, 17, 0, 38, 38, 61, 17, 36, 0, 22, 0], [55, 164, 6, 0, 26, 26, -46, 6, 15, 0, -9, 0], [-28, 0, -7, 14, 5, -5, -42, 7, 0, 3, 0, 14], [-181, 88, 47, 0, 88, 88, 203, 47, -46, 0, -22, 0], [234, -28, 2, -28, 55, 0, 0, 0, 1, -1, 14, -14], [-62, 0, -45, -14, 18, -18, -48, 45, 0, 17, 0, -28], [3, -126, 63, 0, 21, 21, 15, 63, -57, 0, -18, 0], [396, -58, -13, -58, -119, 0, 0, 0, 28, -28, 5, -5], [-58, -32, 11, -32, 42, 0, 0, 0, -37, 37, -62, 62], [-461, 103, -2, 103, 27, 0, 0, 0, -22, 22, -43, 43], [-92, -49, 71, 0, 11, 11, 95, 71, 19, 0, -3, 0], [20, 11, 0, -11, 0, 100, 110, 47, 30, 30, -31, -31], [-42, 33, 0, -33, 0, 15, -304, 78, -13, -13, 9, 9], [130, -110, 0, 110, 0, -67, -343, 11, 0, 0, -20, -20], [-70, 199, -19, 0, 27, 27, 185, -19, -21, 0, -115, 0], [222, -55, -88, -55, -23, 0, 0, 0, 11, -11, -21, 21], [-79, 166, 13, 0, -1, -1, 45, 13, -52, 0, 34, 0], [-52, -9, -27, 0, 29, 29, -97, -27, 35, 0, 149, 0], [105, 161, 8, 0, 58, 58, -166, 8, 22, 0, 61, 0], [62, -22, 0, 22, 0, -85, 352, -64, 2, 2, -40, -40], [42, -101, 42, 0, 88, 88, -83, 42, -9, 0, 41, 0], [-56, 85, 44, 85, 67, 0, 0, 0, 24, -24, -5, 5], [32, -19, 0, 19, 0, 72, 138, -1, -2, -2, -13, -13], [15, 0, 14, 112, -5, 5, -97, -14, 0, 29, 0, 74], [-98, 204, 0, -204, 0, 38, 246, -48, -16, -16, -106, -106], [142, 0, -93, 238, -12, 12, -96, 93, 0, 43, 0, -23], [-61, 0, 79, 54, -22, 22, -115, -79, 0, 24, 0, 131], [-530, -142, -21, -142, -124, 0, 0, 0, -6, 6, -48, 48], [311, -118, 19, 0, 3, 3, -306, 19, 10, 0, -5, 0], [65, -35, 0, 35, 0, 10, -94, 45, 36, 36, -30, -30], [-2, 50, 0, -50, 0, 35, 721, 11, 16, 16, -48, -48], [-132, 137, 0, -137, 0, -80, 174, -105, 16, 16, -5, -5], [-208, 130, 0, -130, 0, -22, -120, -33, 2, 2, 78, 78], [-54, 0, -22, -52, -66, 66, -2, 22, 0, -11, 0, -103], [44, -33, 0, 33, 0, 5, -166, 96, -8, -8, -11, -11], [84, 178, -107, 0, 60, 60, -30, -107, -18, 0, -54, 0], [-52, -3, 13, -3, -44, 0, 0, 0, 31, -31, 43, -43], [-229, -161, 49, -161, 86, 0, 0, 0, 8, -8, -92, 92], [-115, 211, -44, 0, 100, 100, 198, -44, -8, 0, -83, 0], [-88, -88, -7, 0, 68, 68, 46, -7, 12, 0, 42, 0], [-1, 40, -159, 40, -125, 0, 0, 0, 56, -56, 32, -32], [-104, -196, -69, -196, -140, 0, 0, 0, 27, -27, -54, 54], [-76, 58, 86, 58, -118, 0, 0, 0, 18, -18, -42, 42], [263, 0, -19, 110, 109, -109, 153, 19, 0, 18, 0, 38], [-33, -21, -96, 0, 2, 2, -38, -96, 14, 0, 71, 0], [-182, 273, 0, -273, 0, -14, 284, -14, 5, 5, -91, -91], [-47, -58, 18, 0, -22, -22, -94, 18, 31, 0, 141, 0], [-199, 0, 68, 80, -26, 26, -279, -68, 0, -11, 0, 52], [89, 0, 10, 110, -32, 32, -21, -10, 0, 51, 0, 208], [-861, -96, 64, -96, 32, 0, 0, 0, 7, -7, 11, -11], [-334, 59, 2, 59, 86, 0, 0, 0, 10, -10, 37, -37], [72, -57, 0, 57, 0, 9, 313, -2, 39, 39, -15, -15], [373, -26, -86, 0, -19, -19, -413, -86, -8, 0, 40, 0], [-197, 111, 0, -111, 0, -44, 22, -55, 36, 36, 86, 86], [-269, 0, 47, 164, 62, -62, -433, -47, 0, -34, 0, -42], [-127, 0, 15, 166, -96, 96, -293, -15, 0, -89, 0, -42], [-227, 18, -39, 0, -18, -18, 181, -39, 39, 0, 46, 0], [-18, 123, 0, -123, 0, 49, -11, -82, 2, 2, -105, -105], [-350, -135, 78, -135, -83, 0, 0, 0, -20, 20, 21, -21], [-205, -192, -34, -192, -208, 0, 0, 0, 17, -17, 117, -117], [-237, 0, -19, 260, -69, 69, -497, 19, 0, -65, 0, 36], [-145, 146, 0, -146, 0, 109, 191, 137, 30, 30, -1, -1], [281, 0, 14, 66, 49, -49, 215, -14, 0, -63, 0, -93], [134, -107, 54, -107, 187, 0, 0, 0, 13, -13, -26, 26], [-205, -306, 76, 0, 89, 89, 159, 76, -78, 0, 46, 0], [-261, 189, 0, -189, 0, -12, 450, 37, 8, 8, 72, 72], [340, 103, 0, 0, 19, 19, -329, 0, 51, 0, -11, 0], [320, 0, -55, 304, -128, 128, 16, 55, 0, -58, 0, -178]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_333_i_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_333_3_i_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_333_3_i_a(:prec:=12)
    chi := MakeCharacter_333_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_333_3_i_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_333_3_i_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_333_i();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<2,R![576, -2832, 6962, -2222, 505, -696, 1604, -532, 90, -8, 18, -6, 1]>],Snew);
    return Vf;
end function;