
// Make newform 24.29.h.a 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_29_h_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_24_29_h_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
        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 := 29;
    raw_aps := [[-16384], [-4782969], [-11577394034], [-193132900798], [720252825193582], [0], [0], [0], [0], [-239163927290883595538], [1487053511440341707042], [0], [0], [0], [0], [-2493538039018795134031538], [4628202273695994234168622], [0], [0], [0], [-43980854921531886461068318], [-385455539594119457156247838], [1227167273478473553631896142], [0], [-12497567780595875582388896638], [-3151091140799435559293466098], [-23525274446450591075899909438], [45420095627175428607640616302], [0], [0], [561686670260785831194175378082], [388252065525939022078501852942], [0], [0], [5284686695217640652355868349902], [-4178426516079220024948261238398], [0], [0], [0], [-12549030894051851144473499172818], [-65298179461586764500586515420338], [0], [0], [-156459466277475932725944082665598], [159723985022382455570484990021262], [-119360956455938433518012559767998], [0], [-399064004187840017974963065220318], [1750120623035967253705742308851982], [0], [0], [0], [-4328406721092405614388991583119678], [-2428689387517699255334422472982098], [0], [0], [19148652657475172223301794627540142], [-1606567270605465255048598784094238], [0], [0], [0], [-55027681762585822964703443717581298], [0], [0], [-359327921419888537884161309491678], [17798916152667293715533765541112942], [0], [318255940146280581500914427687526722], [-399701221272871124136598455665001938], [0], [0], [0], [-1449279815880091211844678480743494558], [0], [0], [0], [-3457669980972646996899934373086037618], [0], [0], [5550345422258981278552128126049996322], [-6364708222197667503286494521342659058], [0], [0], [-16019482335851324684784939988259578558], [3961420472833561496613525578591316482], [4668401322466047456597845670567689902], [0], [25008758044099313217617290895657935202], [-25812472310035560595211613995891144018], [32205377472285003953320409504521521122], [-24521663337152882533097469572025537458], [0], [25073074878629592046064855353681475522], [72163007963975463971208722216333971822], [0], [0], [28902819710919711331309296414979239022], [0], [0], [0], [0], [341882114941400798518510166807131865902], [-363133164668921507430357013410011459378], [0], [0], [829888222169336636352178260434391223682], [795120065867911126241724412848578045422], [0], [0], [666337771275110336368781950879061546402], [1703294506731466701601663850620649248802], [0], [0], [0], [-2913745263692431420054301604364768450558], [0], [0], [0], [4959086281170484881913824789443089362862], [-2074855310026519172997442500644463587378], [0], [3132081892867891586923046444187588151682], [-409164737333635908700381240345987186418], [9561098783393798419123576615831373992942], [0], [12148264243531549831288844152754789077102], [0], [0], [11689908897211669006652517047835402890882], [0], [0], [0], [14972088504128766625035382550443746626402], [0], [0], [23148163559445531375349640942971190528642], [39103293137951278398077997521173967715982], [0], [64113937340335342844596324142479011066862], [0], [0], [116498838375505613471050258940484657923662], [80034023965595065956509462453753741057282], [-51251534636922894436147390324272866436818], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [-264401483957875672612760467276939839384958], [0], [-767881280464692661139647018318898005646878], [-850531218887846553598015823875404845274578], [-314261480524987212620893377117846662594738], [0], [-743697270468722428295495052516036712340158], [-18064187763219744313699013509593847829138], [0], [0], [338557341246712348190931256487736402988322], [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_29_h_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_24_29_h_a(:prec:=1)
    chi := MakeCharacter_24_h();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 29));
    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_29_h_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_24_29_h_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_24_h();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,29,sign)));
    Vf := Kernel([<5,R![11577394034, 1]>],Snew);
    return Vf;
end function;