
// Make newform 224.3.r.c in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_224_r();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_224_r_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_224_3_r_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_224_3_r_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 := [9604, 13720, 9800, 11256, 8040, 1400, 392, 140, -100, -28, 0, 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, 0, 0, 0], [776953996, 554967140, -5486280500, 592256728, 177107560, -136812774, 88185794, 8312290, -6636168, 1397522, -998230, 185087], [532857500, 32365480, 23118200, 28459298, 17604650, 2329950, 1347136, -467710, -374850, 52651, -13895, 9925], [4105950100, 2932821500, -22969617500, 3088145620, 906142300, -757254414, 441573890, 39668650, -36262548, 6959540, -4971100, 1063307], [-328244140, -397130300, -260890672, -331811440, -61020400, -9143106, -9190790, 3439850, 1425522, -61250, 43750, -47849], [-1032109070, 136569566, 97549690, 118480348, 75432304, 10651200, 5328386, -1301039, -1464615, 122126, -46921, 33515], [-10097578372, -7212555980, 34749182480, -7551097666, -2197406470, 1897920192, -1060486748, -93122680, 90419994, -16672019, 11908585, -2703596], [413603679776, 136892822920, 97780587800, 413550016298, 71568506870, 7789022850, 14550916744, -3672955450, -1880565750, 95938717, -88280465, 63057475], [289957457860, 84296468900, 235663193500, 296825119540, 48265430500, 11125655898, 8649690350, -3204789650, -1206155664, 16182740, -34797700, 42267851], [-39215176280, -10236754738, -32703518330, -40737809870, -6269750816, -1991859114, -1254655150, 505900669, 154642887, 3870755, 2833565, -5716498], [6820349200, 8284498796, 5462022580, 6923873500, 1160490016, 214099620, 195169100, -68302394, -29199870, 972650, -927136, 994220], [3850892837260, 2750637740900, 1791591829216, 2291747902264, 418021281160, 47467063518, 59864945378, -24485870270, -8664707646, 358186178, -255847270, 308950247]];
    Rf_basisdens := [1, 2812715640, 78928245, 7734968010, 227738280, 157856490, 7734968010, 108289552140, 54144776070, 4922252370, 773496801, 216579104280];
    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_224_r();"
function MakeCharacter_224_r()
    N := 224;
    order := 6;
    char_gens := [127, 197, 129];
    v := [3, 6, 4];
    // 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_224_r_Hecke();"
function MakeCharacter_224_r_Hecke(Kf)
    N := 224;
    order := 6;
    char_gens := [127, 197, 129];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0], [0, -1, 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, 1, 0, 0, -1, -1, 1, 0, 0, 0], [0, 1, 0, 2, 0, 0, 1, 0, 0, 0, 0, 0], [-11, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], [-2, 0, 1, 0, 2, 0, 0, 0, 0, 0, 1, -3], [0, -3, 0, 0, 0, 0, 0, 3, -1, -3, 0, 0], [0, -1, 0, 0, 0, 0, 0, 1, -1, -2, 0, 0], [11, 0, 3, 0, 0, -1, 0, 0, 0, 0, 0, 0], [0, -3, 0, -2, 0, 0, 5, 0, 0, 0, 0, 0], [0, 0, 0, 0, -13, 6, 0, 0, 0, 0, 1, 6], [31, 0, -1, 0, 0, 3, 0, 0, 0, 0, 0, 0], [0, 0, 0, 10, 0, 0, -4, -8, 10, -4, 0, 0], [0, -11, 0, 0, 0, 0, 0, 11, -8, 3, 0, 0], [1, 0, -4, 0, -1, 0, 0, 0, 0, 0, -4, 4], [0, -1, 0, -2, 0, 0, -4, 0, 0, 0, 0, 0], [0, 0, 0, 0, -73, 2, 0, 0, 0, 0, -1, 2], [0, 19, 0, -9, 0, 0, 6, 0, 0, 0, 0, 0], [0, 0, 0, -5, 0, 0, 14, 4, -5, 14, 0, 0], [-1, 0, 3, 0, 1, 0, 0, 0, 0, 0, 3, 2], [0, -1, 0, 0, 0, 0, 0, 1, 5, -10, 0, 0], [0, 0, 0, -15, 0, 0, 2, 12, -15, 2, 0, 0], [0, 0, 0, 0, -87, 0, 0, 0, 0, 0, 2, 0], [-59, 0, 2, 0, 0, -15, 0, 0, 0, 0, 0, 0], [-44, 0, -6, 0, 44, 0, 0, 0, 0, 0, -6, -5], [0, 19, 0, 0, 0, 0, 0, -19, -24, 4, 0, 0], [0, 5, 0, 0, 0, 0, 0, -5, 15, -19, 0, 0], [30, 0, 1, 0, -30, 0, 0, 0, 0, 0, 1, 1], [29, 0, -4, 0, 0, 25, 0, 0, 0, 0, 0, 0], [0, 0, 0, 37, 0, 0, -10, -20, 37, -10, 0, 0], [0, 3, 0, 0, 0, 0, 0, -3, -11, 18, 0, 0], [26, 0, 9, 0, -26, 0, 0, 0, 0, 0, 9, 9], [0, 0, 0, 9, 0, 0, -18, -36, 9, -18, 0, 0], [0, 0, 0, 0, -12, -11, 0, 0, 0, 0, 6, -11], [0, -43, 0, 6, 0, 0, 25, 0, 0, 0, 0, 0], [-133, 0, -5, 0, 133, 0, 0, 0, 0, 0, -5, 10], [0, -1, 0, 0, 0, 0, 0, 1, 56, -8, 0, 0], [0, 0, 0, 18, 0, 0, 1, -14, 18, 1, 0, 0], [0, 0, 0, 0, -83, 0, 0, 0, 0, 0, -6, 0], [0, 9, 0, -2, 0, 0, -23, 0, 0, 0, 0, 0], [-50, 0, 5, 0, 0, 8, 0, 0, 0, 0, 0, 0], [0, -19, 0, 0, 0, 0, 0, 19, -30, 7, 0, 0], [-32, 0, 6, 0, 32, 0, 0, 0, 0, 0, 6, 19], [-1, 0, -5, 0, 0, -45, 0, 0, 0, 0, 0, 0], [0, 33, 0, -53, 0, 0, 11, 0, 0, 0, 0, 0], [0, 0, 0, 35, 0, 0, 6, -28, 35, 6, 0, 0], [0, 0, 0, 43, 0, 0, -18, 4, 43, -18, 0, 0], [0, 37, 0, -25, 0, 0, 27, 0, 0, 0, 0, 0], [0, 0, 0, 0, 10, -13, 0, 0, 0, 0, -3, -13], [0, 0, 0, 0, 136, -19, 0, 0, 0, 0, 12, -19], [0, 0, 0, -44, 0, 0, -9, -42, -44, -9, 0, 0], [165, 0, -18, 0, -165, 0, 0, 0, 0, 0, -18, 28], [0, 0, 0, -40, 0, 0, 51, -2, -40, 51, 0, 0], [0, 0, 0, 0, 162, -25, 0, 0, 0, 0, 5, -25], [0, -5, 0, 18, 0, 0, -36, 0, 0, 0, 0, 0], [75, 0, 5, 0, -75, 0, 0, 0, 0, 0, 5, 26], [0, -37, 0, 0, 0, 0, 0, 37, 44, 8, 0, 0], [-123, 0, -6, 0, 123, 0, 0, 0, 0, 0, -6, 16], [325, 0, 14, 0, 0, -15, 0, 0, 0, 0, 0, 0], [0, 17, 0, 90, 0, 0, 1, 0, 0, 0, 0, 0], [-62, 0, 6, 0, 0, 8, 0, 0, 0, 0, 0, 0], [0, 0, 0, -44, 0, 0, -36, 64, -44, -36, 0, 0], [0, 63, 0, -43, 0, 0, 30, 0, 0, 0, 0, 0], [0, 0, 0, 0, 127, -2, 0, 0, 0, 0, -1, -2], [0, 0, 0, 0, -239, -44, 0, 0, 0, 0, -10, -44], [0, -13, 0, 0, 0, 0, 0, 13, 59, -6, 0, 0], [-109, 0, 27, 0, 0, 23, 0, 0, 0, 0, 0, 0], [0, -25, 0, -56, 0, 0, 4, 0, 0, 0, 0, 0], [39, 0, 17, 0, 0, 11, 0, 0, 0, 0, 0, 0], [-36, 0, -2, 0, 36, 0, 0, 0, 0, 0, -2, -41], [0, -79, 0, 0, 0, 0, 0, 79, -27, -71, 0, 0], [0, -13, 0, 22, 0, 0, -12, 0, 0, 0, 0, 0], [0, 0, 0, 0, 225, 28, 0, 0, 0, 0, 16, 28], [0, 0, 0, -16, 0, 0, 45, -30, -16, 45, 0, 0], [0, -63, 0, 0, 0, 0, 0, 63, -25, -27, 0, 0], [-200, 0, -18, 0, 200, 0, 0, 0, 0, 0, -18, 55], [0, 0, 0, 0, 22, 7, 0, 0, 0, 0, 13, 7], [0, 0, 0, 0, -174, -9, 0, 0, 0, 0, 7, -9], [-6, 0, -11, 0, 6, 0, 0, 0, 0, 0, -11, 25], [0, 0, 0, 96, 0, 0, 0, 0, 96, 0, 0, 0], [-183, 0, 10, 0, 0, 37, 0, 0, 0, 0, 0, 0], [0, 73, 0, -1, 0, 0, -53, 0, 0, 0, 0, 0], [-131, 0, -2, 0, 0, 41, 0, 0, 0, 0, 0, 0], [0, 57, 0, 0, 0, 0, 0, -57, -13, 5, 0, 0], [0, -47, 0, 0, 0, 0, 0, 47, -2, 39, 0, 0], [-473, 0, 25, 0, 0, 59, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 303, 46, 0, 0, 0, 0, -23, 46], [-261, 0, 1, 0, 0, -65, 0, 0, 0, 0, 0, 0], [0, 0, 0, -72, 0, 0, -44, -48, -72, -44, 0, 0], [0, -57, 0, 0, 0, 0, 0, 57, -2, -60, 0, 0], [0, -9, 0, -91, 0, 0, 18, 0, 0, 0, 0, 0], [0, -61, 0, -92, 0, 0, 28, 0, 0, 0, 0, 0], [0, 0, 0, -96, 0, 0, -3, 34, -96, -3, 0, 0], [0, -113, 0, 0, 0, 0, 0, 113, -84, 20, 0, 0], [0, 0, 0, 15, 0, 0, -18, -12, 15, -18, 0, 0], [0, 0, 0, 0, 80, -39, 0, 0, 0, 0, -42, -39], [-59, 0, -24, 0, 59, 0, 0, 0, 0, 0, -24, 36], [0, 37, 0, 0, 0, 0, 0, -37, 31, 29, 0, 0], [0, 0, 0, 0, 56, -47, 0, 0, 0, 0, 32, -47], [0, 0, 0, 4, 0, 0, 91, 30, 4, 91, 0, 0], [530, 0, 3, 0, -530, 0, 0, 0, 0, 0, 3, -3], [0, -93, 0, 83, 0, 0, -70, 0, 0, 0, 0, 0], [0, 0, 0, 0, -301, 18, 0, 0, 0, 0, -5, 18], [0, -39, 0, -92, 0, 0, -47, 0, 0, 0, 0, 0], [581, 0, -18, 0, -581, 0, 0, 0, 0, 0, -18, -52], [0, 0, 0, 54, 0, 0, 48, 24, 54, 48, 0, 0], [0, 0, 0, 0, 580, 17, 0, 0, 0, 0, 0, 17], [0, -145, 0, 97, 0, 0, 22, 0, 0, 0, 0, 0], [-235, 0, 0, 0, 0, -79, 0, 0, 0, 0, 0, 0], [0, 49, 0, 0, 0, 0, 0, -49, 43, 101, 0, 0], [-306, 0, -9, 0, 306, 0, 0, 0, 0, 0, -9, -55], [-161, 0, -23, 0, 0, 83, 0, 0, 0, 0, 0, 0], [0, 75, 0, 23, 0, 0, -30, 0, 0, 0, 0, 0], [0, 0, 0, 7, 0, 0, -58, 52, 7, -58, 0, 0], [441, 0, 18, 0, -441, 0, 0, 0, 0, 0, 18, 88], [0, 0, 0, -138, 0, 0, 0, -72, -138, 0, 0, 0], [0, -9, 0, 47, 0, 0, 62, 0, 0, 0, 0, 0], [0, 0, 0, 0, 129, 100, 0, 0, 0, 0, 40, 100], [0, 0, 0, -41, 0, 0, -42, -44, -41, -42, 0, 0], [583, 0, -9, 0, -583, 0, 0, 0, 0, 0, -9, 54], [47, 0, -37, 0, 0, 115, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 174, -9, 0, 0, 0, 0, -35, -9], [0, -35, 0, 47, 0, 0, -53, 0, 0, 0, 0, 0], [0, -77, 0, 0, 0, 0, 0, 77, -39, -34, 0, 0], [-6, 0, 56, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, -149, -66, 0, 0, 0, 0, 57, -66], [0, -37, 0, 0, 0, 0, 0, 37, 44, -24, 0, 0], [0, 0, 0, 37, 0, 0, -54, 220, 37, -54, 0, 0], [0, 0, 0, 0, -443, 40, 0, 0, 0, 0, -10, 40], [0, 61, 0, 5, 0, 0, -93, 0, 0, 0, 0, 0], [0, 0, 0, 135, 0, 0, -78, -156, 135, -78, 0, 0], [0, 61, 0, 0, 0, 0, 0, -61, 154, 15, 0, 0], [-377, 0, 29, 0, 0, 75, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, -438, -25, 0, 0, 0, 0, 17, -25], [-273, 0, -23, 0, 0, 67, 0, 0, 0, 0, 0, 0], [-44, 0, 24, 0, 44, 0, 0, 0, 0, 0, 24, 139], [0, 15, 0, 80, 0, 0, -48, 0, 0, 0, 0, 0], [855, 0, -11, 0, 0, -5, 0, 0, 0, 0, 0, 0], [-161, 0, -43, 0, 161, 0, 0, 0, 0, 0, -43, 82], [0, 0, 0, -56, 0, 0, 64, 160, -56, 64, 0, 0], [0, 0, 0, 0, -406, 131, 0, 0, 0, 0, 13, 131], [0, -1, 0, -155, 0, 0, -74, 0, 0, 0, 0, 0], [0, 0, 0, -200, 0, 0, 60, -80, -200, 60, 0, 0], [206, 0, 23, 0, -206, 0, 0, 0, 0, 0, 23, -47], [0, 0, 0, -48, 0, 0, -16, -288, -48, -16, 0, 0], [-323, 0, -22, 0, 0, -135, 0, 0, 0, 0, 0, 0], [-613, 0, 9, 0, 613, 0, 0, 0, 0, 0, 9, 134], [0, -39, 0, 0, 0, 0, 0, 39, 68, -41, 0, 0], [0, -177, 0, 0, 0, 0, 0, 177, -23, 122, 0, 0], [0, 0, 0, 0, 408, -111, 0, 0, 0, 0, -14, -111], [-90, 0, -3, 0, 0, -136, 0, 0, 0, 0, 0, 0], [0, 0, 0, 33, 0, 0, -10, 60, 33, -10, 0, 0], [0, -315, 0, 0, 0, 0, 0, 315, 26, -45, 0, 0], [0, 63, 0, 50, 0, 0, -116, 0, 0, 0, 0, 0], [0, 0, 0, 234, 0, 0, 72, 72, 234, 72, 0, 0], [0, 57, 0, 0, 0, 0, 0, -57, 323, 29, 0, 0], [0, 0, 0, 0, -229, -174, 0, 0, 0, 0, 7, -174], [-6, 0, -38, 0, 0, 56, 0, 0, 0, 0, 0, 0], [-803, 0, 64, 0, 803, 0, 0, 0, 0, 0, 64, -160], [0, 195, 0, 0, 0, 0, 0, -195, 37, 134, 0, 0], [17, 0, -10, 0, 0, -131, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, -2, -68, 1, -2, 0, 0], [0, -109, 0, 0, 0, 0, 0, 109, -157, -38, 0, 0], [-296, 0, 30, 0, 296, 0, 0, 0, 0, 0, 30, -149], [0, 165, 0, -170, 0, 0, 229, 0, 0, 0, 0, 0], [0, 31, 0, 111, 0, 0, 50, 0, 0, 0, 0, 0], [843, 0, -39, 0, -843, 0, 0, 0, 0, 0, -39, -14]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_224_r_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_224_3_r_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_224_3_r_c(:prec:=12)
    chi := MakeCharacter_224_r();
    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_224_3_r_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_224_3_r_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_224_r();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<3,R![4879681, 0, -1261339, 0, 231054, 0, -20135, 0, 1278, 0, -43, 0, 1]>],Snew);
    return Vf;
end function;