[PATCH] fix powmod(0,0,3) in INT and SINT

2 views
Skip to first unread message

Qian Yun

unread,
May 30, 2026, 2:13:08 AM (3 days ago) May 30
to fricas-devel
This will make "0^0 mod 3" return 1 instead of 0, making it
consistent with the rest of fricas.

This will make 0^0 return 1 for ZMOD.

This will not affect the other user of powmod in
"rabinProvesComposite".

- Qian


diff --git a/src/algebra/integer.spad b/src/algebra/integer.spad
index 91bc0c46..a93d2f57 100644
--- a/src/algebra/integer.spad
+++ b/src/algebra/integer.spad
@@ -186,8 +186,8 @@
-- speeds up functions like 'primes'
powmod(x, n : %, p) ==
if negative? x then x := positiveRemainder(x, p)
- zero? x => 0
zero? n => 1
+ zero? x => 0
y : % := 1
z := x
repeat
diff --git a/src/algebra/si.spad b/src/algebra/si.spad
index 736abf2f..ac28e709 100644
--- a/src/algebra/si.spad
+++ b/src/algebra/si.spad
@@ -129,8 +129,8 @@

powmod(x, n, p) ==
if negative? x then x := positiveRemainder(x, p)
- zero? x => 0
zero? n => 1
+ zero? x => 0
y : % := 1
z := x
repeat

Waldek Hebisch

unread,
May 30, 2026, 5:06:40 AM (2 days ago) May 30
to fricas...@googlegroups.com
On Sat, May 30, 2026 at 02:13:03PM +0800, Qian Yun wrote:
> This will make "0^0 mod 3" return 1 instead of 0, making it
> consistent with the rest of fricas.
>
> This will make 0^0 return 1 for ZMOD.
>
> This will not affect the other user of powmod in
> "rabinProvesComposite".

Thanks, please commit.
> --
> You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/fricas-devel/6cb853c5-90ff-41cc-8cd6-da3834497c22%40gmail.com.

--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages