Skip to content

Commit 6d164a1

Browse files
committed
typ: Fix mpoly_p typing protocol
1 parent 5bca700 commit 6d164a1

File tree

5 files changed

+156
-128
lines changed

5 files changed

+156
-128
lines changed

src/flint/types/fmpq_mpoly.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class fmpq_mpoly_ctx(flint_mpoly_context[fmpq_mpoly, fmpq, ifmpq]):
2828

2929
class fmpq_mpoly(flint_mpoly[fmpq_mpoly_ctx, fmpq, ifmpq]):
3030
def __init__(self,
31-
val: fmpq_mpoly | fmpz_mpoly | ifmpq | dict[tuple[int, ...], ifmpq] | _str = 0,
31+
val: fmpq_mpoly | fmpz_mpoly | ifmpq | Mapping[tuple[int, ...], ifmpq] | _str = 0,
3232
ctx: fmpq_mpoly_ctx | None = None
3333
) -> None: ...
3434

@@ -53,7 +53,7 @@ class fmpq_mpoly(flint_mpoly[fmpq_mpoly_ctx, fmpq, ifmpq]):
5353
def __getitem__(self, index: tuple[int, ...]) -> fmpq: ...
5454
def __setitem__(self, index: tuple[int, ...], coeff: ifmpq) -> None: ...
5555

56-
def subs(self, mapping: dict[_str | int, ifmpq]) -> fmpq_mpoly: ...
56+
def subs(self, mapping: Mapping[_str | int, ifmpq]) -> fmpq_mpoly: ...
5757
def compose(self, *args: fmpq_mpoly, ctx: fmpq_mpoly_ctx | None = None) -> fmpq_mpoly: ...
5858

5959
def __call__(self, *args: ifmpq) -> fmpq: ...

src/flint/types/fmpz_mod_mpoly.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class fmpz_mod_mpoly_ctx(flint_mod_mpoly_context[fmpz_mod_mpoly, fmpz_mod, ifmpz
3131

3232
class fmpz_mod_mpoly(flint_mpoly[fmpz_mod_mpoly_ctx, fmpz_mod, ifmpz_mod]):
3333
def __init__(self,
34-
val: fmpz_mod_mpoly | fmpz_mpoly | ifmpz_mod | dict[tuple[int, ...], ifmpz_mod] | _str = 0,
34+
val: fmpz_mod_mpoly | fmpz_mpoly | ifmpz_mod | Mapping[tuple[int, ...], ifmpz_mod] | _str = 0,
3535
ctx: fmpz_mod_mpoly_ctx | None = None
3636
) -> None: ...
3737

@@ -56,7 +56,7 @@ class fmpz_mod_mpoly(flint_mpoly[fmpz_mod_mpoly_ctx, fmpz_mod, ifmpz_mod]):
5656
def __getitem__(self, index: tuple[int, ...]) -> fmpz_mod: ...
5757
def __setitem__(self, index: tuple[int, ...], coeff: ifmpz_mod) -> None: ...
5858

59-
def subs(self, mapping: dict[_str | int, ifmpz_mod]) -> fmpz_mod_mpoly: ...
59+
def subs(self, mapping: Mapping[_str | int, ifmpz_mod]) -> fmpz_mod_mpoly: ...
6060
def compose(self, *args: fmpz_mod_mpoly, ctx: fmpz_mod_mpoly_ctx | None = None) -> fmpz_mod_mpoly: ...
6161

6262
def __call__(self, *args: ifmpz_mod) -> fmpz_mod: ...

src/flint/types/fmpz_mpoly.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class fmpz_mpoly_ctx(flint_mpoly_context[fmpz_mpoly, fmpz, ifmpz]):
2727
class fmpz_mpoly(flint_mpoly[fmpz_mpoly_ctx, fmpz, ifmpz]):
2828

2929
def __init__(self,
30-
val: fmpz_mpoly | ifmpz | dict[tuple[int, ...], ifmpz] | _str = 0,
30+
val: fmpz_mpoly | ifmpz | Mapping[tuple[int, ...], ifmpz] | _str = 0,
3131
ctx: fmpz_mpoly_ctx | None = None
3232
) -> None: ...
3333

@@ -52,7 +52,7 @@ class fmpz_mpoly(flint_mpoly[fmpz_mpoly_ctx, fmpz, ifmpz]):
5252
def __getitem__(self, index: tuple[int, ...]) -> fmpz: ...
5353
def __setitem__(self, index: tuple[int, ...], coeff: ifmpz) -> None: ...
5454

55-
def subs(self, mapping: dict[_str | int, ifmpz]) -> fmpz_mpoly: ...
55+
def subs(self, mapping: Mapping[_str | int, ifmpz]) -> fmpz_mpoly: ...
5656
def compose(self, *args: fmpz_mpoly, ctx: fmpz_mpoly_ctx | None = None) -> fmpz_mpoly: ...
5757

5858
def __call__(self, *args: ifmpz) -> fmpz: ...

src/flint/types/nmod_mpoly.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class nmod_mpoly_ctx(flint_mpoly_context[nmod_mpoly, nmod, inmod]):
3232

3333
class nmod_mpoly(flint_mpoly[nmod_mpoly_ctx, nmod, inmod]):
3434
def __init__(self,
35-
val: nmod_mpoly | fmpz_mpoly | inmod | dict[tuple[int, ...], inmod] | _str = 0,
35+
val: nmod_mpoly | fmpz_mpoly | inmod | Mapping[tuple[int, ...], inmod] | _str = 0,
3636
ctx: nmod_mpoly_ctx | None = None
3737
) -> None: ...
3838

@@ -57,7 +57,7 @@ class nmod_mpoly(flint_mpoly[nmod_mpoly_ctx, nmod, inmod]):
5757
def __getitem__(self, index: tuple[int, ...]) -> nmod: ...
5858
def __setitem__(self, index: tuple[int, ...], coeff: inmod) -> None: ...
5959

60-
def subs(self, mapping: dict[_str | int, inmod]) -> nmod_mpoly: ...
60+
def subs(self, mapping: Mapping[_str | int, inmod]) -> nmod_mpoly: ...
6161
def compose(self, *args: nmod_mpoly, ctx: nmod_mpoly_ctx | None = None) -> nmod_mpoly: ...
6262

6363
def __call__(self, *args: inmod) -> nmod: ...

src/flint/typing.py

Lines changed: 148 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#
22
#
33
#
4+
from __future__ import annotations
5+
46
from typing import (
57
TYPE_CHECKING,
68
Protocol,
@@ -39,9 +41,9 @@
3941
"elem_p",
4042
"scalar_p",
4143
"poly_p",
42-
# "mpoly_p",
43-
# "mpoly_context_p",
4444
# "series_p",
45+
"mpoly_p",
46+
"mpoly_context_p",
4547

4648
# Types
4749
"Ordering",
@@ -50,16 +52,8 @@
5052
]
5153

5254

53-
if TYPE_CHECKING:
54-
import flint as _flint
55-
56-
5755
_Telem = TypeVar("_Telem", bound=flint_scalar)
58-
_Telem_co = TypeVar("_Telem_co", bound=flint_scalar, covariant=True)
59-
_Telem_coerce = TypeVar("_Telem_coerce")
60-
_Telem_coerce_contra = TypeVar("_Telem_coerce_contra", contravariant=True)
61-
_Tmpoly = TypeVar("_Tmpoly", bound=flint_mpoly, covariant=True)
62-
_Tctx = TypeVar("_Tctx", bound=flint_mpoly_context)
56+
_Telem_contra = TypeVar("_Telem_contra", bound=flint_scalar, contravariant=True)
6357
_Sctx = TypeVar("_Sctx", bound=flint_mpoly_context)
6458

6559
_str = str
@@ -149,101 +143,106 @@ def factor_squarefree(self) -> tuple[_Tscalar, list[tuple[Self, int]]]: ...
149143
def deflation(self) -> tuple[Self, int]: ...
150144

151145

152-
class _mpoly_p(elem_p, Protocol[_Tctx, _Telem, _Telem_coerce]):
153-
"""FLINT multivariate polynomial Protocol."""
154-
def __init__(
155-
self,
156-
val: Self
157-
| _Telem
158-
| _Telem_coerce
159-
| int
160-
| dict[tuple[int, ...], _Telem | _Telem_coerce | int]
161-
| str = 0,
162-
ctx: _Tctx | None = None,
163-
) -> None: ...
164-
def str(self) -> _str: ...
165-
def repr(self) -> _str: ...
166-
def context(self) -> _Tctx: ...
167-
def degrees(self) -> tuple[int, ...]: ...
168-
def total_degree(self) -> int: ...
169-
def leading_coefficient(self) -> _Telem: ...
170-
def to_dict(self) -> dict[tuple[int, ...], _Telem]: ...
171-
def is_one(self) -> bool: ...
172-
def is_zero(self) -> bool: ...
173-
def is_constant(self) -> bool: ...
174-
def __len__(self) -> int: ...
175-
def __getitem__(self, index: tuple[int, ...]) -> _Telem: ...
176-
def __setitem__(
177-
self, index: tuple[int, ...], coeff: _Telem | _Telem_coerce | int
178-
) -> None: ...
179-
def __iter__(self) -> Iterable[tuple[int, ...]]: ...
180-
def __contains__(self, index: tuple[int, ...]) -> bool: ...
181-
def coefficient(self, i: int) -> _Telem: ...
182-
def monomial(self, i: int) -> tuple[int, ...]: ...
183-
def terms(self) -> Iterable[tuple[tuple[int, ...], _Telem]]: ...
184-
def monoms(self) -> list[tuple[int, ...]]: ...
146+
class _series_p(elem_p, Protocol[_Telem]):
147+
"""FLINT univariate power series."""
148+
149+
def __iter__(self) -> Iterator[_Telem]: ...
185150
def coeffs(self) -> list[_Telem]: ...
186-
def __pos__(self) -> Self: ...
187-
def __neg__(self) -> Self: ...
188-
def __add__(self, other: Self | _Telem | _Telem_coerce | int) -> Self: ...
189-
def __radd__(self, other: _Telem | _Telem_coerce | int) -> Self: ...
190-
def __sub__(self, other: Self | _Telem | _Telem_coerce | int) -> Self: ...
191-
def __rsub__(self, other: _Telem | _Telem_coerce | int) -> Self: ...
192-
def __mul__(self, other: Self | _Telem | _Telem_coerce | int) -> Self: ...
193-
def __rmul__(self, other: _Telem | _Telem_coerce | int) -> Self: ...
194-
def __truediv__(self, other: Self | _Telem | _Telem_coerce | int) -> Self: ...
195-
def __rtruediv__(self, other: _Telem | _Telem_coerce | int) -> Self: ...
196-
def __floordiv__(self, other: Self | _Telem | _Telem_coerce | int) -> Self: ...
197-
def __rfloordiv__(self, other: _Telem | _Telem_coerce | int) -> Self: ...
198-
def __mod__(self, other: Self | _Telem | _Telem_coerce | int) -> Self: ...
199-
def __rmod__(self, other: _Telem | _Telem_coerce | int) -> Self: ...
200-
def __divmod__(
201-
self, other: Self | _Telem | _Telem_coerce | int
202-
) -> tuple[Self, Self]: ...
203-
def __rdivmod__(self, other: _Telem | _Telem_coerce | int) -> tuple[Self, Self]: ...
204-
def __pow__(self, other: _Telem | _Telem_coerce | int) -> Self: ...
205-
def __rpow__(self, other: _Telem | _Telem_coerce | int) -> Self: ...
206-
def iadd(self, other: _Telem | _Telem_coerce | int) -> None: ...
207-
def isub(self, other: _Telem | _Telem_coerce | int) -> None: ...
208-
def imul(self, other: _Telem | _Telem_coerce | int) -> None: ...
209-
def gcd(self, other: Self) -> Self: ...
210-
def term_content(self) -> Self: ...
211-
def factor(self) -> tuple[_Telem, Sequence[tuple[Self, int]]]: ...
212-
def factor_squarefree(self) -> tuple[_Telem, Sequence[tuple[Self, int]]]: ...
213-
def sqrt(self) -> Self: ...
214-
def resultant(self, other: Self, var: _str | int) -> Self: ...
215-
def discriminant(self, var: _str | int) -> Self: ...
216-
def deflation_index(self) -> tuple[list[int], list[int]]: ...
217-
def deflation(self) -> tuple[Self, list[int]]: ...
218-
def deflation_monom(self) -> tuple[Self, list[int], Self]: ...
219-
def inflate(self, N: list[int]) -> Self: ...
220-
def deflate(self, N: list[int]) -> Self: ...
221-
def subs(self, mapping: dict[_str | int, _Telem | _Telem_coerce | int]) -> Self: ...
222-
def compose(self, *args: Self, ctx: _Tctx | None = None) -> Self: ...
223-
def __call__(self, *args: _Telem | _Telem_coerce) -> _Telem: ...
224-
def derivative(self, var: _str | int) -> Self: ...
225-
def unused_gens(self) -> tuple[_str, ...]: ...
226-
def project_to_context(
227-
self, other_ctx: _Tctx, mapping: dict[_str | int, _str | int] | None = None
228-
) -> Self: ...
229-
230-
231-
class _mpoly_context_p(
232-
elem_p, Protocol[_Tmpoly, _Telem_co, _Telem_coerce_contra]
233-
):
234-
"""FLINT multivariate polynomial context protocol."""
151+
152+
153+
class mpoly_p(elem_p, Protocol[_Telem]):
154+
def __init__(
155+
self,
156+
val: Self
157+
| _Telem
158+
| int
159+
| Mapping[tuple[int, ...], _Telem | int]
160+
| str = 0,
161+
ctx: Any | None = None,
162+
) -> None: ...
163+
def str(self) -> _str: ...
164+
def repr(self) -> _str: ...
165+
def context(self) -> mpoly_context_p[Self, _Telem]: ...
166+
def degrees(self) -> tuple[int, ...]: ...
167+
def total_degree(self) -> int: ...
168+
def leading_coefficient(self) -> _Telem: ...
169+
def to_dict(self) -> dict[tuple[int, ...], _Telem]: ...
170+
def is_one(self) -> bool: ...
171+
def is_zero(self) -> bool: ...
172+
def is_constant(self) -> bool: ...
173+
def __len__(self) -> int: ...
174+
def __getitem__(self, index: tuple[int, ...]) -> _Telem: ...
175+
def __setitem__(
176+
self, index: tuple[int, ...], coeff: _Telem | int
177+
) -> None: ...
178+
def __iter__(self) -> Iterable[tuple[int, ...]]: ...
179+
def __contains__(self, index: tuple[int, ...]) -> bool: ...
180+
def coefficient(self, i: int) -> _Telem: ...
181+
def monomial(self, i: int) -> tuple[int, ...]: ...
182+
def terms(self) -> Iterable[tuple[tuple[int, ...], _Telem]]: ...
183+
def monoms(self) -> list[tuple[int, ...]]: ...
184+
def coeffs(self) -> list[_Telem]: ...
185+
def __pos__(self) -> Self: ...
186+
def __neg__(self) -> Self: ...
187+
def __add__(self, other: Self | _Telem | int) -> Self: ...
188+
def __radd__(self, other: _Telem | int) -> Self: ...
189+
def __sub__(self, other: Self | _Telem | int) -> Self: ...
190+
def __rsub__(self, other: _Telem | int) -> Self: ...
191+
def __mul__(self, other: Self | _Telem | int) -> Self: ...
192+
def __rmul__(self, other: _Telem | int) -> Self: ...
193+
def __truediv__(self, other: Self | _Telem | int) -> Self: ...
194+
def __rtruediv__(self, other: _Telem | int) -> Self: ...
195+
def __floordiv__(self, other: Self | _Telem | int) -> Self: ...
196+
def __rfloordiv__(self, other: _Telem | int) -> Self: ...
197+
def __mod__(self, other: Self | _Telem | int) -> Self: ...
198+
def __rmod__(self, other: _Telem | int) -> Self: ...
199+
def __divmod__(
200+
self, other: Self | _Telem | int
201+
) -> tuple[Self, Self]: ...
202+
def __rdivmod__(self, other: _Telem | int) -> tuple[Self, Self]: ...
203+
def __pow__(self, other: _Telem | int) -> Self: ...
204+
def __rpow__(self, other: _Telem | int) -> Self: ...
205+
def iadd(self, other: _Telem | int) -> None: ...
206+
def isub(self, other: _Telem | int) -> None: ...
207+
def imul(self, other: _Telem | int) -> None: ...
208+
def gcd(self, other: Self) -> Self: ...
209+
def term_content(self) -> Self: ...
210+
def factor(self) -> tuple[_Telem, Sequence[tuple[Self, int]]]: ...
211+
def factor_squarefree(self) -> tuple[_Telem, Sequence[tuple[Self, int]]]: ...
212+
def sqrt(self) -> Self: ...
213+
def resultant(self, other: Self, var: _str | int) -> Self: ...
214+
def discriminant(self, var: _str | int) -> Self: ...
215+
def deflation_index(self) -> tuple[list[int], list[int]]: ...
216+
def deflation(self) -> tuple[Self, list[int]]: ...
217+
def deflation_monom(self) -> tuple[Self, list[int], Self]: ...
218+
def inflate(self, N: list[int]) -> Self: ...
219+
def deflate(self, N: list[int]) -> Self: ...
220+
def subs(self, mapping: Mapping[_str | int, _Telem | int]) -> Self: ...
221+
def compose(self, *args: Self, ctx: Any | None = None) -> Self: ...
222+
def __call__(self, *args: _Telem) -> _Telem: ...
223+
def derivative(self, var: _str | int) -> Self: ...
224+
def unused_gens(self) -> tuple[_str, ...]: ...
225+
def project_to_context(
226+
self, other_ctx: Any, mapping: dict[_str | int, _str | int] | None = None
227+
) -> Self: ...
228+
229+
230+
_Tmpoly_p = TypeVar("_Tmpoly_p", bound=mpoly_p, covariant=True)
231+
232+
233+
class mpoly_context_p(elem_p, Protocol[_Tmpoly_p, _Telem_contra]):
235234
def nvars(self) -> int: ...
236235
def ordering(self) -> Ordering: ...
237-
def gen(self, i: int, /) -> _Tmpoly: ...
238-
def from_dict(self, d: Mapping[tuple[int, ...], _Telem_coerce_contra], /) -> _Tmpoly: ...
239-
def constant(self, z: _Telem_coerce_contra, /) -> _Tmpoly: ...
236+
def gen(self, i: int, /) -> _Tmpoly_p: ...
237+
def from_dict(self, d: Mapping[tuple[int, ...], _Telem_contra], /) -> _Tmpoly_p: ...
238+
def constant(self, z: _Telem_contra, /) -> _Tmpoly_p: ...
240239
def name(self, i: int, /) -> str: ...
241240
def names(self) -> tuple[str]: ...
242-
def gens(self) -> tuple[_Tmpoly, ...]: ...
241+
def gens(self) -> tuple[_Tmpoly_p, ...]: ...
243242
def variable_to_index(self, var: str, /) -> int: ...
244243
def term(
245-
self, coeff: _Telem_coerce_contra | None = None, exp_vec: Iterable[int] | None = None
246-
) -> _Tmpoly: ...
244+
self, coeff: _Telem_contra | None = None, exp_vec: Iterable[int] | None = None
245+
) -> _Tmpoly_p: ...
247246
def drop_gens(self, gens: Iterable[str | int], /) -> Self: ...
248247
def append_gens(self, gens: Iterable[str | int], /) -> Self: ...
249248
def infer_generator_mapping(
@@ -258,31 +257,60 @@ def from_context(
258257
) -> _Sctx: ...
259258

260259

261-
class _series_p(elem_p, Protocol[_Telem]):
262-
"""FLINT univariate power series."""
260+
if TYPE_CHECKING:
263261

264-
def __iter__(self) -> Iterator[_Telem]: ...
265-
def coeffs(self) -> list[_Telem]: ...
262+
import flint as _f
266263

264+
_x1: scalar_p = _f.fmpz(1)
265+
_x2: scalar_p = _f.fmpq(1, 2)
266+
_x3: scalar_p = _f.nmod(1, 2)
267+
_x4: scalar_p = _f.fmpz_mod(1, _f.fmpz_mod_ctx(2))
268+
_x5: scalar_p = _f.fq_default(1, _f.fq_default_ctx(2))
269+
# XXX: Add arf, acf, arb, acb, ...
267270

268-
if TYPE_CHECKING:
271+
_Tscalar0 = TypeVar("_Tscalar0", bound=scalar_p)
269272

270-
_x1: scalar_p = _flint.fmpz(1)
271-
_x2: scalar_p = _flint.fmpq(1, 2)
272-
_x3: scalar_p = _flint.nmod(1, 2)
273-
_x4: scalar_p = _flint.fmpz_mod(1, _flint.fmpz_mod_ctx(2))
274-
_x5: scalar_p = _flint.fq_default(1, _flint.fq_default_ctx(2))
275-
# XXX: Add arf, acf, arb, acb, ...
273+
def _scalar(x: _Tscalar0, y: _Tscalar0) -> _Tscalar0:
274+
z = x + y + 1
275+
z = z / z + x**2
276+
z = 1 / z + 1**z
277+
return z
276278

277-
_y1: poly_p[_flint.fmpz] = _flint.fmpz_poly([1, 2])
278-
_y2: poly_p[_flint.fmpq] = _flint.fmpq_poly([1, 2])
279-
_y3: poly_p[_flint.nmod] = _flint.nmod_poly(1, 2)
280-
_y4: poly_p[_flint.fmpz_mod] = _flint.fmpz_mod_poly(1, _flint.fmpz_mod_poly_ctx(2))
281-
_y5: poly_p[_flint.fq_default] = _flint.fq_default_poly(1, _flint.fq_default_poly_ctx(2))
279+
_y1: poly_p[_f.fmpz] = _f.fmpz_poly([1, 2])
280+
_y2: poly_p[_f.fmpq] = _f.fmpq_poly([1, 2])
281+
_y3: poly_p[_f.nmod] = _f.nmod_poly(1, 2)
282+
_y4: poly_p[_f.fmpz_mod] = _f.fmpz_mod_poly(1, _f.fmpz_mod_poly_ctx(2))
283+
_y5: poly_p[_f.fq_default] = _f.fq_default_poly(1, _f.fq_default_poly_ctx(2))
282284
# XXX: Add arb_poly, acb_poly, ...
283285

284-
_z1: epoly_p[_flint.fmpz] = _flint.fmpz_poly([1, 2])
285-
_z2: epoly_p[_flint.fmpq] = _flint.fmpq_poly([1, 2])
286-
_z3: epoly_p[_flint.nmod] = _flint.nmod_poly(1, 2)
287-
_z4: epoly_p[_flint.fmpz_mod] = _flint.fmpz_mod_poly(1, _flint.fmpz_mod_poly_ctx(2))
288-
_z5: epoly_p[_flint.fq_default] = _flint.fq_default_poly(1, _flint.fq_default_poly_ctx(2))
286+
def _poly(x: epoly_p[_Tscalar0], y: epoly_p[_Tscalar0]) -> epoly_p[_Tscalar0]:
287+
z = x + y + 1
288+
z = z / z + x**2
289+
z = 1 / z + z.coeffs()[0]
290+
return z
291+
292+
_z1: epoly_p[_f.fmpz] = _f.fmpz_poly([1, 2])
293+
_z2: epoly_p[_f.fmpq] = _f.fmpq_poly([1, 2])
294+
_z3: epoly_p[_f.nmod] = _f.nmod_poly(1, 2)
295+
_z4: epoly_p[_f.fmpz_mod] = _f.fmpz_mod_poly(1, _f.fmpz_mod_poly_ctx(2))
296+
_z5: epoly_p[_f.fq_default] = _f.fq_default_poly(1, _f.fq_default_poly_ctx(2))
297+
298+
def _epoly(x: epoly_p[_Tscalar0], y: epoly_p[_Tscalar0]) -> epoly_p[_Tscalar0]:
299+
return x.gcd(y).factor()[1][0][0]
300+
301+
_ctx1: mpoly_context_p[_f.fmpz_mpoly, _f.fmpz] = _f.fmpz_mpoly_ctx.get(['x', 'y'])
302+
_ctx2: mpoly_context_p[_f.fmpq_mpoly, _f.fmpq] = _f.fmpq_mpoly_ctx.get(['x', 'y'])
303+
_ctx3: mpoly_context_p[_f.nmod_mpoly, _f.nmod] = _f.nmod_mpoly_ctx.get(['x', 'y'], modulus=7)
304+
_ctx4: mpoly_context_p[_f.fmpz_mod_mpoly, _f.fmpz_mod] = _f.fmpz_mod_mpoly_ctx.get(['x', 'y'], modulus=7)
305+
306+
_p1: mpoly_p[_f.fmpz] = _ctx1.gens()[0]
307+
_p2: mpoly_p[_f.fmpq] = _ctx2.gens()[0]
308+
_p3: mpoly_p[_f.nmod] = _ctx3.gens()[0]
309+
_p4: mpoly_p[_f.fmpz_mod] = _ctx4.gens()[0]
310+
311+
_Tmpoly0 = TypeVar("_Tmpoly0", bound=mpoly_p)
312+
313+
def _mpoly(x: mpoly_p[_Telem], y: mpoly_p[_Telem], ctx: mpoly_context_p[_Tmpoly0, _Telem]) -> mpoly_p[_Telem]:
314+
z = x.gcd(y).factor()[1][0][0] + ctx.gens()[0]
315+
t = z.compose(z, ctx=ctx) + z.context().gens()[0]
316+
return t

0 commit comments

Comments
 (0)