
// Make newform 99.6.a.g in Magma, downloaded from the LMFDB on 02 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_99_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_99_6_a_g();".
// 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_99_6_a_g();".
// 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 := [-38, -52, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-1, 3, 0], [-34, -3, 1]];
    Rf_basisdens := [1, 1, 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_99_a();"
function MakeCharacter_99_a()
    N := 99;
    order := 1;
    char_gens := [56, 46];
    v := [1, 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_99_a_Hecke(Kf)
    return MakeCharacter_99_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 := [[0, 0, -1], [0, 0, 0], [-8, -3, 1], [28, -10, -10], [-121, 0, 0], [162, 6, 70], [-362, 20, -132], [460, -20, -60], [1022, -167, 21], [1142, 46, 182], [-1366, 23, -101], [5908, 197, 937], [-1998, -94, 1378], [-8736, -370, 1190], [5744, 424, 600], [-16862, 540, 476], [1246, -249, -3141], [6162, -1346, -1466], [-15918, -907, -6575], [-13094, 891, 3935], [5142, -1174, 5370], [41716, 454, 3902], [47976, -3750, -3150], [35608, 1523, 5167], [3228, 2143, 123], [-61246, -5372, -564], [54984, 264, -12136], [46016, 6618, 11290], [146582, 1020, -3604], [62996, -6863, 1637], [25056, 5064, -1792], [336, 2518, -1898], [-27060, -679, 1005], [85584, 1886, 5118], [-5414, -5408, -20600], [-7564, 15786, 23298], [64160, 403, -26801], [-116540, -6624, -67296], [-84672, 12308, -27364], [306634, 18772, -24444], [196014, -6237, -39465], [471804, -10151, 10685], [-55622, -16401, 19539], [-202098, 8306, 11610], [-661334, 3240, 18472], [-295576, -14152, 34680], [-16540, 26392, -25864], [-747694, 21939, 22775], [-131592, -14062, 42386], [466460, 7841, -65019], [203810, 42786, 3418], [-113692, 6638, 66102], [543478, -14346, -16578], [-514362, 2515, 3735], [854326, 12132, 4804], [314148, -29478, -34022], [523066, 48228, 112276], [411128, 78580, 5548], [432102, 27720, 92632], [-534418, -8020, 77292], [289068, -21912, 37240], [82590, 68062, 48094], [-898052, -32492, -129172], [-2176448, -17108, -186036], [-1317112, 61805, -56143], [739304, 86409, -136995], [516670, -20709, 37215], [-318382, -69192, -46272], [-915372, -57120, -353752], [-299090, 114464, 24424], [66552, -122977, -384949], [-483888, -6276, -140380], [-568054, -81745, 87379], [-152058, -177200, -134536], [-1408218, 99631, -126253], [-2523578, 8609, 38957], [1635608, 94365, 354289], [583294, -188112, -264864], [1523502, -189168, -348896], [4220362, -21016, 181960], [1419740, 46608, -14272], [723510, 69232, 510176], [1080236, 130498, -199918], [914580, -94789, -143961], [-2745704, 38224, 125152], [-4306562, 65287, 226043], [729096, -180473, 59795], [5811014, -138534, -179246], [-592354, 157330, -538006], [-3504210, 157349, 483777], [-1713098, -77521, 549379], [2620344, 225036, 36388], [-840478, 215999, -305389], [1375884, 313908, 153956], [-3148684, 394912, 310720], [3800756, -441742, -525862], [2450748, 76663, 815347], [-2874060, 325317, -31527], [-3763500, 19588, -711444], [4520618, 143434, -733878], [-693220, -423612, 455844], [1594818, 47024, 111352], [33388, 7056, 116992], [4765026, -15094, 842594], [-905588, 76872, -677048], [7465036, 204583, 306867], [-5746604, -221584, -1152], [-6509646, 530134, 789998], [-746760, 321968, 448048], [-3863686, 270056, 344672], [3151356, -234518, -1040334], [-12941022, -104710, -110078], [4426950, 293080, 294424], [2691390, 88203, 1442303], [-4197486, -417457, 1223859], [3166816, -374053, -762329], [4504074, 61129, 553029], [-9498670, -116257, -1584893], [293468, 172415, 343451], [13208232, -120150, -596974], [6532272, 398327, -1186413], [2196362, 618700, -452036], [9141514, 279824, -716360], [-2602596, -79300, -412836], [626322, 500269, 423129], [9175866, 565564, 1233188], [-41972, -515911, 1412733], [-4835786, -685391, -2338659], [-16096646, 1851, -513121], [10235090, 343758, 169366], [-3912616, 411694, 150166], [15829072, 455300, 407028], [1270790, 329817, 1857701], [-2560386, -131500, -1637372], [2756266, 39102, -1806274], [11919262, -408766, -120750], [-17121390, -350164, 1526588], [-1983716, 1110380, 1080428], [11038264, -1029279, -543963], [-2957054, -896102, -1540614], [12728864, 331726, -200058], [-18371894, -642112, 611232], [-4414670, -249073, -1467485], [-2985612, -422416, 372792], [9402592, 818883, -1099041], [7925222, 1177181, -1368103], [11547782, -527656, -2254312], [-4761998, 686178, 2982858], [-3052566, 794501, 170513], [2401280, -47928, -696056], [-1818910, 224342, 3197478], [-6456404, 772885, -175751], [-16488332, 869392, 806944], [9615164, 157038, 913094], [14360572, 173928, 841160], [9637880, 164356, -781468], [5091812, -776622, -3009766], [8578494, 1147840, 3530992], [-19336498, 1668270, 1559982], [2775818, -160316, -1379356], [-15834122, 1554783, 1908131], [-17467802, 420792, -2794832], [30916824, 561080, 3516168], [867026, 191101, 4206105], [23952012, -1011307, 1155833], [3242926, -1133055, 3457325], [24516608, -293224, -885416], [-11007818, 776640, -2314088]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_99_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_99_6_a_g();".
// 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_99_6_a_g(:prec:=3)
    chi := MakeCharacter_99_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_99_6_a_g();".
// 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_99_6_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_99_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![-188, -90, 0, 1]>],Snew);
    return Vf;
end function;