Skip to content

Commit 8613fd3

Browse files
committed
gr: Add is_{zero,one,neg_one} to contexts
1 parent 9dfcbf2 commit 8613fd3

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/flint/types/_gr.pxd

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,18 @@ cdef class gr_ctx(flint_ctx):
378378
gr_vec_clear(gens, self.ctx_t)
379379
return py_gens
380380

381+
@cython.final
382+
cdef inline truth_t _is_zero(self, gr x):
383+
return gr_is_zero(x.pval, self.ctx_t)
384+
385+
@cython.final
386+
cdef inline truth_t _is_one(self, gr x):
387+
return gr_is_one(x.pval, self.ctx_t)
388+
389+
@cython.final
390+
cdef inline truth_t _is_neg_one(self, gr x):
391+
return gr_is_neg_one(x.pval, self.ctx_t)
392+
381393
# @cython.final
382394
# cdef inline list _gens_recursive(self):
383395
# cdef int err

src/flint/types/_gr.pyx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,48 @@ cdef class gr_ctx(flint_ctx):
355355
"""
356356
return self._gens()
357357

358+
def is_zero(self, x) -> bool | None:
359+
"""
360+
Returns whether x is equal to the ring element 0.
361+
362+
>>> from flint.types._gr import gr_real_arb_ctx
363+
>>> ctx = gr_real_arb_ctx.new(10)
364+
>>> ctx.is_zero(ctx(0))
365+
True
366+
>>> ctx.is_zero(ctx(1))
367+
False
368+
>>> ctx.is_zero(ctx("[0 +/- 0.1]"))
369+
"""
370+
return truth_to_py(self._is_zero(x))
371+
372+
def is_one(self, x) -> bool | None:
373+
"""
374+
Returns whether x is equal to the ring element 1.
375+
376+
>>> from flint.types._gr import gr_real_arb_ctx
377+
>>> ctx = gr_real_arb_ctx.new(10)
378+
>>> ctx.is_one(ctx(0))
379+
False
380+
>>> ctx.is_one(ctx(1))
381+
True
382+
>>> ctx.is_one(ctx("[1 +/- 0.1]"))
383+
"""
384+
return truth_to_py(self._is_one(x))
385+
386+
def is_neg_one(self, x) -> bool | None:
387+
"""
388+
Returns whether x is equal to the ring element -1.
389+
390+
>>> from flint.types._gr import gr_real_arb_ctx
391+
>>> ctx = gr_real_arb_ctx.new(10)
392+
>>> ctx.is_neg_one(ctx(1))
393+
False
394+
>>> ctx.is_neg_one(ctx(-1))
395+
True
396+
>>> ctx.is_neg_one(ctx("[-1 +/- 0.1]"))
397+
"""
398+
return truth_to_py(self._is_neg_one(x))
399+
358400
# def gens_recursive(self) -> list[gr]:
359401
# """Return all generators of the domain
360402

0 commit comments

Comments
 (0)