
// Make newform 29.6.a.a in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_29_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_29_6_a_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_29_6_a_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 := [10, -27, -34, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-17, 3, 1, 0], [-17, -3, 1, 0], [-25, -67, -1, 2]];
    Rf_basisdens := [1, 3, 3, 3];
    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_29_a();"
function MakeCharacter_29_a()
    N := 29;
    order := 1;
    char_gens := [2];
    v := [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;

function MakeCharacter_29_a_Hecke(Kf)
    return MakeCharacter_29_a();
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, 0, -1, 0], [-7, 1, 1, 0], [-15, -2, 6, 4], [-58, 0, -4, -12], [-41, -21, -29, -20], [-85, -10, -38, 60], [44, 14, 50, -4], [-540, 168, -80, 116], [-368, 146, 14, -140], [-841, 0, 0, 0], [-4849, 485, -319, -92], [-2712, -712, 544, 40], [-682, -366, 1950, -804], [-4969, -341, 1603, 772], [5979, -1675, 449, 72], [2529, 1898, -2258, 628], [-2780, 3098, -2466, -140], [11164, -3142, 3582, -2396], [-2476, -4428, 4676, -1032], [-12234, 3250, -3598, -96], [-19500, 3784, -2200, -1504], [-25087, -1457, -5901, 2864], [15168, -5038, 2566, -1108], [29082, -842, -7382, 4380], [-8790, 3962, 7150, 7180], [29024, 10240, 10656, 1592], [-126, 5562, 538, -4928], [10214, 2960, -17908, 8260], [51629, -4202, 10454, 4372], [73370, 316, 19636, -6224], [-43508, 324, -11732, -16772], [-128448, -10964, -15404, 12908], [18564, -20868, 4940, 712], [-220296, -16114, 47010, -796], [-111029, 11630, 4514, -12548], [-168558, -5204, -4432, -6660], [110678, 40726, -38702, 36900], [37871, 10595, -69157, 14624], [-124462, 25146, 11474, 8616], [115042, -37100, -756, -30072], [-289286, 18450, -11326, 2176], [260903, 9590, 7118, -4124], [-247740, -54552, 26520, -20380], [590770, 29890, -21970, -30132], [-323566, -37144, 31032, 38192], [-437482, 52236, 29512, -3772], [-633021, -20349, -541, 8072], [288362, 10958, 46446, -6264], [113230, -69446, 74018, -88688], [-142082, 42854, -90758, -45956], [668479, 76116, -166812, 33080], [364172, 102254, -31518, 84916], [-198751, -66544, 150464, -71488], [607757, 85097, -100415, -7296], [-510039, -39592, -12004, -17584], [337467, 67205, -159175, 36204], [-214084, -104138, 69898, -36060], [-312631, -91869, 93703, 80676], [-768482, 215512, -75032, -24208], [-667501, 51220, 27148, 5304], [-14552, -31478, -87698, 22628], [473782, -175952, 102608, -110232], [-1249605, -95225, -219073, -2612], [942996, -214120, 91112, 38164], [-2015979, -45364, -38800, -81272], [726392, -24518, -178578, 21268], [68287, 123419, -69869, 24464], [-399172, -47282, -49974, -123028], [438138, 8742, 247094, 121888], [169805, -218494, 57158, -7580], [-986082, 136292, -100404, 163352], [2180809, 52507, 216231, 10352], [1662980, -31916, -196980, 20524], [235899, -326902, -265614, 54172], [-1164512, -233028, 380196, 155604], [236222, -146720, 444252, -205844], [-825384, 330640, -233400, -128912], [-1400953, -20166, -69766, 113804], [-344365, -56456, 516752, 37504], [-1203194, 191172, -402940, -174608], [-874886, -205486, -161414, 380776], [750036, -9130, -9014, -175092], [2491716, 213746, 89294, 36268], [-407088, 120544, -164560, 176752], [658760, 162366, -59406, -380644], [-401456, -9480, -623896, 139604], [553214, -204344, 739080, 261064], [1407926, 498868, 471468, -38072], [693314, -212800, 284224, 94960], [2595560, -267310, 637062, -8380], [-1583129, -144005, 495475, -133036], [2504369, -31789, -527289, 63540], [2396370, 445372, -34896, 142324], [-2196459, -30295, 710897, -53076], [-134664, 53642, -1018690, 22572], [-1288631, -170141, -559337, -216924], [-4888179, -420986, -648614, -212628], [3971095, 271024, -123764, 8528], [-4589640, -439140, 397812, 136880], [897504, 275416, 554696, 197464], [-759978, -134572, 335368, -221764], [7213742, 326168, -180472, 282976], [-5540877, -592393, 277695, 453056], [2608682, 155032, -610928, 14672], [-3289748, 149156, -684100, 267752], [2819084, 240362, -159954, -602972], [-5921080, -694794, -607374, -616436], [-7558557, 1424888, -599540, 290368], [-3613603, -332861, 209191, 455320], [-2138362, 1437294, -1029110, 484836], [1326313, 392851, -326201, -387804], [6724481, -631646, 1077274, 56988], [-1935068, 794028, -368996, 422952], [-9064445, -331825, 199271, -108344], [-4214554, 378266, 1343898, -460328], [-2908012, -862462, 848310, -208436], [-8011446, -202128, -887412, 135252], [9546748, 221690, 772326, 1008276], [-1261590, -301302, 344478, -727708], [3642769, -941251, 943461, 556056], [7087470, 754448, 639872, 386272], [9611625, -188884, 882540, -318840], [3599254, -221100, -821532, 428136], [-5015320, -46404, 227772, -595368], [-3763652, 812072, 573880, 597112], [-1824273, 1561166, -2077942, 28940], [2931283, -1615082, 250258, 264188], [11763770, -606078, 72834, 808088], [2890228, -75376, 1792816, -695356], [5766440, -42500, 1362020, 593488], [-7660099, 365549, -1512579, 228672], [4999200, 1752232, -353712, 1356980], [-3504324, -1217676, 2293324, 542964], [2464020, -616454, -1737562, -812044], [-9401918, -1511916, 1249804, -734808], [-5092256, 1576902, 951218, -522796], [4649010, -670118, -2464522, 125660], [-1362770, 1444806, 297782, -190360], [-15017580, -1308038, 1469534, -170636], [-3596776, 81604, -2518972, -911552], [6242934, -1813572, 205480, -852708], [-5518349, 684970, -2940218, 1649604], [489236, 190924, 2084164, 163868], [7147179, 1195067, 2350811, 660208], [-1658748, -243782, -2499890, 237212], [-32261, -403511, 993533, 1352008], [13207014, 577248, 95376, -466968], [-14420783, -408308, 1984224, -887400], [7873845, 109105, 1496713, -2143692], [6263654, 1081678, -808474, -1249488], [1071497, 867954, 2451846, 1024756], [3966250, -2304, -207544, -1868168], [-4662850, 2279640, -2617980, 810708], [-3429229, -273759, 4262045, -1472244], [-11863416, 1866712, 2283848, -873900], [14099209, -208741, -103889, -880380], [2882802, -603694, -4188918, -680840], [-10916126, 3135960, -939272, 1317840], [6589950, -2287736, -993096, -1425952], [-9908051, -484866, -2160914, -2871500], [13837507, 2535163, 2158555, -1037092], [-7214801, -2320216, 4468296, -474416], [37019, -892851, 4346617, -112312], [1416264, 1950384, -381104, 1817020], [-12942847, 1810376, 1997828, 1077760], [-4377009, 3389073, -1894883, -321056], [-29522630, -1273386, 1662254, 204096], [20313312, 2474620, -160020, 2619392]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_29_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_29_6_a_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_29_6_a_a(:prec:=4)
    chi := MakeCharacter_29_a();
    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_29_6_a_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_29_6_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_29_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![196, 168, -69, 0, 1]>],Snew);
    return Vf;
end function;