
// Make newform 3.11.b.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_3_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_3_11_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_3_11_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
        poly := [5, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 12]];
    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_3_b();"
function MakeCharacter_3_b()
    N := 3;
    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_3_b_Hecke();"
function MakeCharacter_3_b_Hecke(Kf)
    N := 3;
    order := 2;
    char_gens := [2];
    char_values := [[-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, 1], [-27, 9], [0, -106], [17234, 0], [0, -6962], [-169654, 0], [0, -12792], [-949462, 0], [0, 99044], [0, 118594], [-29793118, 0], [-60811846, 0], [0, 6770372], [107419706, 0], [0, -9987608], [0, 7158798], [0, -24192682], [1030793642, 0], [1876742474, 0], [0, 100003596], [-2846528494, 0], [1488647618, 0], [0, 47175562], [0, -224371428], [-1592948926, 0], [0, 157648390], [4417605266, 0], [0, -119012130], [-15465036022, 0], [0, 944133176], [58409844194, 0], [0, -2115809326], [0, 2941482484], [8896830458, 0], [0, -2769972610], [-59094953038, 0], [-38186331286, 0], [161033775626, 0], [0, -2220223012], [0, -7713362966], [0, 1945835034], [-338840384038, 0], [0, 5795864992], [350354918786, 0], [0, -11627443338], [-151942626862, 0], [136228590122, 0], [115572973346, 0], [0, -828896414], [548204193338, 0], [0, 32000551332], [0, -33953014648], [371249985122, 0], [0, 6554110710], [0, 28336588160], [0, 8864392876], [0, -58606809894], [-1666190485438, 0], [-2065190101606, 0], [0, -100246310276], [1445333968346, 0], [0, 126369661670], [2071043154794, 0], [0, 79897608788], [-814837959694, 0], [0, 30605240338], [1767333872762, 0], [-535777293406, 0], [0, -181619177338], [78376615658, 0], [0, 182911978288], [0, -30697309572], [5559332053634, 0], [-42192119974, 0], [-9514222286182, 0], [0, -105371758528], [0, -41782115498], [-7467314883766, 0], [0, -607318221880], [10513422551858, 0], [0, 815077743746], [6756790359482, 0], [0, -589649287896], [-14612343458974, 0], [-12682584641422, 0], [0, 174656256790], [0, 1052490737760], [9228535928594, 0], [0, -291052421702], [-33043187720254, 0], [0, -151652698422], [0, -481567681136], [-21637085398126, 0], [0, -1264646338018], [-18337451028502, 0], [0, 346275348468], [0, -571756932622], [0, 1338772026036], [57887055504506, 0], [-3168439533718, 0], [-22907016862966, 0], [0, -3398393699670], [0, 1769733731546], [0, -424294299764], [-19970767254118, 0], [-8526179547646, 0], [0, -554899055186], [0, -1419424067160], [0, 3191708280260], [-28973213605198, 0], [-84140858374366, 0], [22720492008506, 0], [0, -972309953692], [171879072494138, 0], [-1356240871438, 0], [0, -4381223866688], [136129636411466, 0], [0, 5228643775212], [0, 4605325744538], [0, 7234432023658], [-224813438361958, 0], [63929333759426, 0], [0, 2549451563686], [0, -4384947804738], [54049208484842, 0], [0, 9759114677970], [-121603319262982, 0], [0, -10522928014824], [-69800963744206, 0], [-328397183788054, 0], [304479262586378, 0], [0, 10500537403580], [386635365171842, 0], [-17696784403366, 0], [0, 6496710815468], [193973820796418, 0], [0, -1958941431786], [-152665047808726, 0], [0, -11997501299518], [0, -15744987414972], [-521066483365318, 0], [0, 6961326826126], [62278205138546, 0], [0, -14893163964714], [-551492991071062, 0], [0, -7396933266548], [719131868179226, 0], [0, 9595087717660], [481364628349658, 0], [0, 403122929616], [-69444127348726, 0], [0, 34368329527224], [-30321296867734, 0], [0, 34947115040564], [-915530722499206, 0], [0, -41473127290952], [468202756080818, 0], [0, -15114755779376], [-163834664956846, 0], [0, -28420109310358], [0, 37589791005082], [0, 8399482721868], [789274805349074, 0], [0, 8865118111086], [0, -17250961242904], [0, -26264478707708], [964031778393122, 0], [-869672763808966, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3_11_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_3_11_b_a(:prec:=2)
    chi := MakeCharacter_3_b();
    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_3_11_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_3_11_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,11,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;