
// Make newform 63.6.e.d in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_63_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_63_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_63_6_e_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_63_6_e_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 := [81, 9, 10, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [81, -10, 10, -1], [-81, 190, -10, 1], [14, 0, 0, 1]];
    Rf_basisdens := [1, 90, 90, 5];
    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_63_e();"
function MakeCharacter_63_e()
    N := 63;
    order := 3;
    char_gens := [29, 10];
    v := [3, 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_63_e_Hecke();"
function MakeCharacter_63_e_Hecke(Kf)
    N := 63;
    order := 3;
    char_gens := [29, 10];
    char_values := [[1, 0, 0, 0], [0, -1, 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 := 6;
    raw_aps := [[0, 1, 1, 0], [0, 0, 0, 0], [0, -19, -10, 0], [-14, -56, -14, -21], [212, -212, -23, -23], [-462, 0, 0, -28], [-1173, 1173, -132, -132], [0, 180, -277, 0], [0, -6, -69, 0], [3526, 0, 0, -700], [-1774, 1774, -715, -715], [0, -5545, 790, 0], [-1750, 0, 0, 868], [-6340, 0, 0, -1344], [0, -11478, 1635, 0], [1521, -1521, 1818, 1818], [-32904, 32904, -531, -531], [0, 21243, 4154, 0], [-21156, 21156, 919, 919], [1104, 0, 0, -2184], [25253, -25253, -7372, -7372], [0, -4502, 5193, 0], [52164, 0, 0, -4536], [0, -13333, 9356, 0], [104566, 0, 0, 196], [32581, -32581, 638, 638], [0, -46874, 2901, 0], [0, 76952, 1793, 0], [-91345, 91345, 21254, 21254], [-81734, 0, 0, -6916], [90232, 0, 0, 6328], [0, -157288, -1543, 0], [-31449, 31449, -9816, -9816], [868, 0, 0, -55160], [0, -108555, -40578, 0], [123814, -123814, -38631, -38631], [-210381, 210381, 40858, 40858], [0, -144768, -58801, 0], [398524, 0, 0, -45724], [0, 231877, -79082, 0], [-305240, 305240, -73075, -73075], [464982, 0, 0, 26096], [0, 322610, -15637, 0], [-49163, 49163, -118620, -118620], [240238, 0, 0, 39284], [29894, -29894, 65561, 65561], [-43188, 0, 0, -89656], [-768264, 0, 0, 66584], [-876600, 876600, 5517, 5517], [0, 23371, -89646, 0], [0, -1049649, 1128, 0], [340380, 0, 0, -196308], [698233, -698233, -50856, -50856], [415408, 0, 0, 69692], [0, -117773, -67364, 0], [-320290, 320290, 5227, 5227], [110085, -110085, -60738, -60738], [0, 1586562, -100111, 0], [-547857, 547857, 69190, 69190], [1272962, 0, 0, 156940], [-1480524, 1480524, 47935, 47935], [-1736854, 0, 0, -15680], [-592284, 0, 0, -20608], [-1647426, 1647426, 129963, 129963], [0, -2018963, -66084, 0], [0, -194739, 340446, 0], [0, 186724, 147363, 0], [-995538, 0, 0, 262892], [-56600, 56600, 298205, 298205], [-612486, 0, 0, 165116], [-42949, 42949, 88012, 88012], [0, -2869250, 148135, 0], [11582, -11582, 359393, 359393], [0, 135799, -249978, 0], [275704, 0, 0, -509012], [0, 3264522, 2643, 0], [852693, -852693, 624846, 624846], [0, 616439, -89954, 0], [0, -1512741, -301692, 0], [-2149535, 2149535, 125376, 125376], [-142548, 0, 0, -783552], [-95590, 0, 0, 416724], [1156878, -1156878, -1049589, -1049589], [1602678, 0, 0, -695884], [0, -1361110, 196129, 0], [0, 498744, -549135, 0], [-39006, 0, 0, -239148], [0, 302469, -305740, 0], [5286470, 0, 0, 136948], [4429392, 0, 0, -81088], [0, -189768, 868137, 0], [-7481870, 7481870, 134639, 134639], [-9085470, 9085470, -74219, -74219], [4048952, 0, 0, 681268], [0, 1086168, -530713, 0], [2576784, 0, 0, 1286376], [0, -6841511, -616094, 0], [-6073197, 6073197, -251292, -251292], [0, 257640, 824351, 0], [0, -8469833, 416814, 0], [-6641640, 0, 0, 358148], [-3817231, 3817231, -433190, -433190], [2912444, -2912444, -191519, -191519], [0, 4344467, 629924, 0], [-4264892, 4264892, -157617, -157617], [255105, -255105, -1133504, -1133504], [-5233004, 0, 0, 733040], [0, -3867981, 1727436, 0], [4420782, -4420782, 1259739, 1259739], [52654, 0, 0, 937636], [0, -2218442, 325965, 0], [928275, -928275, 282298, 282298], [-11604630, 0, 0, 849828], [-11170344, 11170344, -484541, -484541], [-5326816, 0, 0, 101640], [-10546737, 10546737, 21264, 21264], [4798388, 0, 0, 1303680], [-10534682, 10534682, -920653, -920653], [0, -4653627, 1705782, 0], [-8577564, 0, 0, -1350552], [4133511, -4133511, -2463938, -2463938], [5898174, 0, 0, 1063916], [0, 5342661, 1043550, 0], [10118796, -10118796, -1356063, -1356063], [0, -21473888, -343137, 0], [-12523422, 0, 0, 127344], [0, -4970617, 1943878, 0], [0, 5029950, 3541647, 0], [456176, 0, 0, -281736], [0, 9724307, 1272610, 0], [18763400, -18763400, 841283, 841283], [2092704, 0, 0, 2793000], [0, 14552166, 1774541, 0], [-4841086, 0, 0, 3589068], [0, 11489823, -1793592, 0], [-1771378, 0, 0, -2797284], [-5092091, 5092091, 2367422, 2367422], [-15485172, 15485172, -305369, -305369], [-17336522, 0, 0, -2253580], [2587083, -2587083, -4486596, -4486596], [3696812, 0, 0, 776496], [0, -18694451, 1181734, 0], [3960290, -3960290, -3478795, -3478795], [13089060, 0, 0, 1799280], [15827767, -15827767, 2736558, 2736558], [16784152, 0, 0, -714112], [-9949702, 0, 0, 1471428], [5391011, -5391011, -5234060, -5234060], [0, 12825496, -2605089, 0], [0, -11551266, -2570049, 0], [0, 5426847, -3750538, 0], [-4001634, 0, 0, -1996848], [-34815940, 0, 0, -622440], [0, -3705938, -1807865, 0], [12119728, -12119728, 4145115, 4145115], [-13433520, 0, 0, 2208864], [0, 1604602, -473103, 0], [0, 5984407, -2515544, 0], [9306682, 0, 0, -412496], [11867677, -11867677, 6119030, 6119030], [0, 25521280, 159937, 0], [9673298, 0, 0, -1505924], [993120, 0, 0, 5341112], [0, -1048164, -954915, 0], [28440435, -28440435, 48228, 48228], [-13107798, 13107798, -6016905, -6016905], [2527390, -2527390, 63009, 63009], [-19711233, 19711233, 883798, 883798]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_63_e_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_63_6_e_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_63_6_e_d(:prec:=4)
    chi := MakeCharacter_63_e();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_63_6_e_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_63_6_e_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_63_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![1296, 72, 40, -2, 1]>],Snew);
    return Vf;
end function;