
// Make newform 108.6.a.c in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_108_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_108_6_a_c();".
// 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_108_6_a_c();".
// 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, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-9, 18]];
    Rf_basisdens := [1, 1];
    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_108_a();"
function MakeCharacter_108_a()
    N := 108;
    order := 1;
    char_gens := [55, 29];
    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_108_a_Hecke(Kf)
    return MakeCharacter_108_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], [0, 0], [0, -1], [-16, -3], [243, 8], [104, 12], [972, -20], [-316, -6], [3402, 4], [5832, 38], [1664, -81], [-4978, 60], [6804, -58], [2480, 162], [9234, -264], [-5832, 341], [972, 376], [4088, -720], [45032, 450], [-22356, -788], [-60607, 504], [14384, 840], [-7533, 1752], [-89424, 358], [44471, 1272], [-101088, -1055], [131936, -1260], [92583, -1240], [-150226, -324], [-16524, 1350], [-139768, 2835], [261711, -952], [95256, 1670], [163976, 1500], [-40824, -2777], [-41416, 315], [-113212, -7128], [47924, 2544], [222102, 4176], [-268272, 3963], [35721, 3224], [363536, 7584], [-264384, 5812], [-590971, 2304], [-511272, -1643], [290024, -6909], [-23476, 5178], [-429160, -1296], [-308124, -1416], [-1192906, 4536], [272160, 12074], [-205578, 9396], [32366, -10056], [-474336, 8864], [1293732, -1632], [-486, -15236], [672624, -4138], [709856, 1557], [696848, 16200], [1806948, 12668], [-10036, -35802], [730944, -24254], [-365236, 20412], [-375678, 23612], [1528661, -12936], [1174176, 25873], [-1395160, -16422], [-1284718, 9960], [-462915, -4152], [600554, -12828], [1670868, -29950], [-1352538, -10248], [-49408, -25101], [767732, -43116], [-2124064, -24708], [-2530116, -3868], [-2482488, -8177], [-1192552, -17820], [-1671840, -48004], [-702265, 6432], [-821340, -29040], [3869696, 11832], [-2579202, 34096], [-1866859, 74520], [-707584, -27945], [774684, 77424], [4349700, -58374], [-651145, -77112], [-6837048, -35713], [2910848, 6105], [4930227, -57184], [5557410, 52296], [-1935280, -55392], [1279881, -149576], [1523672, 79218], [5937462, 55140], [-2313360, -15067], [628884, -11384], [-3156580, -13428], [5301692, 53448], [-4661188, -49356], [-1249992, 39583], [6434397, 117336], [2288088, -100292], [-4852948, -80544], [500030, 36504], [2441907, -129848], [-3888000, -167126], [3045762, -38696], [-1190533, -92664], [-8475520, 127968], [10498094, -76320], [6956604, -130534], [-12170068, -27432], [-2255104, 46437], [-9345780, 167630], [3553280, 177876], [6424920, -171048], [-11508480, -103901], [6103917, 103504], [-9818446, 167220], [-9894211, -12912], [-624024, 161434], [-1960524, -256080], [2100704, -103356], [-6213024, 75533], [189308, 266736], [-710532, -63264], [-3186040, 106677], [-2846674, 32724], [-5301916, 328212], [15240960, -164916], [9419288, 260115], [1223882, 68472], [-2109240, 224760], [-69583, -159792], [13452480, -2106], [-7035520, 232416], [17494056, -223893], [21978864, -226694], [6105836, -163134], [-9789984, 93214], [-9117904, 61347], [16990560, 84448], [504314, 319368], [-6443388, 294876], [14133854, -256392], [21433572, 186324], [19208840, -308208], [-14604300, 412432], [7548602, -504480], [-31433508, -250072], [2184524, -577086], [-592920, 198068], [14374748, 395706], [-26267814, -24000], [-17315800, 339471], [-12649608, 233244], [-885997, -151464], [-9288432, 422155], [130005, -271488], [14193144, 650148], [12869456, -115803], [-51366069, 80136], [4420656, 3790], [22851234, 81448], [12408992, 102285], [-36702976, -135108]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_108_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_108_6_a_c();".
// 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_108_6_a_c(:prec:=2)
    chi := MakeCharacter_108_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_108_6_a_c();".
// 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_108_6_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_108_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![-3321, 0, 1]>,<11,R![-153495, -486, 1]>],Snew);
    return Vf;
end function;