
// Make newform 82.6.a.b in Magma, downloaded from the LMFDB on 27 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_82_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_82_6_a_b();".
// 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_82_6_a_b();".
// 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 := [-12280, -5166, -492, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-2800, 88, 27, -1], [-4920, -1522, -43, 4]];
    Rf_basisdens := [1, 1, 65, 65];
    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_82_a();"
function MakeCharacter_82_a()
    N := 82;
    order := 1;
    char_gens := [47];
    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_82_a_Hecke( : Kf := Kf)
    return MakeCharacter_82_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]];
    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 := [[-4, 0, 0, 0], [2, -1, 0, -1], [2, 0, -2, -3], [38, -7, -3, -8], [2, -13, 3, -16], [-226, 2, -2, -12], [410, -4, -10, 6], [-434, 105, 28, -33], [2608, 48, 84, 50], [3278, -142, 16, -164], [1688, -68, -194, -104], [-998, 316, 316, -259], [1681, 0, 0, 0], [-2496, 438, -78, -214], [-1934, 783, 156, 119], [5494, -410, 150, -26], [-12916, 1440, 252, -398], [-29482, 674, 244, -480], [-3514, -267, -699, 2100], [-362, -1203, -1584, -1585], [-6274, -328, -306, -1349], [13798, -1355, 1444, 317], [15516, 3796, -530, 3778], [-3350, 708, -1378, -2412], [-45094, 4596, 1408, 1412], [-5642, 7070, 1288, 7274], [-24516, 3970, -870, 9112], [42748, -408, -4042, 2682], [-47466, -1350, 2512, 2494], [10238, -40, -3158, -5135], [-7848, -5432, 4954, -3648], [135448, -4454, -248, -11202], [16394, -44, 7262, -3134], [-112420, 112, 2138, 7500], [-186162, 18, 3436, -4192], [-5650, -12031, -2100, 8551], [-121586, 15278, -420, -586], [16084, 8540, 8130, -10462], [-1602, 1101, -7611, -15906], [-166498, 10860, -516, 21148], [113494, -4483, 3025, 6230], [-250778, -12158, -1142, -14098], [192778, 1307, 21051, 8334], [73458, -10436, 5908, -462], [570926, -22246, 880, 9724], [193778, 18087, 6087, 27234], [365574, -1255, -5999, -44110], [-10984, 31256, -3620, 6936], [696838, 32229, -13644, 9041], [-118114, 48466, -2908, -15378], [16866, 45560, 23706, 42274], [518238, 37877, -22608, 43225], [734970, -23334, -22172, 15376], [296816, -36498, 15640, 1818], [586106, 25236, 24378, -48692], [110354, 17099, 13896, -24199], [-785754, -70806, 13944, -48288], [230168, -16156, -26576, 23502], [271722, -110788, -13990, -58709], [-691614, 96660, 852, 43020], [-355668, 59240, -11266, 35680], [18854, -69770, -49180, -74132], [-535568, -130818, 3830, -133384], [303450, -16221, -65885, -8728], [269778, -25448, 11140, 91998], [-512338, 22974, -29942, 135936], [-1097662, 139187, 34151, 102938], [-410778, 77424, 55408, -97307], [696510, -46523, 13564, -12509], [146346, -11904, -2378, -156395], [767678, 106352, 93380, 54963], [-2111688, -92184, -42040, -114116], [901484, -55642, 19230, -39254], [1355654, 66808, 17572, 88300], [-199508, -203400, -69304, -103570], [200482, 61707, -35533, -117300], [-810586, -209812, 17744, -169560], [163318, 54742, -6062, 147668], [3126662, -113640, -52280, -54927], [2038310, -219352, -20058, -201155], [-3536016, -61790, -57698, 114118], [1552190, 320658, 88086, 267186], [2884732, 101046, -93436, 54528], [-1039934, -272016, -153988, -174616], [2303838, -132219, -31167, -99586], [-538248, 192986, -90862, -74008], [-3883638, 34210, -45764, 16924], [4240314, 73356, -57718, 20418], [1638674, 3292, 130544, -62411], [1517910, -205899, -19228, 111291], [-2697548, -260508, 39780, -86818], [-1021186, -12631, 56593, 22984], [-105932, 122458, 123352, -204058], [-140572, -138684, 53872, 48930], [-7290502, -125121, -67640, 41195], [2181094, -414639, 52544, -7863], [-4090834, 156874, 18134, 137044], [-1649118, 163524, -63704, -118126], [-721972, -49816, 159668, 158972], [-1400006, 502624, 56962, 598217], [2110438, -225359, -1056, -249129], [-1698506, -322230, -194242, 79782], [-6433278, 107595, -9381, -88932], [1498654, -296768, -96960, -228023], [3573690, 397067, -38893, 191680], [2306594, -272412, -139230, -120906], [-2477862, -412925, -208025, -25070], [1055770, -45748, 67986, -446028], [-7441456, 227456, 136026, -71776], [2085010, 10228, 8626, 146858], [4916020, 272710, 82836, -116676], [2023970, -224568, -250154, -373483], [353754, -215928, 157856, 425284], [-1532460, -311216, -395874, -15764], [-5363376, 626232, 199954, 458686], [2600322, 371292, -254592, 149046], [-71126, -395125, -348065, -798278], [2499428, 484046, 79584, -111070], [4047382, 561062, 106912, 535970], [-5839510, 333063, 185992, 130797], [3184802, 892888, 224372, 579555], [-712350, -1061528, -386214, -701528], [11989986, -291496, -9580, 15035], [-592130, 197105, -122112, 672831], [6078798, -313739, 42612, -720689], [-4611774, -764148, 13320, -434703], [-5945370, 57386, 7984, -81034], [-8106366, -875325, -45868, -776369], [5746630, -924755, 133056, -403167], [4405782, 376938, 184196, 458280], [461292, 569508, 74158, 498826], [12250108, -368102, 183954, -7484], [-2441346, -13087, 200933, -7658], [1181470, 85486, -639160, -7310], [4256278, -1054088, -189054, 29101], [-5292126, 371760, -35488, -751764], [14301014, -442754, -40846, -537986], [-7560584, -187950, -164476, -691114], [-1333002, 578994, 197416, 13484], [9955002, 697944, -578838, 633366], [13871960, 470970, 8524, 704366], [16346842, 814724, -331524, 46461], [18440038, 163053, -233176, 83969], [-1940654, 116843, 6991, -255046], [-8110278, -638880, -58174, 73653], [17368970, -49593, 253063, 4464], [-18487850, 235020, 56948, 74288], [9612246, -286528, 15272, -1633249], [-982016, -1396410, -680998, -819592], [-13679836, 1001454, -46794, 428062], [-18069114, -1107598, -275068, -189896], [-13015182, -396392, -318260, -409208], [-11743106, -1116507, 13072, -1032303], [9701786, 494859, 109495, -653130], [351408, -320706, 478206, 1406312], [18181308, -1369782, -330050, -1760674], [-5363038, -1050937, 116503, -225156], [-15688190, 299388, 4002, 73640], [-5411910, -1874532, -106472, -2118446], [-3232130, 143796, 580848, 1729892], [-3700964, -1089668, 466632, 141358], [-15477642, -688112, -188766, -673507], [-1907822, -1996785, -1079425, -911590], [33005082, -718097, -133628, 394327], [5775842, -944220, -845478, -1220828], [13029040, 44056, 647092, 1236534], [82486, 1791257, 88020, -403357], [-9167658, -1646946, -174902, 206566]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_82_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_82_6_a_b();".
// 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_82_6_a_b(:prec:=4)
    chi := MakeCharacter_82_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_82_6_a_b();".
// 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_82_6_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_82_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![44820, 198, -546, -8, 1]>],Snew);
    return Vf;
end function;