
// Make newform 6.24.a.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6_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_6_24_a_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_6_24_a_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_6_a();"
function MakeCharacter_6_a()
    N := 6;
    order := 1;
    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;

function MakeCharacter_6_a_Hecke(Kf)
    return MakeCharacter_6_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 := 24;
    raw_aps := [[-2048], [-177147], [196251270], [-8131131904], [413280901452], [-5925134073898], [44831041228386], [869707616627540], [-3916239181103928], [99766495798865310], [56862945627758072], [859891131907937966], [1932133475449013802], [-1824796198841231668], [16746003232028322816], [63201959277916197222], [-70131254279037574260], [190432055560639941302], [428735859584268062996], [492213204429702165432], [4468601862249804902522], [-1683222034549677714040], [-19704564971975645125548], [-7782978323840347028790], [-93407314867322893215934], [11104447244654271356022], [66716463209732033693552], [-253806638871586299179364], [-334894208295441228309610], [386600101599622639284402], [2984368479036114375360776], [-1279455574155578392713708], [4231234948016085038516586], [2551953336984835826048540], [-6070805231811643701447690], [-5486281553246639278473328], [4495724925309813235038326], [-21988646907635828454099388], [31725239378359771969665576], [-60823304536547597610127938], [19478781655188893936283780], [40639125162414655688733902], [-66145820329295492136787968], [337146507051312966165905282], [198931392429851973742520886], [-30911422733718529270714000], [-491471153355573729293336668], [1250780600005335447219308552], [-644307960570901752601286844], [1611830756751895298976136190], [-2852986032395555010702313158], [-3442221616918977687646717680], [-3642966446609541806049737038], [5101293974236743344139656892], [-5907200659261452846872807934], [5188907025734300376383608392], [3075234315996813870683481390], [589165114750532033447140472], [-14282230272655928799732422674], [-7059561825690838583352523158], [27286680887377112985853292972], [-35270472037716331478949698058], [-1352373961434208646477840764], [46465195902775580599661683032], [62984746926308116934648568842], [33508498147888977069112184286], [19392290335668325810101768572], [-37162417579268983688327728654], [-241719478425016234633326644004], [-223249868714212115027333869930], [-268010216159206030498562379198], [-127459913040855308458550359080], [-147243752669112568075252774264], [483719854993707197318787443582], [527542805429228091091103450300], [318617505371350152645969795072], [-98322144584889602197027652730], [1491268751717298290765293229606], [11376723285199721251444797762], [821640196853290345037684856650], [1407420718809251359508890711620], [-753133634181377924368850594338], [608344110286309153713117991392], [-242465988017857255743046172398], [1155249408897255215281368404480], [205440014688637341707966781372], [513123344549688614908099236210], [382320727329145689176716933466], [-280354246033325293813877869218], [2874534945497154213405871212152], [-1977086603399992603604091117324], [-4722747308384682756647321890800], [-7409320888732551907586005437664], [-5600185841165753908954641214308], [-1142470783527435117443831794300], [9578470370460944385857022234792], [8385900741194875594342114923870], [-4282085140852673533611405893238], [28977048603013965691566660188492], [47083058910047283154076340198182], [-27598655287089268815072826883164], [-74039641092116689880093332836834], [21785484534740879882644223302452], [69425424073954348203745021500570], [-31531830186527772339055401847828], [-49466415977058552851180946416254], [-70073343323294174338930373599044], [-6582977214293940291232670362158], [166844859288245411737469264370600], [-15453019321192201158267392102998], [-78552386608917767332514422129624], [-158035348571309167450282580880178], [-137509129965896634101542951413414], [150771488856595930053321767198780], [110861975926407213569789518497392], [30518931804839131467230929327602], [-211583810395038255105427419324988], [-121875743783351367411103657078344], [279261010422791340279540862684542], [-126037115231115033860592063683580], [431607459839170973472231343827902], [-403228642412259333207116151563038], [-313988636034093260109842665423674], [676861033362058961415840320744652], [-120741746228540481104328327747628], [-714026665468037407858192131002658], [380615344278524171486990468825630], [-760837576288534516439155120911840], [230751572525305789430680766889296], [-520455407072812446603509814364858], [-1419795495528054655232124709407340], [507868609582037861447739960387912], [-1700516403141155006588795758451608], [176925786036604643863673079198446], [-990357571320166444499218795402758], [-642169473973606314594112687894270], [-1262884326611828191062631201256778], [-3439836582274097041259637113503564], [-901028044089347986411191804965394], [1482505679646117064576606740488010], [-122539696195755988043157072036148], [3290211364428572110954257267522822], [-4033611272379589324148869176454768], [1483638678488272703228037803245356], [3828738597446607768150601506206150], [-6153430204943020547009255353721640], [-4984594040898022805017666155874498], [574761853071002150561709435030906], [-6561105268716195846081220777947940], [8313276535684381879291489977702432], [1511445439953368770316021695438406], [-10856505227750900524801791497146158], [4679896612642302277061086425285332], [14013365583435726208168297124608056], [15730000042466226214251084639266636], [3692297111167290323668509795904752], [-4172550230284674315119305577679760], [-19132701779397446418357070633398030], [10382460392763988162461652619755226], [-4427757265696787505604095622467138], [-14181900226300494961815405897947004], [12610923313045168178712601466441562], [-3366063978420831741038825691309424], [15935559671300630465922027151109292], [-34004446902692850942506286324919614], [-21218414300039049257616136888585128], [15059249770472442943901590857510872], [10821688886359553166028484470173326]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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