
// Make newform 11.33.b.a in Magma, downloaded from the LMFDB on 26 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_11_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_11_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_11_33_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_11_33_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_11_b();"
function MakeCharacter_11_b()
    N := 11;
    order := 2;
    char_gens := [2];
    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_11_b_Hecke();"
function MakeCharacter_11_b_Hecke( : Kf := false)
    N := 11;
    order := 2;
    char_gens := [2];
    char_values := [[-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 := 33;
    raw_aps := [[0], [-85968833], [-9728091649], [0], [45949729863572161], [0], [0], [0], [3656631949033345760447], [0], [-1006459202425404995301313], [17726726040327497823316607], [0], [0], [-1020566006447389822959797758], [4022797084351571925113466242], [33520999946136001669135487807], [0], [-153526925358039096047591099713], [708325301570462956915970875967], [0], [0], [0], [-30353141869613419294864684580353], [-40247763790655769287984856095233], [0], [320274572027911349448857710698242], [0], [0], [417860054669880092686397674612607], [0], [0], [-17395473855748518691162897545547393], [0], [0], [0], [239303035992198860894873905189792127], [-471268169817698836027425029331957118], [0], [0], [-1831148023514595178096954985402951233], [2394863435473180614235955496463989887], [5525532204068096085369049015043260607], [0], [0], [12057962993403576619030671129916896002], [0], [35806177828836449729167360218675488447], [0], [64449887939245812380322627464105703167], [0], [0], [0], [168550547041103415177141774922289665727], [706099234049094594257467636719433113602], [0], [1092564895126321818283174760119540037762], [0], [0], [0], [0], [0], [0], [1735626379106440444384429432038182872322], [12864800201594160798047966950267524993407], [-15426318585375495315413469951630745792513], [-35144910260704747604491385913175002318913], [0], [0], [0], [13270769676650327815192753856467553779967], [0], [-113672305320019912981122160878547952958913], [0], [-344103696061357470452733163562347547908033], [-390296141871762752884453639025131630811713], [547898270632313476077070394146139116837247], [-27342112209883949105951669136376403621758], [-339240603556444364265565359547042121817598], [0], [661595677957627366907365318235789910764162], [-45294093502389077785904472367346583596158], [0], [2733678658920358590022385529320593488885887], [0], [-2357274910169418531968573739956466857278273], [5214873230531503993111798371085062855184127], [0], [0], [7336588894432556901233239754137529261731007], [-6211893817088053736349644019222552516155713], [0], [10930061310287162453027068226383570704575807], [0], [-17539560231885603036646909029618187869206398], [0], [-28651382398051249145581127303495618580225793], [-16399774881333242132250651050515441877336833], [0], [0], [0], [0], [0], [0], [0], [278913992875317319922339793944672653303669247], [-124278074329063786155811318377454057276437118], [0], [141487447394134151582798451566532206310662402], [0], [0], [0], [602022442536503341141944065186928917773052162], [743513274564976632414441526256331279050157887], [-299285441058001444750783630239059412823509313], [-1451192102517665078578406969503998803814225793], [476563288423175948540863819074217420225758527], [1102438156359928025688746531930452373024578367], [-1061971949382682845004162992207924877295615233], [0], [-848245019334073324657455168906789711348260353], [0], [0], [-4053737635910654043155496831166795047656115838], [-2393255674545493120774896233911161947297299393], [0], [5118451096034626573755615620116967931870763007], [-8211941019023775200552940278062403436904888513], [11461223265609033741580740472906328766813987647], [0], [0], [0], [5650616075103712389696390096434202526355118527], [17174565235988771644778698695727540201057084802], [0], [0], [4697096343008594472597772789614046894173851522], [0], [-6885231564107106368106956281786611625417343233], [0], [0], [0], [20172297637285884873201653574093576438533350847], [0], [-37854206695769728583957330941041959644619288833], [-118368973779546174368589910693397250276250556353], [0], [0], [92346679965414174686993710804032988220682278207], [-119612776426519366276798220675417758437208120318], [0], [-246061016688963108459555249109495006377552698113], [-19007625804942149394267648294043022777211987838], [0], [-182331603191589322789253631091594920272550902398], [-417699794733022541968017824109393964569878868478], [0], [-447334330309452426997455557096546223392291343358], [0], [0], [821888122875673822905760071549472812790181122367], [0], [0], [967952773758309849423253007073223381896115896767], [-211549860030430651023581036435862078191542157953], [794328468421927264700230932417530107687569703487], [-1049041158819662907960543881918263846823784606718], [0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_11_b_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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