Post Reply 
Strange results for MOD in CAS
02-25-2024, 08:15 AM
Post: #1
Strange results for MOD in CAS
In CAS view:
(-27) MOD (-5) --> -7

Huh???

Although -7 is in fact congruent to -27 (mod -5), wouldn't an output of -2 (as returned in Home view) be reasonably expected as the result?

Disclaimer: The above output is produced by several recent firmware versions, but might not be produced by all versions.

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
02-25-2024, 02:30 PM
Post: #2
RE: Strange results for MOD in CAS
Perhaps you mean irem(-27, -5)?

Yes. this bug is added to latest HP emulator.

2.1.14181 (2018 10 6) Cas> irem(-27, -5)      → 3
2.1.14730 (2023 4 13) Cas> irem(-27, -5)      → -7 ???

The bug was added to latest XCas too.

XCas 1-5-0> irem(-27, -5)      → 3
XCas 1-9-0> irem(-27, -5)      → -7 ???
Find all posts by this user
Quote this message in a reply
02-27-2024, 12:22 PM
Post: #3
RE: Strange results for MOD in CAS
Indeed, I did not realize that b could be negative in a MOD b.
Find all posts by this user
Quote this message in a reply
03-03-2024, 08:54 AM
Post: #4
RE: Strange results for MOD in CAS
Does the "mod" (written in lowercase) used in CAS have different functionality depending on some settings? I have two sessions of the Virtual Calculator. In the first one, when I enter 27 mod 5 in CAS, it returns the result "2", with the original command automatically changed to "irem(27,5)" at the left side. However, in the second session, entering the same command in CAS gives the result "2 %% 5", and the original command changes to "%%(27,5)". I don't see any differences in the CAS settings, but the same command works differently.
   
What could be the reason for this?

Executing this on the HOME side changes "mod" to "MOD" and always returns the result 2 there (as expected).
Find all posts by this user
Quote this message in a reply
03-03-2024, 11:10 AM
Post: #5
RE: Strange results for MOD in CAS
Hi, komame

That explained it! There are actually 2 bugs (1st based on your session output)

1. Cas (a mod b) sometimes switch to irem(a,b)
2. irem(a,b) return negative numbers.
Find all posts by this user
Quote this message in a reply
03-03-2024, 07:32 PM
Post: #6
RE: Strange results for MOD in CAS
MOD is not a synonym of mod in CAS.

If xcas_mode()==0, mod will build an element of Z/nZ, like 27 mod 5 -> 2 %% 5.
If xcas_mode()>0, mod will call irem and return an element of Z; 27 mod 5 -> 2
The difference will become clear if you make further operations on the result, e.g. multiply by 3.
It's unclear for me how xcas_mode can be modified on the Prime...

MOD in CAS will call _MODULO in rpn.cc, it's not the same code as irem, I don't remember the difference, probably _MODULO behaves more like MOD in HOME.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)