
// Make newform 1089.3.b.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1089_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1089_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_1089_3_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_1089_3_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 := [2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_1089_b();"
function MakeCharacter_1089_b()
    N := 1089;
    order := 2;
    char_gens := [848, 244];
    v := [1, 2];
    // 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_1089_b_Hecke();"
function MakeCharacter_1089_b_Hecke(Kf)
    N := 1089;
    order := 2;
    char_gens := [848, 244];
    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 := 3;
    raw_aps := [[0, 1], [0, 0], [0, -4], [-1, 0], [0, 0], [-16, 0], [0, -8], [-33, 0], [0, -17], [0, 9], [31, 0], [-57, 0], [0, -11], [0, 0], [0, 43], [0, -63], [0, 49], [-105, 0], [-103, 0], [0, -84], [47, 0], [-23, 0], [0, -75], [0, 36], [-25, 0], [0, 107], [-25, 0], [0, -93], [119, 0], [0, 9], [79, 0], [0, 81], [0, 64], [-58, 0], [0, -184], [64, 0], [257, 0], [79, 0], [0, 21], [0, -48], [0, -141], [-287, 0], [0, -116], [-145, 0], [0, -32], [-57, 0], [105, 0], [199, 0], [0, -132], [-72, 0], [0, -93], [0, -3], [-160, 0], [0, 77], [0, 185], [0, 311], [0, 173], [-344, 0], [95, 0], [0, 276], [335, 0], [0, -396], [-311, 0], [0, 12], [200, 0], [0, 200], [577, 0], [289, 0], [0, -383], [-513, 0], [0, -180], [0, -320], [160, 0], [-127, 0], [454, 0], [0, -53], [0, 3], [481, 0], [0, 304], [-177, 0], [0, 217], [160, 0], [0, 489], [-143, 0], [335, 0], [0, 92], [0, 604], [-264, 0], [0, 87], [-608, 0], [0, -300], [0, 587], [56, 0], [0, -197], [-439, 0], [0, -428], [0, 249], [0, 411], [385, 0], [-88, 0], [424, 0], [0, 148], [0, -332], [0, -588], [-503, 0], [-615, 0], [0, -4], [0, 203], [0, -676], [601, 0], [1024, 0], [721, 0], [0, 36], [152, 0], [544, 0], [0, 576], [-1231, 0], [0, 112], [0, -187], [0, -347], [-521, 0], [-239, 0], [0, -216], [0, -779], [-919, 0], [0, -457], [518, 0], [0, -129], [-114, 0], [234, 0], [-1241, 0], [0, 100], [-113, 0], [-55, 0], [0, -624], [-41, 0], [0, 240], [-1024, 0], [0, -5], [0, -660], [-1513, 0], [0, 655], [615, 0], [0, 767], [97, 0], [0, -964], [-41, 0], [0, 284], [-1425, 0], [0, -783], [1593, 0], [0, 457], [-1145, 0], [0, 311], [-87, 0], [0, -1056], [-865, 0], [0, -843], [-473, 0], [0, 81], [0, -579], [0, -737], [-937, 0], [0, -491], [0, -501], [0, 387], [286, 0], [265, 0], [-608, 0], [0, -48], [0, -820], [175, 0], [0, 281], [-1358, 0], [488, 0], [0, -773], [1297, 0], [0, -545], [-110, 0], [-1759, 0], [401, 0], [0, 1196], [-1464, 0], [0, 651], [0, -879], [0, 984], [1809, 0], [609, 0], [-1016, 0], [0, 56], [1457, 0], [0, 1015], [-609, 0], [0, 1461], [0, -1320], [0, 975], [712, 0], [823, 0], [0, -408], [0, -1597], [0, -3], [-135, 0], [639, 0], [497, 0], [0, 688], [0, 92], [105, 0], [0, -1236], [0, -1020], [-1583, 0], [-561, 0], [0, 96], [-2463, 0], [0, 209], [0, -480], [1472, 0], [-2279, 0], [0, -345], [0, -1272], [0, 99], [473, 0], [270, 0], [0, 1116], [-1849, 0], [0, -1671], [-680, 0], [0, -828], [0, -564], [-712, 0], [0, -284], [-1664, 0], [-2575, 0], [281, 0], [0, 875], [-2561, 0], [0, -1019], [-735, 0], [0, 1728], [0, 1016], [0, 1463], [0, -880], [520, 0], [-129, 0], [-1935, 0], [0, -395], [0, 141], [-1792, 0], [0, -1160], [1200, 0], [0, 583], [-2335, 0], [0, 368], [0, 768], [-535, 0], [0, 603], [0, 1972], [520, 0], [-2376, 0], [0, -792], [983, 0], [1376, 0], [0, -2181], [-2225, 0], [1689, 0], [0, 576], [559, 0], [0, -1587], [0, 219], [457, 0], [0, -516], [368, 0], [759, 0], [-3065, 0], [-98, 0], [439, 0], [1097, 0], [0, 276], [3128, 0], [-1807, 0], [0, 1284], [0, -1931], [305, 0], [0, -1516], [2566, 0], [-1831, 0], [0, 780], [-2985, 0], [0, 1491], [-143, 0], [0, 271], [0, -1208], [0, 460], [0, 2109], [0, 1152], [-456, 0], [0, 473], [2383, 0], [0, -1492], [0, 837], [1087, 0], [-1431, 0], [0, -1539], [-97, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1089_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1089_3_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_1089_3_b_a(:prec:=2)
    chi := MakeCharacter_1089_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(1999) - 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_1089_3_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_1089_3_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1089_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<2,R![2, 0, 1]>,<7,R![1, 1]>],Snew);
    return Vf;
end function;