
// Make newform 23.11.b.a in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_23_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_23_b_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_23_11_b_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_23_11_b_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 := [-3, -6, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-4, -1, 1]];
    Rf_basisdens := [1, 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_23_b();"
function MakeCharacter_23_b()
    N := 23;
    order := 2;
    char_gens := [5];
    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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_23_b_Hecke();"
function MakeCharacter_23_b_Hecke(Kf)
    N := 23;
    order := 2;
    char_gens := [5];
    char_values := [[-1, 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 := 11;
    raw_aps := [[0, -23, -2], [0, -66, 119], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, -74882, -218321], [0, 0, 0], [0, 0, 0], [-6436343, 0, 0], [0, -14142914, 1170439], [0, 20457814, 997111], [0, 0, 0], [0, 82807462, 23460967], [0, 0, 0], [0, 65544982, -110682929], [0, 0, 0], [1281228026, 0, 0], [0, 0, 0], [0, 0, 0], [0, -1246022426, 97551247], [0, 336680998, -1110128873], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [20892534074, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 16453838902, 16558202623], [0, 5710704862, 22752933967], [0, 0, 0], [0, -1057619474, 29769838903], [0, 0, 0], [0, -51708494426, -27218756153], [0, 0, 0], [0, -52985220002, -60012643073], [-205151453518, 0, 0], [-96943688182, 0, 0], [0, 86809308286, -65794304561], [0, 0, 0], [0, 0, 0], [0, -83546659466, -153364378481], [0, 191311439566, 109099809031], [0, 0, 0], [-157603646326, 0, 0], [1002594143618, 0, 0], [0, 0, 0], [0, 0, 0], [0, 491696960518, 134229246079], [0, -76580705162, -458807214617], [0, 0, 0], [0, 0, 0], [0, 795763018966, 12515238631], [0, 0, 0], [0, -887407092674, -545626124897], [-1036060122526, 0, 0], [0, -16080101234, -944131077569], [0, 0, 0], [0, 0, 0], [0, 0, 0], [-5335128626614, 0, 0], [0, 891525027814, -1372503254489], [0, 0, 0], [5305531919786, 0, 0], [0, -1730728877138, 1541395690567], [0, 0, 0], [-8641842776518, 0, 0], [0, 3336581795326, 1906349919703], [0, 3955182450934, 517839672319], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 2883140615902, 5686967204023], [0, 0, 0], [0, -4883781903962, 4517497447183], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, -956336927162, -9542038026017], [0, 4298436067918, 9948294480679], [11677573554626, 0, 0], [0, 0, 0], [0, 11969724694174, 9273026730247], [21517720667618, 0, 0], [0, 0, 0], [0, 0, 0], [0, 16548466559782, -5912022890129], [0, 12410106791374, -11086747904753], [0, -17649134710562, -13898709559817], [0, 0, 0], [0, -12363996180962, -19131984075617], [0, 0, 0], [0, 0, 0], [0, -33473356393538, -5791948580633], [0, -17294233905218, 21781205057671], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, -23199896456234, 28064059468231], [0, 30218870029582, 37217645203471], [-137611266249886, 0, 0], [-60270806929774, 0, 0], [0, 36146437753414, -28827204121289], [164623596000386, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 79577139287302, -2194627239977], [0, 55260819321598, 61631917995727], [0, 0, 0], [0, 0, 0], [0, 26450393099734, 81263832584119], [0, 0, 0], [0, -80597746779602, -70118979973673], [277778461344074, 0, 0], [0, 0, 0], [0, 0, 0], [27813363441698, 0, 0], [0, 0, 0], [0, 0, 0], [0, 157845676368286, 9731645576239], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, -174878985322586, -75776452079489], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [302574295817426, 0, 0], [0, 198233631623374, -93145497870353], [-718621103708326, 0, 0], [0, -210202488402266, 103857260379319], [0, 0, 0], [-736297940194774, 0, 0], [0, 0, 0], [134653472863514, 0, 0], [0, 179411001448102, 255000007170223], [0, -115231635185714, -273036972573161], [0, -209378450834666, 185041708194919], [755454176707082, 0, 0], [0, 0, 0], [359888749628618, 0, 0], [0, 96187182108166, 323565240764431], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 3279575633686, -398945869793561], [0, 0, 0], [0, 0, 0], [0, 538716071707102, 178949651888023], [0, 0, 0], [0, -502313540138618, -361400273479529], [0, 0, 0], [0, 0, 0], [0, 0, 0], [65337232563074, 0, 0], [890592632017082, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_23_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_23_11_b_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_23_11_b_a(:prec:=3)
    chi := MakeCharacter_23_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 11));
    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_23_11_b_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_23_11_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_23_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,11,sign)));
    Vf := Kernel([<2,R![50407, -3072, 0, 1]>],Snew);
    return Vf;
end function;