
// Make newform 24.23.h.b in Magma, downloaded from the LMFDB on 08 February 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_24_h();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_24_h_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_24_23_h_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_24_23_h_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_24_h();"
function MakeCharacter_24_h()
    N := 24;
    order := 2;
    char_gens := [7, 13, 17];
    v := [2, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_24_h_Hecke();"
function MakeCharacter_24_h_Hecke( : Kf := false)
    N := 24;
    order := 2;
    char_gens := [7, 13, 17];
    char_values := [[1], [-1], [-1]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), 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]];
    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 := 23;
    raw_aps := [[2048], [-177147], [78087502], [2465522390], [506642048890], [0], [0], [0], [0], [-22106449229264450], [-42028193165217562], [0], [0], [0], [0], [10041664974306202606], [-48466665456028599110], [0], [0], [0], [405821217855787668050], [-1253187373444691625658], [-2032047895376754826166], [0], [8848153397402570697410], [-17503077491519151647090], [14095501424916785570390], [-41537260102331223437414], [0], [0], [29868970899533209013030], [-382142334089588733077750], [0], [0], [1338188427787266199998190], [408914196268090066355702], [0], [0], [0], [-8263861841244323656314146], [11895905705262310187303530], [0], [0], [-2061028925729425081689310], [-20155939109232008353275506], [-16074926691619105958868202], [0], [43076534478014708412773030], [17700288866863147668056554], [0], [0], [0], [-190165752161797778600309182], [344543573130226753372190170], [0], [0], [736747244341977180809986270], [1070379751799861418340022342], [0], [0], [0], [2728294723715195450710935886], [0], [0], [5615100022930448858517785330], [1162179059789495551861579966], [0], [-24314924742592897440350590], [-17447359288161150020060904806], [0], [0], [0], [-30874571563265879270923621690], [0], [0], [0], [-25607077689487334909480111090], [0], [0], [-75640810770228700150590295918], [112373808691661955810744612970], [0], [0], [-60439946226351548541443035870], [91395335147847688399522001078], [226166382399638391374553066586], [0], [-180784419912468140237045886670], [175035245422439690630500748830], [56219177686001915317230959750], [-432321499277249365394345713334], [0], [-396584134925807588879071736170], [-569946246789852632102003961830], [0], [0], [-225407324106556779524964309890], [0], [0], [0], [0], [-2935351597380354238139598415586], [-321615211866401409151744502774], [0], [0], [-1606760322733498229704342425310], [-1064268610264236982940626599974], [0], [0], [-4607351900295435981763549477198], [5990208496716571102108518474470], [0], [0], [0], [-6898502234125336488337496180362], [0], [0], [0], [4510182632209886929018363051294], [-3522014574150212183069240435030], [0], [25654282848655711271240288361410], [-10016151779791887403358134461554], [21956856096377454478478779311034], [0], [15361480494084442704798186975550], [0], [0], [-41080120068856964270089856173450], [0], [0], [0], [53619571054886966416642198270598], [0], [0], [28731978215541681823831335877538], [18189381703544861916782363983054], [0], [138229943755497559203082383729406], [0], [0], [227552248724879122756473967363630], [10247293270231336146408104119670], [-162327207623222434879023757240646], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [624207735204239137587629973646262], [0], [619226636181516103177587405579890], [-583470011046215694038541688141730], [-955921651175382003816920200922006], [0], [-225671768170799564633126446968490], [492490173070648619195379925067770], [0], [0], [-1459328490698746793669551821209818], [0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_24_h_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_24_23_h_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_24_23_h_b(:prec:=1)
    chi := MakeCharacter_24_h();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 23));
    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_24_23_h_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_24_23_h_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_24_h();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,23,sign)));
    Vf := Kernel([<5,R![-78087502, 1]>],Snew);
    return Vf;
end function;