Skip to content

Commit e1036a0

Browse files
committed
type: annotations for fq_default and fq_default_poly
1 parent 5e387c9 commit e1036a0

File tree

3 files changed

+234
-14
lines changed

3 files changed

+234
-14
lines changed

src/flint/test/test_all.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4535,7 +4535,7 @@ def test_fq_default():
45354535
assert raises(lambda: flint.fq_default_ctx(5, fq_type="A"), ValueError)
45364536
assert raises(lambda: flint.fq_default_ctx(5, fq_type=[]), TypeError)
45374537
assert raises(lambda: flint.fq_default_ctx(5, fq_type=-1), ValueError)
4538-
assert raises(lambda: flint.fq_default_ctx("ABC"), TypeError)
4538+
assert raises(lambda: flint.fq_default_ctx("ABC"), TypeError) # type: ignore
45394539

45404540
# var must be one character
45414541
assert raises(lambda: flint.fq_default_ctx(5, var="XXX"), ValueError)
@@ -4614,8 +4614,8 @@ def test_fq_default():
46144614
assert gf_5.gen() == gf_5(R.gen())
46154615
assert gf_5.gen() == gf_5(flint.nmod_poly([0, 1], 5))
46164616
assert gf_5(flint.fmpz(2**64)) == gf_5(2**64)
4617-
assert raises(lambda: flint.fq_default(1, "AAA"), TypeError)
4618-
assert raises(lambda: flint.fq_default.__init__(1, "AAA"), TypeError)
4617+
assert raises(lambda: flint.fq_default(1, "AAA"), TypeError) # type: ignore
4618+
assert raises(lambda: flint.fq_default.__init__(1, "AAA"), TypeError) # type: ignore
46194619
assert raises(lambda: flint.fq_default("AAA", gf_5), TypeError)
46204620
assert raises(lambda: gf_5.one() + gf_5_2.one(), ValueError)
46214621
# testing various equalties between types
@@ -4682,10 +4682,10 @@ def test_fq_default():
46824682
assert (gf(0) != gf.zero()) is False
46834683
assert (gf(1) == gf.zero()) is False
46844684
assert (gf(1) != gf.zero()) is True
4685-
assert raises(lambda: gf.zero() > gf.zero(), TypeError)
4686-
assert raises(lambda: gf.zero() >= gf.zero(), TypeError)
4687-
assert raises(lambda: gf.zero() < gf.zero(), TypeError)
4688-
assert raises(lambda: gf.zero() <= gf.zero(), TypeError)
4685+
assert raises(lambda: gf.zero() > gf.zero(), TypeError) # type: ignore
4686+
assert raises(lambda: gf.zero() >= gf.zero(), TypeError) # type: ignore
4687+
assert raises(lambda: gf.zero() < gf.zero(), TypeError) # type: ignore
4688+
assert raises(lambda: gf.zero() <= gf.zero(), TypeError) # type: ignore
46894689

46904690
assert gf.zero().is_zero() is True
46914691
assert gf.one().is_zero() is False
@@ -4719,7 +4719,7 @@ def test_fq_default():
47194719
assert raises(lambda: a / 0, ZeroDivisionError)
47204720
assert raises(lambda: ~gf.zero(), ZeroDivisionError)
47214721
assert raises(lambda: pow(gf.zero(), -1), ZeroDivisionError)
4722-
assert raises(lambda: pow(gf.zero(), "A"), TypeError)
4722+
assert raises(lambda: pow(gf.zero(), "A"), TypeError) # type: ignore
47234723

47244724
assert 1/a == pow(a, -1) == ~a
47254725
assert gf.one() == pow(a, 0)
@@ -4742,7 +4742,7 @@ def test_fq_default_poly():
47424742
R2 = flint.fq_default_poly_ctx(11, 3)
47434743
R3 = flint.fq_default_poly_ctx(13, 5)
47444744

4745-
assert raises(lambda: flint.fq_default_poly_ctx("AAA"), TypeError)
4745+
assert raises(lambda: flint.fq_default_poly_ctx("AAA"), TypeError) # type: ignore
47464746
assert (R1 == R1) is True
47474747
assert hash(R1) == hash(R2)
47484748
assert (R1 != R1) is False
@@ -4760,10 +4760,10 @@ def test_fq_default_poly():
47604760
# random element failure
47614761
f = R1.random_element(not_zero=True)
47624762
assert not f.is_zero()
4763-
assert raises(lambda: R1.random_element(monic="AAA"), TypeError)
4763+
assert raises(lambda: R1.random_element(monic="AAA"), TypeError) # type: ignore
47644764
assert raises(lambda: R1.random_element(degree=-1), ValueError)
47654765

4766-
assert raises(lambda: flint.fq_default_poly([1,2,3], "AAA"), TypeError)
4766+
assert raises(lambda: flint.fq_default_poly([1,2,3], "AAA"), TypeError) # type: ignore
47674767

47684768
assert R1(0).leading_coefficient() == 0
47694769
assert raises(lambda: R1.random_element().reverse(degree=-1), ValueError)
@@ -4827,8 +4827,8 @@ def test_fq_default_poly():
48274827
assert pow(R_gen, 2**60, g) == pow(pow(R_gen, 2**30, g), 2**30, g)
48284828
assert raises(lambda: pow(f, -2, g), ValueError)
48294829
assert raises(lambda: pow(f, 1, "A"), TypeError)
4830-
assert raises(lambda: pow(f, "A", g), TypeError)
4831-
assert raises(lambda: f.pow_mod(2**32, g, mod_rev_inv="A"), TypeError)
4830+
assert raises(lambda: pow(f, "A", g), TypeError) # type: ignore
4831+
assert raises(lambda: f.pow_mod(2**32, g, mod_rev_inv="A"), TypeError) # type: ignore
48324832

48334833
# Shifts
48344834
assert raises(lambda: R_test([1,2,3]).left_shift(-1), ValueError)
@@ -4905,7 +4905,7 @@ def test_fq_default_poly():
49054905
assert f.sub_trunc(g, 3) == (f - g) % x**3
49064906

49074907
assert raises(lambda: f.mul_low("A", 1), TypeError)
4908-
assert raises(lambda: f.mul_low(g, "A"), TypeError)
4908+
assert raises(lambda: f.mul_low(g, "A"), TypeError) # type: ignore
49094909
assert raises(lambda: f.mul_low(f_cmp, 1), ValueError)
49104910
assert f.mul_low(g, 3) == (f * g) % x**3
49114911

src/flint/types/fq_default.pyi

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
from enum import Enum
2+
from ..flint_base.flint_base import flint_scalar
3+
from .fmpz import fmpz
4+
from .fmpz_mod import fmpz_mod, ifmpz
5+
from .fmpz_poly import fmpz_poly
6+
from .nmod_poly import nmod_poly
7+
from .fmpz_mod_poly import fmpz_mod_poly
8+
9+
class fq_default_type(Enum):
10+
DEFAULT = 0
11+
FQ_ZECH = 1
12+
FQ_NMOD = 2
13+
FQ = 3
14+
NMOD = 4
15+
FMPZ_MOD = 5
16+
17+
ifmpz_mod = ifmpz | fmpz_mod
18+
ifq_default = fq_default | fmpz_mod_poly | nmod_poly | fmpz_poly | ifmpz_mod
19+
20+
class fq_default_ctx:
21+
r"""Context object for creating :class:`~.fq_default`."""
22+
23+
def __init__(
24+
self,
25+
p: ifmpz | None = None,
26+
degree: int | None = None,
27+
var: str | None = None,
28+
modulus: fmpz_mod_poly | fmpz_poly | None = None,
29+
fq_type: str | int | fq_default_type = fq_default_type.DEFAULT,
30+
check_prime: bool = True,
31+
check_modulus: bool = True,
32+
): ...
33+
@property
34+
def fq_type(self) -> fq_default_type: ...
35+
def degree(self) -> int: ...
36+
def characteristic(self) -> fmpz: ...
37+
def prime(self) -> fmpz: ...
38+
def order(self) -> fmpz: ...
39+
def multiplicative_order(self) -> fmpz: ...
40+
def modulus(self) -> fmpz_mod_poly: ...
41+
def zero(self) -> fq_default: ...
42+
def one(self) -> fq_default: ...
43+
def gen(self) -> fq_default: ...
44+
def random_element(self, not_zero: bool = False) -> fq_default: ...
45+
def __call__(self, val: ifq_default) -> fq_default: ...
46+
47+
class fq_default(flint_scalar):
48+
def __init__(self, val: list[ifmpz] | ifq_default, ctx: fq_default_ctx): ...
49+
def __int__(self) -> int: ...
50+
def polynomial(self) -> fmpz_mod_poly: ...
51+
def to_list(self) -> list[ifmpz]: ...
52+
def str(self) -> str: ...
53+
def __hash__(self) -> int: ...
54+
def is_zero(self) -> bool: ...
55+
def is_one(self) -> bool: ...
56+
def inverse(self) -> fq_default: ...
57+
def square(self) -> fq_default: ...
58+
def __neg__(self) -> fq_default: ...
59+
def __add__(self, other: ifq_default, /) -> fq_default: ...
60+
def __radd__(self, other: ifq_default, /) -> fq_default: ...
61+
def __sub__(self, other: ifq_default, /) -> fq_default: ...
62+
def __rsub__(self, other: ifq_default, /) -> fq_default: ...
63+
def __mul__(self, other: ifq_default, /) -> fq_default: ...
64+
def __rmul__(self, other: ifq_default, /) -> fq_default: ...
65+
def __truediv__(self, other: ifq_default, /) -> fq_default: ...
66+
def __rtruediv__(self, other: ifq_default, /) -> fq_default: ...
67+
def __invert__(self) -> fq_default: ...
68+
def __pow__(self, e: ifmpz) -> fq_default: ...
69+
def sqrt(self) -> fq_default: ...
70+
def is_square(self) -> bool: ...
71+
def pth_root(self) -> fq_default: ...
72+
def trace(self) -> fmpz: ...
73+
def norm(self) -> fmpz: ...
74+
def frobenius(self, e: int = ...) -> fq_default: ...
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
from typing import overload
2+
from flint.flint_base.flint_base import flint_poly
3+
from .fmpz import fmpz, ifmpz
4+
from .fmpz_mod import fmpz_mod
5+
from .fmpz_poly import fmpz_poly, ifmpz_poly
6+
from .fmpz_mod_poly import fmpz_mod_poly
7+
from .fq_default import fq_default_type, fq_default_ctx, fq_default, ifq_default
8+
9+
ifmpz_mod = int | fmpz | fmpz_mod
10+
ifq_default_poly = fq_default_poly | ifq_default | ifmpz_poly
11+
12+
class fq_default_poly_ctx:
13+
r"""Context object for creating :class:`~.fq_default_poly` initialised
14+
with a finite field `GF(p^d)`.
15+
"""
16+
17+
@overload
18+
def __init__(self, p: fq_default_ctx, /) -> None: ...
19+
@overload
20+
def __init__(
21+
self,
22+
p: fq_default_ctx | ifmpz | None = None,
23+
degree: int | None = None,
24+
var: str | None = None,
25+
modulus: fmpz_mod_poly | fmpz_poly | None = None,
26+
fq_type: str | int | fq_default_type = fq_default_type.DEFAULT,
27+
check_prime: bool = True,
28+
check_modulus: bool = True,
29+
): ...
30+
def __init__(
31+
self,
32+
p: fq_default_ctx | ifmpz | None = None,
33+
degree: int | None = None,
34+
var: str | None = None,
35+
modulus: fmpz_mod_poly | fmpz_poly | None = None,
36+
fq_type: str | int | fq_default_type = fq_default_type.DEFAULT,
37+
check_prime: bool = True,
38+
check_modulus: bool = True,
39+
): ...
40+
def base_field(self) -> fq_default_ctx: ...
41+
def characteristic(self) -> fmpz: ...
42+
def prime(self) -> fmpz: ...
43+
def zero(self) -> fq_default_poly: ...
44+
def one(self) -> fq_default_poly: ...
45+
def gen(self) -> fq_default_poly: ...
46+
def random_element(
47+
self,
48+
degree: int = 3,
49+
not_zero: bool = False,
50+
monic: bool = False,
51+
irreducible: bool = False,
52+
) -> fq_default_poly: ...
53+
def __str__(self) -> str: ...
54+
def __repr__(self) -> str: ...
55+
def __call__(self, val: ifq_default_poly) -> fq_default_poly: ...
56+
57+
class fq_default_poly(flint_poly[fq_default]):
58+
"""
59+
The *fq_default_poly* type represents univariate polynomials
60+
over a finite field.
61+
"""
62+
63+
def __init__(
64+
self, other: ifq_default_poly | list[ifq_default], ctx: fq_default_poly_ctx, /
65+
) -> None: ...
66+
def __getitem__(self, i: int, /) -> fq_default: ...
67+
def __setitem__(self, i: int, x: ifq_default, /) -> None: ...
68+
def __len__(self) -> int: ...
69+
def length(self) -> int: ...
70+
def degree(self) -> int: ...
71+
def constant_coefficient(self) -> fq_default: ...
72+
def leading_coefficient(self) -> fq_default: ...
73+
def reverse(self, degree: int | None = None) -> fq_default_poly: ...
74+
def truncate(self, n: int) -> fq_default_poly: ...
75+
def monic(self) -> fq_default_poly: ...
76+
def is_zero(self) -> bool: ...
77+
def is_one(self) -> bool: ...
78+
def is_gen(self) -> bool: ...
79+
def is_constant(self) -> bool: ...
80+
def is_monic(self) -> bool: ...
81+
def is_irreducible(self) -> bool: ...
82+
def is_squarefree(self) -> bool: ...
83+
def __pos__(self) -> fq_default_poly: ...
84+
def __neg__(self) -> fq_default_poly: ...
85+
def __add__(self, other: ifq_default_poly, /) -> fq_default_poly: ...
86+
def __radd__(self, other: ifq_default_poly, /) -> fq_default_poly: ...
87+
def __sub__(self, other: ifq_default_poly, /) -> fq_default_poly: ...
88+
def __rsub__(self, other: ifq_default_poly, /) -> fq_default_poly: ...
89+
def __mul__(self, other: ifq_default_poly, /) -> fq_default_poly: ...
90+
def __rmul__(self, other: ifq_default_poly, /) -> fq_default_poly: ...
91+
def __floordiv__(self, other: ifq_default_poly, /) -> fq_default_poly: ...
92+
def __rfloordiv__(self, other: ifq_default_poly, /) -> fq_default_poly: ...
93+
def __mod__(self, other: ifq_default_poly, /) -> fq_default_poly: ...
94+
def __rmod__(self, other: ifq_default_poly, /) -> fq_default_poly: ...
95+
def __divmod__(
96+
self, other: ifq_default_poly, /
97+
) -> tuple[fq_default_poly, fq_default_poly]: ...
98+
def __rdivmod__(
99+
self, other: ifq_default_poly, /
100+
) -> tuple[fq_default_poly, fq_default_poly]: ...
101+
def __truediv__(self, other: ifq_default_poly, /) -> fq_default_poly: ...
102+
def __rtruediv__(self, other: ifq_default_poly, /) -> fq_default_poly: ...
103+
def __pow__(
104+
self, e: int, mod: ifq_default_poly | None = None
105+
) -> fq_default_poly: ...
106+
def pow_mod(self, e: int, modulus: ifq_default_poly) -> fq_default_poly: ...
107+
def divmod(
108+
self, other: ifq_default_poly
109+
) -> tuple[fq_default_poly, fq_default_poly]: ...
110+
def exact_division(self, other: ifq_default_poly) -> fq_default_poly: ...
111+
def gcd(self, other: ifq_default_poly) -> fq_default_poly: ...
112+
def xgcd(
113+
self, other: ifq_default_poly, /
114+
) -> tuple[fq_default_poly, fq_default_poly, fq_default_poly]: ...
115+
def square(self) -> fq_default_poly: ...
116+
def left_shift(self, n: int) -> fq_default_poly: ...
117+
def right_shift(self, n: int) -> fq_default_poly: ...
118+
def sqrt(self) -> fq_default_poly: ...
119+
def mul_mod(
120+
self, other: ifq_default_poly, modulus: ifq_default_poly
121+
) -> fq_default_poly: ...
122+
def equal_trunc(self, other: ifq_default_poly, n: int) -> bool: ...
123+
def add_trunc(self, other: ifq_default_poly, n: int) -> fq_default_poly: ...
124+
def sub_trunc(self, other: ifq_default_poly, n: int) -> fq_default_poly: ...
125+
def mul_low(self, other: ifq_default_poly, n: int) -> fq_default_poly: ...
126+
def pow_trunc(self, e: int, n: int) -> fq_default_poly: ...
127+
def sqrt_trunc(self, n: int) -> fq_default_poly: ...
128+
def inv_sqrt_trunc(self, n: int) -> fq_default_poly: ...
129+
def inverse_series_trunc(self, n: int) -> fq_default_poly: ...
130+
def inverse_mod(self, other: ifq_default_poly) -> fq_default_poly: ...
131+
def derivative(self) -> fq_default_poly: ...
132+
def radical(self) -> fq_default_poly: ...
133+
def inflate(self, n: int) -> fq_default_poly: ...
134+
def deflate(self, n: int) -> fq_default_poly: ...
135+
def deflation(self) -> tuple[fq_default_poly, int]: ...
136+
def __call__(self, input: fq_default_poly | ifq_default) -> fq_default_poly: ...
137+
def evaluate(self, input: ifq_default) -> fq_default_poly: ...
138+
def compose(self, other: ifq_default_poly) -> fq_default_poly: ...
139+
def compose_mod(
140+
self, other: ifq_default_poly, modulus: ifq_default_poly
141+
) -> fq_default_poly: ...
142+
def factor_squarefree(
143+
self,
144+
) -> tuple[fq_default_poly, list[tuple[fq_default_poly, int]]]: ...
145+
def factor(self) -> tuple[fq_default_poly, list[tuple[fq_default_poly, int]]]: ...
146+
def roots(self, multiplicities=True) -> list[tuple[fq_default, int]]: ...

0 commit comments

Comments
 (0)