
// Make newform 12.11.c.b in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_12_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_12_c_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_12_11_c_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_12_11_c_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
        poly := [9, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-36, 72]];
    Rf_basisdens := [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_12_c();"
function MakeCharacter_12_c()
    N := 12;
    order := 2;
    char_gens := [7, 5];
    v := [2, 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_12_c_Hecke();"
function MakeCharacter_12_c_Hecke(Kf)
    N := 12;
    order := 2;
    char_gens := [7, 5];
    char_values := [[1, 0], [-1, 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, 0], [117, 1], [0, 6], [-10318, 0], [0, 1374], [-256822, 0], [0, -2616], [3196106, 0], [0, -39228], [0, 147858], [23140994, 0], [29797946, 0], [0, 4452], [247522778, 0], [0, -1547352], [0, 2588478], [0, 1686054], [-1054839766, 0], [-361186198, 0], [0, -4373844], [374437394, 0], [-113914462, 0], [0, 23058234], [0, 15410172], [2809917122, 0], [0, -60530442], [15121973234, 0], [0, -62053266], [1398457226, 0], [0, 54365688], [889746626, 0], [0, -49563966], [0, 186204948], [5420439578, 0], [0, -362090706], [74817268754, 0], [20673863402, 0], [95760465578, 0], [0, 687783420], [0, -1081096326], [0, 1070062026], [345325094234, 0], [0, -963883104], [-139964333182, 0], [0, -1998946842], [-83298545614, 0], [-618669020086, 0], [84552251138, 0], [0, -1542241710], [-1064680502854, 0], [0, -1320281148], [0, 226038600], [1095100233314, 0], [0, -5204576442], [0, -266179968], [0, 584149836], [0, 10063585770], [535797273122, 0], [1175328354842, 0], [0, -9358773924], [-1415468720902, 0], [0, -15881478954], [2724692597642, 0], [0, -9857696844], [2157461126258, 0], [0, 11846823906], [2234060912282, 0], [-5320463090398, 0], [0, 1593195606], [-2822357255062, 0], [0, -34493834064], [0, -485409636], [10934326270562, 0], [-5572379727142, 0], [13479490870586, 0], [0, 3799281984], [0, 67521743814], [-2505527724598, 0], [0, 21129811080], [-4137794344654, 0], [0, -15640647822], [1731992253242, 0], [0, 37763073768], [-1888697857822, 0], [-20697593004334, 0], [0, 11100293478], [0, -80257930272], [-9299633773294, 0], [0, -35209761078], [-10122655141726, 0], [0, 157048659834], [0, -189070316784], [-39170668769038, 0], [0, -159439071570], [48925578343946, 0], [0, -56275990956], [0, -183841657662], [0, 69186450900], [-16132114142182, 0], [-42389418937366, 0], [-24696332500054, 0], [0, 218549922618], [0, 282412300554], [0, -159536099220], [20426188587194, 0], [15733257993602, 0], [0, -303202626882], [0, -45636143640], [0, 410252027556], [27733118012594, 0], [97736469825026, 0], [-141137788728646, 0], [0, -228068499324], [39502090881626, 0], [-60437036211886, 0], [0, 738678815808], [134823187074794, 0], [0, 188836552332], [0, 734884817322], [0, 20433527706], [-25843314165478, 0], [93318076368194, 0], [0, 347243514006], [0, -673372867122], [41578080307082, 0], [0, 578860705698], [-277906443031174, 0], [0, 1124215678296], [-151463369950318, 0], [-237805987019926, 0], [-358451427345622, 0], [0, 993783868380], [10894528637282, 0], [351497499281882, 0], [0, -1447113216564], [-278710781354494, 0], [0, -1898535511674], [-125180950868278, 0], [0, -585349132014], [0, 1963858236132], [392624493739994, 0], [0, 892419378366], [-202565251309102, 0], [0, -568069165914], [-234410936280022, 0], [0, 2410483237164], [395974567773338, 0], [0, 109465992828], [-478130309070982, 0], [0, -3898596595632], [70664080650122, 0], [0, 3406511020920], [-122030473175542, 0], [0, -832836596844], [-342190103566054, 0], [0, -2790133297416], [-628087274017774, 0], [0, 639750233808], [659993065913042, 0], [0, 3120939493626], [0, 3750076957770], [0, 855914611500], [1132725119410226, 0], [0, -4314243563010], [0, -8123073265752], [0, 6073930398180], [1434097326849794, 0], [1705387517615546, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_12_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_12_11_c_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_12_11_c_b(:prec:=2)
    chi := MakeCharacter_12_c();
    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_12_11_c_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_12_11_c_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_12_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,11,sign)));
    Vf := Kernel([<5,R![1632960, 0, 1]>],Snew);
    return Vf;
end function;