
// Make newform 63.6.e.e in Magma, downloaded from the LMFDB on 25 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_e();".
// 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_e();".
// 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 := [86436, 2058, 28567, -91, 9122, 83, 98, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [307508418, -141627885, 3262309295, -47979268, 33153695, -1191820, 366059, -8905], [-251390874, -51985031, -2382173465, -14452616, -26314019, 388990, -279647, 1257], [-31645054854, 20796090, 7196875, 222588334, 2122285, 2163175, 56368, 22795], [-235881275616, 428233011339, -75468829240, 1109931296, -966332554, 27571040, -8468248, -341623], [-54979470, -23273922, -8054375, -232964210, -2375153, -2420915, 22795, -25511], [24613669710, 442767354393, -70438948615, 141447402185, 516927917, 1539409445, -23777815, 15589754]];
    Rf_basisdens := [1, 1, 9888988410, 156968070, 706356315, 9888988410, 706356315, 9888988410];
    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, 0, 0, 0], [-1, 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+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 := [[1, -1, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, -2, 1, 1, 1, -1, 0, 0], [53, -2, 45, 0, 1, 1, 6, 1], [0, 8, -107, -9, 0, 0, -8, 3], [97, 0, 0, 0, -1, -9, 76, 9], [0, 108, -92, 8, 0, 0, -108, 4], [-73, -220, -72, 1, 1, -15, 0, 0], [1796, -300, 1804, 8, 8, -20, 0, 0], [-250, 0, 0, 0, 103, 5, 254, -5], [0, -130, -1523, 94, 0, 0, 130, -24], [-3603, -1028, -3508, 95, 95, -9, 0, 0], [-1190, 0, 0, 0, 62, 142, 328, -142], [7049, 0, 0, 0, 93, 33, 816, -33], [-3874, 324, -3818, 56, 56, 28, 0, 0], [0, -1338, -3095, -13, 0, 0, 1338, -239], [0, 888, -9011, -163, 0, 0, -888, -71], [1514, -796, 1566, 52, 52, 240, 0, 0], [0, 2764, -2286, -193, 0, 0, -2764, -465], [-21414, 0, 0, 0, 24, -180, -3660, 180], [0, 3056, 14074, -143, 0, 0, -3056, 93], [11539, -2286, 11635, 96, 96, -786, 0, 0], [51006, 0, 0, 0, -1005, -129, 6432, 129], [-22548, 9508, -20966, 1582, 1582, -622, 0, 0], [-46842, 0, 0, 0, -863, 669, 464, -669], [0, 11428, -42794, 340, 0, 0, -11428, -1264], [-37037, -1320, -36272, 765, 765, -1527, 0, 0], [-9036, -3008, -7979, 1057, 1057, -475, 0, 0], [0, 11408, 16246, -575, 0, 0, -11408, 1917], [-38266, 0, 0, 0, -518, 2594, -5704, -2594], [16563, 0, 0, 0, -572, 2658, 8210, -2658], [-159546, 10216, -162257, -2711, -2711, 989, 0, 0], [0, -3972, 111034, -2326, 0, 0, 3972, 502], [130965, 0, 0, 0, 1921, -1551, -6028, 1551], [214904, 9708, 216046, 1142, 1142, -926, 0, 0], [0, 17286, 97781, -1485, 0, 0, -17286, -855], [0, -34880, 134124, 3314, 0, 0, 34880, -1206], [-158728, -3460, -158772, -44, -44, 3624, 0, 0], [34190, 0, 0, 0, -716, -4900, -11392, 4900], [-304796, -38476, -300818, 3978, 3978, 2550, 0, 0], [0, 46552, -216140, -2810, 0, 0, -46552, -82], [-20903, 0, 0, 0, -10369, 3291, -25304, -3291], [171402, -24536, 160096, -11306, -11306, 3230, 0, 0], [0, -45720, 201845, -3030, 0, 0, 45720, -822], [-601540, 0, 0, 0, -2966, -442, 6500, 442], [0, -53824, 237412, -3644, 0, 0, 53824, 5796], [78868, 0, 0, 0, -13246, -126, -65960, 126], [97318, 0, 0, 0, -3271, -5733, 35890, 5733], [0, 18216, -455117, 1937, 0, 0, -18216, -11387], [-84401, 92208, -75572, 8829, 8829, -8775, 0, 0], [276746, -10980, 270940, -5806, -5806, 11878, 0, 0], [-54114, 0, 0, 0, -17418, 15666, 56892, -15666], [0, 78384, 259031, -13875, 0, 0, -78384, -2007], [-32572, 0, 0, 0, 18313, -7843, 91808, 7843], [551230, 61220, 546658, -4572, -4572, 5736, 0, 0], [0, 44348, -576686, -9006, 0, 0, -44348, -7026], [0, -70506, 481465, 19925, 0, 0, 70506, -2861], [-434266, 143186, -444633, -10367, -10367, -1341, 0, 0], [0, 83968, -484176, 30143, 0, 0, -83968, -12237], [-410744, 0, 0, 0, 18470, -15926, -215252, 15926], [0, 83584, 689502, 21317, 0, 0, -83584, 8073], [605770, 0, 0, 0, 5171, -4919, -91658, 4919], [105751, 0, 0, 0, 40853, -8907, -43244, 8907], [0, 15456, -164408, -20806, 0, 0, -15456, 23410], [13897, 42576, 14959, 1062, 1062, 2718, 0, 0], [-800362, -60774, -780725, 19637, 19637, 15151, 0, 0], [727549, -67032, 775012, 47463, 47463, -1413, 0, 0], [-107891, 0, 0, 0, -1732, -14244, -110720, 14244], [0, -337640, -936764, 15196, 0, 0, 337640, -33172], [371122, 0, 0, 0, -19960, 31752, -86192, -31752], [0, 49232, 1661632, 29850, 0, 0, -49232, -21510], [-968948, 163424, -950450, 18498, 18498, -21462, 0, 0], [0, -175102, -452945, -60866, 0, 0, 175102, -12492], [-2302907, 18072, -2346248, -43341, -43341, 42543, 0, 0], [-2107185, 0, 0, 0, -7151, 23133, 59960, -23133], [-906964, 89616, -838166, 68798, 68798, 1390, 0, 0], [0, 273804, -2321654, 13640, 0, 0, -273804, -6620], [359901, -276704, 406460, 46559, 46559, -37725, 0, 0], [-605668, -32784, -650864, -45196, -45196, 36316, 0, 0], [0, -229584, -1286857, 76362, 0, 0, 229584, 690], [-954534, 0, 0, 0, 3942, -20802, -340992, 20802], [-45847, 0, 0, 0, -36003, -1131, 288516, 1131], [0, -9456, 1897420, 54626, 0, 0, 9456, 58258], [-349925, 0, 0, 0, -45661, -18033, 85624, 18033], [-597666, 290938, -551833, 45833, 45833, -7965, 0, 0], [-2782768, 35808, -2806793, -24025, -24025, -34061, 0, 0], [-597546, 0, 0, 0, 21762, -52362, 23004, 52362], [760451, -43120, 764433, 3982, 3982, 32454, 0, 0], [1754992, 0, 0, 0, 7502, -44582, -474644, 44582], [-3907469, 0, 0, 0, -7339, 6009, 128464, -6009], [-3207730, -126192, -3266660, -58930, -58930, -7010, 0, 0], [0, -66620, 3533566, -3962, 0, 0, 66620, 38594], [0, 152146, -5022309, 13970, 0, 0, -152146, -26472], [-2119088, 0, 0, 0, 22409, -59267, 426424, 59267], [2371595, 418724, 2370786, -809, -809, -15249, 0, 0], [1878702, 0, 0, 0, -137094, 28374, 575052, -28374], [4303648, 159554, 4323007, 19359, 19359, -9423, 0, 0], [0, 554064, 2536738, 38198, 0, 0, -554064, 86014], [3656201, -208660, 3617664, -38537, -38537, 39687, 0, 0], [1922635, 217620, 1830754, -91881, -91881, 52551, 0, 0], [1403608, 0, 0, 0, -77812, 83568, 207964, -83568], [0, 335258, -1396145, 70359, 0, 0, -335258, -101847], [0, 202328, 1552393, 45651, 0, 0, -202328, -52521], [-6391038, -255836, -6342656, 48382, 48382, -59518, 0, 0], [0, -957504, -3182434, 22605, 0, 0, 957504, 50673], [0, 335512, -1381425, 110360, 0, 0, -335512, -55872], [7604396, 0, 0, 0, 64807, -45709, 8792, 45709], [2745470, -1332180, 2821492, 76022, 76022, -75662, 0, 0], [0, 314376, 8134426, 43478, 0, 0, -314376, -81866], [4533759, 0, 0, 0, 228916, -70068, -53896, 70068], [2690239, -1515666, 2711413, 21174, 21174, -98304, 0, 0], [0, -889556, 10308588, -91018, 0, 0, 889556, 23346], [-7977450, 0, 0, 0, 25104, -148896, -116112, 148896], [0, 1078984, 4437510, 39311, 0, 0, -1078984, 69747], [-3710962, 0, 0, 0, -67779, 62175, 14994, -62175], [0, -597120, -7776890, -97858, 0, 0, 597120, 143662], [-2428891, 0, 0, 0, -103923, -149475, -170748, 149475], [0, -321788, -1109978, -24332, 0, 0, 321788, 40928], [5469836, 407526, 5232289, -237547, -237547, -4349, 0, 0], [4907484, 0, 0, 0, -182172, 72444, 1464528, -72444], [0, -49052, -4494822, -292933, 0, 0, 49052, 3723], [13441039, 0, 0, 0, -80530, 1638, 423712, -1638], [2035022, -480234, 2271853, 236831, 236831, -85451, 0, 0], [0, 1336968, -1529153, -21529, 0, 0, -1336968, -84725], [7072273, -201936, 7285096, 212823, 212823, -27261, 0, 0], [-11056734, 0, 0, 0, -70941, 41793, -476826, -41793], [-3172254, 1909552, -3276694, -104440, -104440, 24024, 0, 0], [-9052570, 669960, -9237818, -185248, -185248, 121576, 0, 0], [6503465, 0, 0, 0, -26832, 134298, 432678, -134298], [5809959, -1349468, 5954630, 144671, 144671, -188625, 0, 0], [0, 801188, -1705562, -39251, 0, 0, -801188, -165363], [-812490, 0, 0, 0, 344640, 72624, 479760, -72624], [-9620791, 904694, -9535683, 85108, 85108, 58926, 0, 0], [2588486, 0, 0, 0, 158076, 73104, 721260, -73104], [-2366116, 931500, -2747792, -381676, -381676, -38576, 0, 0], [-11563561, 0, 0, 0, -117354, -228882, -54816, 228882], [0, 1946620, -6354650, 72568, 0, 0, -1946620, -110212], [0, 95320, 1406826, -149134, 0, 0, -95320, -63006], [3522710, 0, 0, 0, 266245, -21865, -629686, 21865], [0, -564552, -13440416, -136162, 0, 0, 564552, 17062], [-2230708, 0, 0, 0, 358122, -47394, -2241084, 47394], [6253048, 651098, 6718903, 465855, 465855, -170391, 0, 0], [0, -1086640, -9846008, 134152, 0, 0, 1086640, 112632], [2875818, 0, 0, 0, -61497, -104421, -1916712, 104421], [0, 700836, -12283192, 19047, 0, 0, -700836, 78279], [-10558336, 0, 0, 0, 165676, -171304, 1924724, 171304], [-13512289, 0, 0, 0, 228663, -46701, -897048, 46701], [0, -1614784, -15138038, 115122, 0, 0, 1614784, 34986], [-6025136, 916224, -5808770, 216366, 216366, -334554, 0, 0], [-1210438, 379920, -1222538, -12100, -12100, 148636, 0, 0], [-3172546, -3087184, -2996016, 176530, 176530, -1974, 0, 0], [2282844, 0, 0, 0, 216126, -75198, -349668, 75198], [3428159, 0, 0, 0, -109719, -88059, 1958760, 88059], [-3082886, -479356, -3368564, -285678, -285678, 174006, 0, 0], [0, 416820, -19072660, -135591, 0, 0, -416820, 243177], [6986076, 0, 0, 0, -461070, -10746, -1737828, 10746], [8609701, -276048, 8668696, 58995, 58995, 74031, 0, 0], [18255982, 680048, 18437026, 181044, 181044, -331572, 0, 0], [-25060017, 0, 0, 0, 216580, -117612, -623392, 117612], [0, -1080638, -2572421, -21791, 0, 0, 1080638, -19093], [3736798, -1605760, 3527248, -209550, -209550, 428490, 0, 0], [-25149212, 0, 0, 0, 220946, -290918, 1662712, 290918], [69361, 0, 0, 0, 318860, -254322, -3875090, 254322], [-14619880, -1377000, -14480759, 139121, 139121, 291037, 0, 0], [0, 2196936, 5314078, -171148, 0, 0, -2196936, 136252], [0, -2788848, -16747196, 396632, 0, 0, 2788848, -86960], [0, 1007118, 8391761, 396954, 0, 0, -1007118, -531612], [0, 2693752, -17801970, -590209, 0, 0, -2693752, 581595]];
    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_e();".
// 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_e(:prec:=8)
    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_e();".
// 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_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_63_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![41616, 37944, 53772, -16260, 9190, -90, 103, -3, 1]>],Snew);
    return Vf;
end function;