Skip to content

Commit 6919e46

Browse files
committed
Use the context to compute things
1 parent d1f10f4 commit 6919e46

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

src/flint/types/_gr.pyx

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,10 +1850,7 @@ cdef class gr(flint_scalar):
18501850
return NotImplemented
18511851

18521852
def __pow__(self, other) -> gr:
1853-
if isinstance(other, int):
1854-
return self._pow_si(other)
1855-
else:
1856-
return NotImplemented
1853+
return self.ctx.pow(self, other)
18571854

18581855
def is_square(self):
18591856
"""Return whether the element is a square (may return ``None``).
@@ -1866,7 +1863,7 @@ cdef class gr(flint_scalar):
18661863
>>> Q(4).sqrt()
18671864
2
18681865
"""
1869-
return truth_to_py(self._is_square())
1866+
return truth_to_py(self.ctx.is_square(self))
18701867

18711868
def sqrt(self):
18721869
"""Return the square root of the element if it exists.
@@ -1875,7 +1872,7 @@ cdef class gr(flint_scalar):
18751872
>>> Z(4).sqrt()
18761873
2
18771874
"""
1878-
return self._sqrt()
1875+
return self.ctx.sqrt(self)
18791876

18801877
def rsqrt(self):
18811878
"""Return the reciprocal square root of the element if it exists.
@@ -1884,7 +1881,7 @@ cdef class gr(flint_scalar):
18841881
>>> Q(4).rsqrt()
18851882
1/2
18861883
"""
1887-
return self._rsqrt()
1884+
return self.ctx.rsqrt(self)
18881885

18891886
def gcd(self, other):
18901887
"""Return the greatest common divisor of two elements.
@@ -1914,7 +1911,7 @@ cdef class gr(flint_scalar):
19141911
other_gr = other
19151912
if not self.ctx == other_gr.ctx:
19161913
raise TypeError("gcd of gr with different contexts.")
1917-
return self._lcm(other_gr)
1914+
return self.ctx.lcm(self, other_gr)
19181915

19191916
def factor(self):
19201917
"""Return the factorization of the element.
@@ -1923,7 +1920,7 @@ cdef class gr(flint_scalar):
19231920
>>> Z(12).factor()
19241921
(1, [(2, 2), (3, 1)])
19251922
"""
1926-
return self._factor()
1923+
return self.ctx.factor(self)
19271924

19281925
def numer(self) -> gr:
19291926
"""Return the numerator of the element.
@@ -1937,7 +1934,7 @@ cdef class gr(flint_scalar):
19371934

19381935
See also :meth:`denom`.
19391936
"""
1940-
return self._numerator()
1937+
return self.ctx.numerator(self)
19411938

19421939
def denom(self) -> gr:
19431940
"""Return the denominator of the element.
@@ -1951,21 +1948,21 @@ cdef class gr(flint_scalar):
19511948

19521949
See also :meth:`numer`.
19531950
"""
1954-
return self._denominator()
1951+
return self.ctx.denominator(self)
19551952

19561953
def __floor__(self) -> gr:
1957-
return self._floor()
1954+
return self.ctx.floor(self)
19581955

19591956
def __ceil__(self) -> gr:
1960-
return self._ceil()
1957+
return self.ctx.ceil(self)
19611958

19621959
def __trunc__(self) -> gr:
1963-
return self._trunc()
1960+
return self.ctx.trunc(self)
19641961

19651962
def __round__(self, ndigits: int = 0) -> gr:
19661963
if ndigits != 0:
19671964
raise NotImplementedError("Rounding to a specific number of digits is not supported")
1968-
return self._nint()
1965+
return self.ctx.nint(self)
19691966

19701967
# def __int__(self) -> int:
19711968
# return self._floor().to_int()
@@ -1974,7 +1971,7 @@ cdef class gr(flint_scalar):
19741971
# return ...
19751972

19761973
def __abs__(self) -> gr:
1977-
return self._abs()
1974+
return self.ctx.abs(self)
19781975

19791976
def conjugate(self) -> gr:
19801977
"""Return complex conjugate of the element.
@@ -1984,7 +1981,7 @@ cdef class gr(flint_scalar):
19841981
>>> (1 + I).conjugate()
19851982
(1-I)
19861983
"""
1987-
return self._conj()
1984+
return self.ctx.conj(self)
19881985

19891986
@property
19901987
def real(self) -> gr:
@@ -1995,7 +1992,7 @@ cdef class gr(flint_scalar):
19951992
>>> (1 + I).real
19961993
1
19971994
"""
1998-
return self._re()
1995+
return self.ctx.re(self)
19991996

20001997
@property
20011998
def imag(self) -> gr:
@@ -2006,7 +2003,7 @@ cdef class gr(flint_scalar):
20062003
>>> (1 + I).imag
20072004
1
20082005
"""
2009-
return self._im()
2006+
return self.ctx.im(self)
20102007

20112008
# XXX: Return -1, 0, 1 as int?
20122009
def sgn(self) -> gr:
@@ -2020,7 +2017,7 @@ cdef class gr(flint_scalar):
20202017
>>> Q(0).sgn()
20212018
0
20222019
"""
2023-
return self._sgn()
2020+
return self.ctx.sgn(self)
20242021

20252022
def csgn(self) -> gr:
20262023
"""Return the complex sign of the element.
@@ -2030,7 +2027,7 @@ cdef class gr(flint_scalar):
20302027
>>> (1 + C.i()).csgn() # doctest: +SKIP
20312028
1
20322029
"""
2033-
return self._csgn()
2030+
return self.ctx.csgn(self)
20342031

20352032
def arg(self) -> gr:
20362033
"""Return the argument of the element.
@@ -2040,4 +2037,4 @@ cdef class gr(flint_scalar):
20402037
>>> (1 + C.i()).arg()
20412038
[0.785 +/- 6.45e-4]
20422039
"""
2043-
return self._arg()
2040+
return self.ctx.arg(self)

0 commit comments

Comments
 (0)