
// Make newform 189.3.b.c in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_189_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_189_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_189_3_b_c();".
// 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_189_3_b_c();".
// 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 := [4, 0, 56, 0, 53, 0, 14, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 4, 0, 1, 0, 0, 0, 0], [-20, 0, 16, 0, 11, 0, 1, 0], [28, 0, 72, 0, 33, 0, 3, 0], [0, 36, 0, 42, 0, 13, 0, 1], [28, 0, 49, 0, 14, 0, 1, 0], [0, 40, 0, 118, 0, 39, 0, 3], [0, 260, 0, 272, 0, 71, 0, 5]];
    Rf_basisdens := [1, 1, 8, 8, 4, 2, 8, 8];
    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_189_b();"
function MakeCharacter_189_b()
    N := 189;
    order := 2;
    char_gens := [29, 136];
    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_189_b_Hecke();"
function MakeCharacter_189_b_Hecke(Kf)
    N := 189;
    order := 2;
    char_gens := [29, 136];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, -1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, -1, 0, -1, 1], [0, 0, -1, 0, 0, 0, 0, 0], [0, 1, 0, 0, -3, 0, 2, -2], [4, 0, 2, 1, 0, 2, 0, 0], [0, -1, 0, 0, -1, 0, -3, 0], [2, 0, -7, -1, 0, -1, 0, 0], [0, 3, 0, 0, 4, 0, 2, 0], [0, -2, 0, 0, -5, 0, -2, 4], [-2, 0, 4, -3, 0, -2, 0, 0], [-2, 0, -13, 3, 0, 0, 0, 0], [0, -2, 0, 0, 1, 0, 5, 3], [-15, 0, 6, -8, 0, 0, 0, 0], [0, -6, 0, 0, -9, 0, -3, 7], [0, -5, 0, 0, 4, 0, 6, -2], [0, -7, 0, 0, 5, 0, 3, -6], [24, 0, -3, -3, 0, 1, 0, 0], [-9, 0, 3, -15, 0, -2, 0, 0], [0, -1, 0, 0, 14, 0, 0, 10], [30, 0, 2, 8, 0, -6, 0, 0], [38, 0, 5, 3, 0, 4, 0, 0], [0, 10, 0, 0, -1, 0, 11, 1], [0, -9, 0, 0, 8, 0, -10, 1], [-52, 0, 7, 13, 0, -5, 0, 0], [0, -14, 0, 0, -10, 0, -20, 22], [-46, 0, 13, 18, 0, -1, 0, 0], [0, 16, 0, 0, -10, 0, 18, -2], [-38, 0, -7, -3, 0, 0, 0, 0], [0, 1, 0, 0, -43, 0, 12, -12], [26, 0, 25, 7, 0, -8, 0, 0], [0, -1, 0, 0, 0, 0, 0, -21], [0, -13, 0, 0, -41, 0, -20, 16], [140, 0, 23, 1, 0, 3, 0, 0], [0, 16, 0, 0, 15, 0, 22, 16], [-112, 0, 5, 3, 0, 16, 0, 0], [92, 0, 10, 17, 0, 0, 0, 0], [-87, 0, -10, -12, 0, -4, 0, 0], [0, 18, 0, 0, 51, 0, -17, 11], [0, 10, 0, 0, 58, 0, -10, 4], [0, -7, 0, 0, -23, 0, -12, 8], [12, 0, 27, -18, 0, 13, 0, 0], [0, 12, 0, 0, 34, 0, 30, -22], [-7, 0, 18, -18, 0, -6, 0, 0], [0, -27, 0, 0, 15, 0, -2, 8], [142, 0, -1, 12, 0, 15, 0, 0], [-17, 0, -49, 13, 0, -16, 0, 0], [-180, 0, 43, 51, 0, -3, 0, 0], [0, -17, 0, 0, 24, 0, -26, 23], [-88, 0, 68, -36, 0, 4, 0, 0], [0, 1, 0, 0, -9, 0, -44, 34], [0, -3, 0, 0, -43, 0, -44, -2], [-154, 0, -37, 27, 0, 19, 0, 0], [0, -2, 0, 0, 45, 0, 17, -13], [0, 2, 0, 0, -48, 0, 52, 2], [0, 28, 0, 0, -71, 0, -8, -36], [0, -4, 0, 0, -47, 0, 7, -17], [-18, 0, -35, 18, 0, 3, 0, 0], [-108, 0, -41, 3, 0, -24, 0, 0], [0, -22, 0, 0, -22, 0, -10, 2], [12, 0, -7, -15, 0, 17, 0, 0], [0, -8, 0, 0, -103, 0, -29, 5], [112, 0, -102, 10, 0, -20, 0, 0], [0, 42, 0, 0, 27, 0, 51, -43], [-86, 0, 0, -34, 0, 42, 0, 0], [0, -16, 0, 0, 30, 0, 26, -62], [175, 0, -12, -46, 0, 30, 0, 0], [-63, 0, 152, 24, 0, 14, 0, 0], [0, -21, 0, 0, 5, 0, 0, -14], [-248, 0, -7, 58, 0, 11, 0, 0], [0, 29, 0, 0, -143, 0, 53, -24], [0, 9, 0, 0, -44, 0, -2, -56], [-150, 0, 147, -22, 0, 5, 0, 0], [-170, 0, -17, 41, 0, -10, 0, 0], [-256, 0, -59, 25, 0, -26, 0, 0], [0, 34, 0, 0, -113, 0, -9, 15], [0, -5, 0, 0, 117, 0, -26, 32], [-104, 0, 34, 42, 0, 16, 0, 0], [0, -50, 0, 0, 164, 0, -76, 44], [-124, 0, 138, 12, 0, 6, 0, 0], [0, 15, 0, 0, -39, 0, 69, 12], [98, 0, 52, -42, 0, -22, 0, 0], [0, -20, 0, 0, -96, 0, 16, -4], [328, 0, 3, 55, 0, 1, 0, 0], [162, 0, -31, 8, 0, -51, 0, 0], [0, -55, 0, 0, 55, 0, -74, 0], [0, -45, 0, 0, -117, 0, 60, -72], [21, 0, -91, 9, 0, -10, 0, 0], [0, -62, 0, 0, 141, 0, -69, 73], [-12, 0, -33, -15, 0, -50, 0, 0], [0, -4, 0, 0, 202, 0, 64, 30], [0, 4, 0, 0, 85, 0, -91, 47], [-94, 0, 32, 62, 0, 62, 0, 0], [0, -57, 0, 0, -71, 0, 64, 0], [36, 0, 31, -9, 0, -6, 0, 0], [0, 14, 0, 0, 93, 0, -85, -3], [0, 54, 0, 0, 85, 0, 55, 19], [0, -45, 0, 0, 47, 0, 13, 48], [450, 0, 11, 15, 0, -37, 0, 0], [280, 0, 107, 41, 0, -8, 0, 0], [280, 0, 135, 31, 0, 4, 0, 0], [0, 35, 0, 0, -182, 0, 128, -60], [0, 33, 0, 0, -48, 0, 70, -23], [0, 82, 0, 0, -122, 0, 106, -88], [271, 0, -146, -16, 0, -4, 0, 0], [228, 0, 136, 12, 0, -24, 0, 0], [0, -31, 0, 0, 58, 0, 38, 91], [0, 76, 0, 0, 83, 0, 137, -133], [0, -14, 0, 0, 19, 0, -66, -14], [-310, 0, -163, -29, 0, -39, 0, 0], [-242, 0, -126, 47, 0, 0, 0, 0], [-174, 0, 112, -54, 0, 6, 0, 0], [0, -52, 0, 0, -70, 0, -126, 34], [-492, 0, -43, 87, 0, 17, 0, 0], [-240, 0, -31, -41, 0, 70, 0, 0], [0, 17, 0, 0, -11, 0, -14, 100], [18, 0, -306, 4, 0, 6, 0, 0], [0, -20, 0, 0, 116, 0, -104, 136], [0, 30, 0, 0, 103, 0, 20, -54], [0, -8, 0, 0, 116, 0, 80, -56], [-100, 0, -57, -121, 0, -35, 0, 0], [309, 0, -221, -81, 0, 0, 0, 0], [0, 54, 0, 0, 220, 0, 8, -12], [0, -33, 0, 0, -317, 0, -100, 28], [-106, 0, 175, -21, 0, -1, 0, 0], [0, 85, 0, 0, 37, 0, 36, -142], [22, 0, -175, 3, 0, -60, 0, 0], [0, -32, 0, 0, 187, 0, -27, -33], [366, 0, 70, -125, 0, -58, 0, 0], [388, 0, 89, 42, 0, -9, 0, 0], [-338, 0, 6, 54, 0, 20, 0, 0], [0, 36, 0, 0, -69, 0, 42, -78], [320, 0, -302, -10, 0, 18, 0, 0], [-282, 0, -21, -11, 0, -36, 0, 0], [0, -21, 0, 0, -103, 0, -113, -82], [-286, 0, 224, 30, 0, -38, 0, 0], [0, -58, 0, 0, -171, 0, 85, -99], [108, 0, 0, 90, 0, 22, 0, 0], [0, 10, 0, 0, -50, 0, 88, -32], [0, 6, 0, 0, 198, 0, -54, -70], [-256, 0, 165, 9, 0, 63, 0, 0], [0, 11, 0, 0, 10, 0, 0, 64], [-20, 0, -103, 45, 0, 6, 0, 0], [0, -93, 0, 0, -37, 0, -68, 184], [400, 0, 7, 23, 0, 47, 0, 0], [0, 106, 0, 0, 75, 0, 47, 101], [188, 0, 81, -42, 0, 99, 0, 0], [0, 9, 0, 0, -215, 0, -15, -108], [-604, 0, -110, 18, 0, -40, 0, 0], [0, 73, 0, 0, 108, 0, 118, -164], [300, 0, 199, 27, 0, -36, 0, 0], [0, -9, 0, 0, -346, 0, -74, -41], [-85, 0, -100, 30, 0, -74, 0, 0], [0, -54, 0, 0, -323, 0, 31, 19], [872, 0, 121, -3, 0, -22, 0, 0], [0, 123, 0, 0, 173, 0, 142, -20], [386, 0, 103, 45, 0, -40, 0, 0], [0, 0, 0, 0, 63, 0, 53, -133], [-694, 0, 123, 97, 0, -55, 0, 0], [0, 118, 0, 0, 181, 0, -139, 23], [0, 36, 0, 0, -192, 0, -52, 170], [0, 6, 0, 0, 230, 0, 126, -208], [-470, 0, -184, -134, 0, -106, 0, 0], [0, -133, 0, 0, -197, 0, -23, -66], [0, 48, 0, 0, 280, 0, 104, -98], [0, -10, 0, 0, 57, 0, 59, -175], [176, 0, -357, 3, 0, -84, 0, 0], [-852, 0, 68, -27, 0, 74, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_189_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_189_3_b_c();".
// 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_189_3_b_c(:prec:=8)
    chi := MakeCharacter_189_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(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_189_3_b_c();".
// 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_189_3_b_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_189_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<2,R![36, 0, 120, 0, 109, 0, 22, 0, 1]>],Snew);
    return Vf;
end function;