@@ -156,23 +156,18 @@ cdef class acb(flint_scalar):
156156 return (self .real._mpf_, self .imag._mpf_)
157157
158158 def __richcmp__ (s , t , int op ):
159- cdef acb_struct sval[1 ]
160159 cdef acb_struct tval[1 ]
161160 cdef bint res
162- cdef int stype, ttype
161+ cdef int ttype
163162 if not (op == 2 or op == 3 ):
164163 raise ValueError (" comparing complex numbers" )
165- stype = acb_set_any_ref(sval, s)
166- if stype == FMPZ_UNKNOWN:
167- return NotImplemented
168164 ttype = acb_set_any_ref(tval, t)
169165 if ttype == FMPZ_UNKNOWN:
170166 return NotImplemented
171167 if op == 2 :
172- res = acb_eq(sval , tval)
168+ res = acb_eq(s.val , tval)
173169 else :
174- res = acb_ne(sval, tval)
175- if stype == FMPZ_TMP: acb_clear(sval)
170+ res = acb_ne(s.val, tval)
176171 if ttype == FMPZ_TMP: acb_clear(tval)
177172 return res
178173
@@ -363,92 +358,114 @@ cdef class acb(flint_scalar):
363358 return res
364359
365360 def __add__ (s , t ):
366- cdef acb_struct sval[1 ]
367361 cdef acb_struct tval[1 ]
368- cdef int stype, ttype
369- stype = acb_set_any_ref(sval, s )
370- if stype == FMPZ_UNKNOWN:
362+ cdef int ttype
363+ ttype = acb_set_any_ref(tval, t )
364+ if ttype == FMPZ_UNKNOWN:
371365 return NotImplemented
366+ u = acb.__new__ (acb)
367+ acb_add((< acb> u).val, s.val, tval, getprec())
368+ if ttype == FMPZ_TMP: acb_clear(tval)
369+ return u
370+
371+ def __radd__ (s , t ):
372+ cdef acb_struct tval[1 ]
373+ cdef int ttype
372374 ttype = acb_set_any_ref(tval, t)
373375 if ttype == FMPZ_UNKNOWN:
374376 return NotImplemented
375377 u = acb.__new__ (acb)
376- acb_add((< acb> u).val, sval, tval, getprec())
377- if stype == FMPZ_TMP: acb_clear(sval)
378+ acb_add((< acb> u).val, tval, s.val, getprec())
378379 if ttype == FMPZ_TMP: acb_clear(tval)
379380 return u
380381
381382 def __sub__ (s , t ):
382- cdef acb_struct sval[1 ]
383383 cdef acb_struct tval[1 ]
384- cdef int stype, ttype
385- stype = acb_set_any_ref(sval, s )
386- if stype == FMPZ_UNKNOWN:
384+ cdef int ttype
385+ ttype = acb_set_any_ref(tval, t )
386+ if ttype == FMPZ_UNKNOWN:
387387 return NotImplemented
388+ u = acb.__new__ (acb)
389+ acb_sub((< acb> u).val, s.val, tval, getprec())
390+ if ttype == FMPZ_TMP: acb_clear(tval)
391+ return u
392+
393+ def __rsub__ (s , t ):
394+ cdef acb_struct tval[1 ]
395+ cdef int ttype
388396 ttype = acb_set_any_ref(tval, t)
389397 if ttype == FMPZ_UNKNOWN:
390398 return NotImplemented
391399 u = acb.__new__ (acb)
392- acb_sub((< acb> u).val, sval, tval, getprec())
393- if stype == FMPZ_TMP: acb_clear(sval)
400+ acb_sub((< acb> u).val, tval, s.val, getprec())
394401 if ttype == FMPZ_TMP: acb_clear(tval)
395402 return u
396403
397404 def __mul__ (s , t ):
398- cdef acb_struct sval[1 ]
399405 cdef acb_struct tval[1 ]
400- cdef int stype, ttype
401- stype = acb_set_any_ref(sval, s)
402- if stype == FMPZ_UNKNOWN:
403- return NotImplemented
406+ cdef int ttype
404407 ttype = acb_set_any_ref(tval, t)
405408 if ttype == FMPZ_UNKNOWN:
406409 return NotImplemented
407410 u = acb.__new__ (acb)
408- acb_mul((< acb> u).val, sval, tval, getprec())
409- if stype == FMPZ_TMP: acb_clear(sval)
411+ acb_mul((< acb> u).val, s.val, tval, getprec())
410412 if ttype == FMPZ_TMP: acb_clear(tval)
411413 return u
412414
413- # important: must not be cdef because of cython magic
414- @staticmethod
415- def _div_ (s , t ):
416- cdef acb_struct sval[1 ]
415+ def __rmul__ (s , t ):
417416 cdef acb_struct tval[1 ]
418- cdef int stype, ttype
419- stype = acb_set_any_ref(sval, s)
420- if stype == FMPZ_UNKNOWN:
421- return NotImplemented
417+ cdef int ttype
422418 ttype = acb_set_any_ref(tval, t)
423419 if ttype == FMPZ_UNKNOWN:
424420 return NotImplemented
425421 u = acb.__new__ (acb)
426- acb_div((< acb> u).val, sval, tval, getprec())
427- if stype == FMPZ_TMP: acb_clear(sval)
422+ acb_mul((< acb> u).val, tval, s.val, getprec())
428423 if ttype == FMPZ_TMP: acb_clear(tval)
429424 return u
430425
431426 def __truediv__ (s , t ):
432- return acb._div_(s, t)
427+ cdef acb_struct tval[1 ]
428+ cdef int ttype
429+ ttype = acb_set_any_ref(tval, t)
430+ if ttype == FMPZ_UNKNOWN:
431+ return NotImplemented
432+ u = acb.__new__ (acb)
433+ acb_div((< acb> u).val, s.val, tval, getprec())
434+ if ttype == FMPZ_TMP: acb_clear(tval)
435+ return u
433436
434- def __div__ (s , t ):
435- return acb._div_(s, t)
437+ def __rtruediv__ (s , t ):
438+ cdef acb_struct tval[1 ]
439+ cdef int ttype
440+ ttype = acb_set_any_ref(tval, t)
441+ if ttype == FMPZ_UNKNOWN:
442+ return NotImplemented
443+ u = acb.__new__ (acb)
444+ acb_div((< acb> u).val, tval, s.val, getprec())
445+ if ttype == FMPZ_TMP: acb_clear(tval)
446+ return u
436447
437448 def __pow__ (s , t , u ):
438- cdef acb_struct sval[1 ]
439449 cdef acb_struct tval[1 ]
440- cdef int stype, ttype
450+ cdef int ttype
441451 if u is not None :
442452 raise ValueError (" modular exponentiation of complex number" )
443- stype = acb_set_any_ref(sval, s )
444- if stype == FMPZ_UNKNOWN:
453+ ttype = acb_set_any_ref(tval, t )
454+ if ttype == FMPZ_UNKNOWN:
445455 return NotImplemented
456+ u = acb.__new__ (acb)
457+ acb_pow((< acb> u).val, s.val, tval, getprec())
458+ if ttype == FMPZ_TMP: acb_clear(tval)
459+ return u
460+
461+ def __rpow__ (s , t ):
462+ cdef acb_struct tval[1 ]
463+ cdef int ttype
446464 ttype = acb_set_any_ref(tval, t)
447465 if ttype == FMPZ_UNKNOWN:
448466 return NotImplemented
449467 u = acb.__new__ (acb)
450- acb_pow((< acb> u).val, sval, tval, getprec())
451- if stype == FMPZ_TMP: acb_clear(sval)
468+ acb_pow((< acb> u).val, tval, s.val, getprec())
452469 if ttype == FMPZ_TMP: acb_clear(tval)
453470 return u
454471
@@ -2560,4 +2577,3 @@ cdef class acb(flint_scalar):
25602577 acb_hypgeom_coulomb(NULL , (< acb> G).val, NULL , NULL ,
25612578 (< acb> l).val, (< acb> eta).val, (< acb> self ).val, getprec())
25622579 return G
2563-
0 commit comments