
// Make newform 810.3.g.k in Magma, downloaded from the LMFDB on 03 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_810_g();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_810_g_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_810_3_g_k();".
// 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_810_3_g_k();".
// 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 := [656100, 874800, 583200, -552420, 231804, -18792, 1458, -1350, 921, -54, 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], [-866523189915450, -1976060739252510, 1738554979846284, -488606626316952, 38281615930188, -3891751338015, 4981515908166, -1873864921524, 104197645485, 2774149290, 2732664981, -1875243545], [-514673191072440, -3374651669136840, -635889801951828, 302362724947734, -96577053626916, -36538823429478, -4340847960756, 1034227795947, -293504336784, -84332616198, -10289055060, 801101591], [514673191072440, 4731675923293020, 635889801951828, -302362724947734, 96577053626916, 36538823429478, 4340847960756, -1034227795947, 293504336784, 84332616198, 10289055060, -801101591], [-13941613256310270, -10660201940923830, -4781616191780274, 1963277075631168, -595414451140695, -112486169698992, -18728224777575, 8313264642702, -1619639566146, -253052027046, -18832079700, 10813781488], [809857776786660, 834168523429260, -4792172232064266, 1453610115391716, -156345435879993, -33937589503557, -19655990449719, 5012953239183, -404288852031, -103969950084, -25387385657, 3622731026], [42423545727242100, 3365547885870840, 2479719205493370, -1588967847139608, 1087697114716545, 63915908241492, 84861549207, -7713673859184, 2957021682174, 245744928891, -16169837742, -16157749007], [1007919072636390, 3303539986850910, -1979731934181828, -348415585518852, 140717902199823, -14930684399106, -15956005799406, -2763963071277, 347221587906, -67696741206, -33865345891, -5903758925], [-17294039977500900, -39403384557775110, 33458088034208070, -9875460177547812, 630410445269325, 29616968614149, 134503746792381, -34924088358249, 1746363892779, 438081208245, 169173040263, -24025140695], [-9850536006124770, -1323689487856290, -3848717489839236, 4144343169038616, -870310936875519, -8816718099276, 12716029565406, 19824337365018, -2346815029725, -33351976611, 60064310034, 28593720413], [3485658627091080, 1361235364554240, -4392386617669956, 3582765378266994, -641292252822288, 27037590897042, 8386289534322, 17343352267269, -1808354936952, 62594041086, 60311648106, 25717796021], [5946353206840080, 2909115091055340, -6157224025286976, 4988031259701762, -749127596045832, 33121669362138, 6070997035512, 22243226512101, -2101886170110, 68463029196, 65859946686, 31183125983]];
    Rf_basisdens := [1, 2035536381234270, 452341418052060, 452341418052060, 2035536381234270, 678512127078090, 2035536381234270, 678512127078090, 2035536381234270, 2035536381234270, 1357024254156180, 1357024254156180];
    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_810_g();"
function MakeCharacter_810_g()
    N := 810;
    order := 4;
    char_gens := [731, 487];
    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_810_g_Hecke();"
function MakeCharacter_810_g_Hecke(Kf)
    N := 810;
    order := 4;
    char_gens := [731, 487];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 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 := [[1, 1, 0, 0, 0, 0, 0, 0, 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, 0, -1, -1, 0, 0, 0, 0, 0, 0], [1, -1, 0, 0, 0, -1, -1, 1, 0, 0, 0, 0], [0, -1, 0, 0, 1, -1, 0, 1, 0, -1, 1, -1], [-2, -3, -1, 1, -1, -1, 1, 2, 1, 2, 0, 0], [0, -3, 1, -1, 0, -2, 0, -2, -1, 0, -1, -1], [3, -4, 0, 0, 1, -1, 1, -2, -1, 2, -1, 0], [0, 5, -4, 1, -2, 2, 0, 2, 0, 2, 4, 1], [5, 0, -1, -1, 1, 0, -1, 0, 0, 1, -1, 1], [7, 3, 3, 1, -4, -4, 1, 1, 1, 1, 0, 0], [-6, 0, 1, -3, 4, 0, -1, 0, 0, 4, 1, 3], [-9, 7, 0, 0, 2, -2, 0, 2, 0, -2, 3, 5], [-4, -6, 8, -5, -2, -2, -1, 2, -1, 2, 0, 0], [14, -13, 0, 0, -1, 1, 0, -5, 0, 5, 4, 2], [0, 26, 1, -4, -3, 0, 0, 0, 0, 3, -1, -4], [38, 0, -1, -1, 0, 0, -1, 0, 0, 0, -1, 1], [0, -1, -4, -1, -1, -1, 3, -1, 3, -1, 0, 0], [-17, 0, -2, 5, 10, 0, 1, 0, 0, 10, -2, -5], [-13, 12, 0, 0, 1, -1, -1, 11, 1, -11, 0, -6], [0, 2, 4, -2, 3, -6, 0, -6, -4, -3, -4, -2], [19, -16, 0, 0, -3, 3, -2, -6, 2, 6, -1, -4], [0, 31, 6, 2, -3, -4, 0, -4, 0, 3, -6, 2], [12, 16, -6, 6, 4, 4, -2, -11, -2, -11, 0, 0], [-42, 1, -11, 6, 10, 1, 6, -1, 0, 10, -11, -6], [-36, 29, 0, 0, 7, -7, 1, 3, -1, -3, 1, -5], [20, 19, -9, -10, -1, -1, -3, 1, -3, 1, 0, 0], [0, 29, -3, 2, 0, 5, 0, 5, 3, 0, 3, 2], [29, -35, 0, 0, 6, -6, -2, 3, 2, -3, 0, 6], [-9, -3, 14, -13, 6, 6, -2, -15, -2, -15, 0, 0], [-32, 3, 1, -1, 2, 3, 4, -3, 0, 2, 1, 1], [22, 19, 20, -14, -3, -3, 1, 6, 1, 6, 0, 0], [0, 17, -11, 3, 14, 13, 0, 13, 0, -14, 11, 3], [0, 6, -9, -8, 4, 6, 0, 6, 3, -4, 9, -8], [61, -13, -2, -6, -10, -13, 5, 13, 0, -10, -2, 6], [0, -3, -4, -12, -3, -3, -8, -10, -8, -10, 0, 0], [-16, 14, 0, 0, 2, -2, 5, -17, -5, 17, -19, 1], [32, 20, 14, 13, -12, -12, 2, -16, 2, -16, 0, 0], [49, -57, 0, 0, 8, -8, 1, 13, -1, -13, -16, -6], [0, 89, 2, 7, -6, 14, 0, 14, 7, 6, -2, 7], [99, 19, -15, 6, -4, 19, 6, -19, 0, -4, -15, -6], [45, 13, 5, -6, 0, 13, -7, -13, 0, 0, 5, 6], [-31, 46, 0, 0, -15, 15, -1, 3, 1, -3, -3, 3], [9, 1, -12, 10, -8, -8, 2, -6, 2, -6, 0, 0], [0, 59, -5, -3, 18, -20, 0, -20, 5, -18, 5, -3], [97, -31, 10, -6, 4, -31, -3, 31, 0, 4, 10, 6], [-89, 99, 0, 0, -10, 10, 7, -16, -7, 16, 6, -1], [11, 33, -19, -9, 22, 22, 1, -22, 1, -22, 0, 0], [0, 119, -2, 11, -2, -8, 0, -8, -10, 2, 2, 11], [44, -23, 0, 0, -21, 21, 0, -8, 0, 8, -5, -3], [0, 63, 20, -5, -6, -7, 0, -7, -6, 6, -20, -5], [170, 10, -2, -13, -2, 10, -1, -10, 0, -2, -2, 13], [101, -21, -11, 4, -15, -21, 5, 21, 0, -15, -11, -4], [-37, -17, -6, -10, 20, 20, -2, -11, -2, -11, 0, 0], [145, -135, 0, 0, -10, 10, 4, 6, -4, -6, -15, -9], [0, -55, 7, -18, 36, -1, 0, -1, -21, -36, -7, -18], [157, -22, 3, 21, 12, -22, 7, 22, 0, 12, 3, -21], [-55, -43, 3, -19, 12, 12, -16, -6, -16, -6, 0, 0], [78, -22, 30, -5, -40, -22, -1, 22, 0, -40, 30, 5], [-116, 103, 0, 0, 13, -13, -2, -12, 2, 12, -17, -10], [83, -75, 0, 0, -8, 8, -6, 32, 6, -32, 41, -7], [-43, -87, -29, 20, -44, -44, -5, 18, -5, 18, 0, 0], [-63, -17, 1, 22, 4, -17, -3, 17, 0, 4, 1, -22], [-18, -27, 0, 0, 45, -45, 7, 19, -7, -19, -21, -45], [-73, -89, 27, 3, -16, -16, 4, -22, 4, -22, 0, 0], [132, 21, 2, 9, 12, 21, -16, -21, 0, 12, 2, -9], [-211, -205, 38, -28, 6, 6, 0, -19, 0, -19, 0, 0], [-56, -32, -31, -13, 24, 24, -3, 8, -3, 8, 0, 0], [0, 207, -9, 23, -8, 22, 0, 22, -4, 8, 9, 23], [-68, 52, 0, 0, 16, -16, 12, -15, -12, 15, 0, -10], [0, 172, 15, 6, -3, -33, 0, -33, 3, 3, -15, 6], [27, 4, 1, -35, -23, -23, 6, 3, 6, 3, 0, 0], [5, -10, 0, 0, 5, -5, 3, 22, -3, -22, 8, 14], [0, 238, 30, -4, -42, 14, 0, 14, 6, 42, -30, -4], [3, -24, 0, 0, 21, -21, 4, 1, -4, -1, -63, -31], [0, -10, -14, 2, -2, -2, 0, -2, 11, 2, 14, 2], [-127, -97, -28, 54, 30, 30, 12, 10, 12, 10, 0, 0], [278, -8, 20, 9, -7, -8, 16, 8, 0, -7, 20, -9], [0, 42, -11, 13, -13, 58, 0, 58, 6, 13, 11, 13], [0, 20, 22, 0, -18, -31, 0, -31, -1, 18, -22, 0], [36, 2, -9, 19, 7, 2, 8, -2, 0, 7, -9, -19], [-100, -5, -53, 45, 29, -5, 20, 5, 0, 29, -53, -45], [105, -43, 0, 0, -62, 62, -4, 11, 4, -11, 39, 15], [0, 4, 1, 18, -9, 30, 0, 30, 8, 9, -1, 18], [62, -64, 0, 0, 2, -2, -18, 36, 18, -36, 74, 25], [0, -121, -14, -7, -27, 31, 0, 31, 30, 27, 14, -7], [-165, -144, 19, -33, 21, 21, 13, -13, 13, -13, 0, 0], [259, -5, -6, 13, 51, -5, 8, 5, 0, 51, -6, -13], [-93, 129, 0, 0, -36, 36, -1, -20, 1, 20, 3, -7], [-275, -256, 15, -29, 19, 19, 0, 10, 0, 10, 0, 0], [0, 94, 22, -48, 31, -8, 0, -8, -16, -31, -22, -48], [-199, -165, -17, -7, 34, 34, -11, -21, -11, -21, 0, 0], [196, 40, 11, -6, 25, 40, 4, -40, 0, 25, 11, 6], [0, 15, -34, -33, -18, 19, 0, 19, -20, 18, 34, -33], [-38, 68, 0, 0, -30, 30, 14, -23, -14, 23, 26, 29], [0, -292, -10, -14, -27, 15, 0, 15, -12, 27, 10, -14], [67, -57, 45, -20, -6, -57, -14, 57, 0, -6, 45, 20], [-226, 143, 0, 0, 83, -83, 19, -20, -19, 20, -50, -31], [189, 92, -25, -25, 21, 92, -4, -92, 0, 21, -25, 25], [-132, -64, 3, -30, 68, 68, 0, 43, 0, 43, 0, 0], [-158, -148, 34, -20, 10, 10, -15, 18, -15, 18, 0, 0], [-53, 68, 0, 0, -15, 15, -31, 7, 31, -7, 22, 21], [0, -197, 8, -6, -8, -13, 0, -13, -24, 8, -8, -6], [-50, 46, 8, -34, 31, 46, -6, -46, 0, 31, 8, 34], [300, 271, 38, -6, -29, -29, -2, -39, -2, -39, 0, 0], [-158, -120, -41, 22, 38, 38, 30, 11, 30, 11, 0, 0], [-68, 57, 0, 0, 11, -11, -12, -6, 12, 6, -43, -47], [0, 58, -34, 30, -19, 44, 0, 44, 14, 19, 34, 30], [78, 65, 20, 2, 18, 65, 22, -65, 0, 18, 20, -2], [-41, -102, 16, 51, -61, -61, -4, 3, -4, 3, 0, 0], [-2, 58, 0, 0, -56, 56, -7, -55, 7, 55, -1, 1], [-130, -112, 2, -32, 18, 18, 13, 13, 13, 13, 0, 0], [0, -15, -45, -3, -3, -16, 0, -16, 3, 3, 45, -3], [-56, -147, 8, 11, 7, -147, 22, 147, 0, 7, 8, -11], [8, 13, -31, 44, 7, 13, -13, -13, 0, 7, -31, -44], [-161, 92, 0, 0, 69, -69, 3, -49, -3, 49, -48, -7], [193, 120, 88, 9, -73, -73, -19, -4, -19, -4, 0, 0], [-202, 255, 0, 0, -53, 53, 4, 15, -4, -15, 59, 25], [0, 38, 45, -16, -67, -42, 0, -42, -8, 67, -45, -16], [284, -34, 19, 35, -5, -34, 22, 34, 0, -5, 19, -35], [54, -55, 0, 0, 1, -1, 5, -71, -5, 71, -103, -1], [-216, -222, 55, -71, -6, -6, 7, -66, 7, -66, 0, 0], [140, -146, 0, 0, 6, -6, 23, 3, -23, -3, 97, 9], [-110, 1, -35, -41, 42, 1, -32, -1, 0, 42, -35, 41], [264, 13, -1, -29, 68, 13, 9, -13, 0, 68, -1, 29], [0, -348, 11, -26, -41, 79, 0, 79, -4, 41, -11, -26], [0, -69, 24, -39, 41, -29, 0, -29, -44, -41, -24, -39], [-42, -82, 38, -15, -40, -40, -45, -44, -45, -44, 0, 0], [-231, 251, 0, 0, -20, 20, 28, -27, -28, 27, -26, -12], [0, -237, -76, 25, 27, -21, 0, -21, -8, -27, 76, 25], [249, -343, 0, 0, 94, -94, 22, 63, -22, -63, 37, -52], [-25, -50, 38, -23, -27, -50, -1, 50, 0, -27, 38, 23], [-157, -105, -1, -57, 52, 52, 3, 1, 3, 1, 0, 0], [301, 51, -70, -7, 11, 51, 22, -51, 0, 11, -70, 7], [0, 85, 40, 15, 40, 20, 0, 20, 50, -40, -40, 15], [-144, 145, 0, 0, -1, 1, 18, 59, -18, -59, -18, -50], [87, 135, -31, -79, 48, 48, -38, -26, -38, -26, 0, 0], [-299, -370, 21, 51, -71, -71, 2, 19, 2, 19, 0, 0], [0, -557, 22, -29, 1, 61, 0, 61, 18, -1, -22, -29], [-6, 30, 40, 38, 4, 30, 2, -30, 0, 4, 40, -38], [270, 76, -21, 63, -12, 76, -17, -76, 0, -12, -21, -63], [448, -518, 0, 0, 70, -70, 27, 26, -27, -26, 36, -41], [-99, -88, -10, 49, 11, 11, 47, -40, 47, -40, 0, 0], [0, -349, 48, 14, 26, -41, 0, -41, 9, -26, -48, 14], [0, 191, -61, -35, 77, 48, 0, 48, 31, -77, 61, -35], [-23, 8, 0, 0, 15, -15, 44, 83, -44, -83, 29, -59], [-243, -230, 5, 19, 13, 13, -19, -9, -19, -9, 0, 0], [0, -18, 135, -30, -66, -133, 0, -133, -41, 66, -135, -30], [176, -148, 0, 0, -28, 28, -46, 31, 46, -31, 34, 43], [165, 157, -67, -17, -8, -8, -19, 18, -19, 18, 0, 0], [324, -47, 43, 53, -76, -47, 45, 47, 0, -76, 43, -53], [10, 10, 0, 0, -20, 20, 16, -7, -16, 7, -60, -27], [236, 296, 13, 19, 60, 60, -15, -100, -15, -100, 0, 0], [385, 310, 72, 39, -75, -75, -1, 31, -1, 31, 0, 0], [-298, 42, 9, 12, -85, 42, 0, -42, 0, -85, 9, -12], [0, 46, 70, -12, 16, -70, 0, -70, -46, -16, -70, -12], [0, 94, 21, 43, -31, 26, 0, 26, -28, 31, -21, 43], [-332, -292, 116, -88, 40, 40, -43, -36, -43, -36, 0, 0], [507, 21, -36, -35, -23, 21, 34, -21, 0, -23, -36, 35], [143, 67, 92, -77, -76, -76, -44, -56, -44, -56, 0, 0], [-57, 63, 0, 0, -6, 6, -14, -65, 14, 65, -75, 23], [44, -35, -85, 94, -79, -79, 4, -38, 4, -38, 0, 0], [121, 99, 10, -14, -71, 99, 13, -99, 0, -71, 10, 14], [-352, -259, 37, 65, 93, 93, 29, -39, 29, -39, 0, 0], [166, -174, 0, 0, 8, -8, -24, 17, 24, -17, 5, -82], [-336, 35, -50, -11, -49, 35, -20, -35, 0, -49, -50, 11], [-309, -367, 12, 44, -58, -58, -21, -3, -21, -3, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_810_g_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_810_3_g_k();".
// 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_810_3_g_k(:prec:=12)
    chi := MakeCharacter_810_g();
    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_810_3_g_k();".
// 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_810_3_g_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_810_g();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![338449609, -167118348, 41259528, 53701934, 23901939, 2545176, 89882, -12756, 7479, 544, 18, -6, 1]>,<11,R![1018990, -913818, 87432, 5228, -621, -6, 1]>],Snew);
    return Vf;
end function;