Post Reply 
HP-50g Modular Arithmetic
02-06-2019, 07:15 PM
Post: #1
HP-50g Modular Arithmetic
Could someone help me understand how the Modulo functions work on the HP-50g
Find all posts by this user
Quote this message in a reply
02-06-2019, 09:26 PM
Post: #2
RE: HP-50g Modular Arithmetic
Any concrete use case?

In general see the 50g advanced user reference pdf . Page 3-150

If you put x on level2 and y on level1 and then you use MOD you get: x mod y.

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
02-07-2019, 05:21 AM (This post was last modified: 02-07-2019 05:22 AM by Gerald H.)
Post: #3
RE: HP-50g Modular Arithmetic
pier4r's reference gives this information:

Code:
Modulo Function: Returns a remainder defined by: x mod y = x – y floor (x/y)
Mod (x, y) is periodic in x with period y. Mod (x, y) lies in the interval [0, y) for y > 0 and in (y, 0]
for y < 0.
Algebraic syntax: argument 1 MOD argument 2

Just in case you don't have the Advanced manual.

AURM is available here:

https://www.hpcalc.org/details/7141
Find all posts by this user
Quote this message in a reply
02-07-2019, 08:22 AM
Post: #4
RE: HP-50g Modular Arithmetic
Arithmetic Modulo commands

ADDTMOD ........................... 3-9
DIVMOD ........................... 3-63
DIV2MOD .......................... 3-62
EXPANDMOD ........................ 3-80
FACTORMOD ........................ 3-83
GCDMOD ........................... 3-96
INVMOD .......................... 3-120
MOD ............................. 3-150
MODSTO .......................... 3-150
MULTMOD ......................... 3-153
POWMOD .......................... 3-175
SUBTMOD ......................... 3-243

Maybe the question is more about these commands?
Best would be to come up with an example that you need explained.

Cheers
Thomas
Find all posts by this user
Quote this message in a reply
02-07-2019, 01:20 PM (This post was last modified: 02-07-2019 01:24 PM by Albert Chan.)
Post: #5
RE: HP-50g Modular Arithmetic
Quote:Modulo Function: Returns a remainder defined by: x mod y = x – y floor (x/y)

Although it is defined this way, it cannot be calculated same way.

My guess is there is an algorithm to reduce x a bit at a time, like this ?

123e45 mod 12345 ≡ 123e9 * 1e36 ≡ 12285e7 * 1e29 ≡ 4035e8 * 1e21 ≡ 8535e8 * 1e13 ≡ 6810e8 * 1e5 ≡ 270e5 ≡ 1485

Or, reduce exponents, like this ?

123e45 mod 12345 ≡ 1e11^4 * 1230 ≡ 6475^4 * 1230 ≡ 2005^2 * 1230 ≡ 7900 * 1230 ≡ 1485

Reducing exponents way look faster, but may get into overflow issue.
Find all posts by this user
Quote this message in a reply
02-07-2019, 02:42 PM (This post was last modified: 02-07-2019 02:43 PM by John Keith.)
Post: #6
RE: HP-50g Modular Arithmetic
The 50g's POWMOD command uses the CAS variable MODULO for the modulus. Joe Horn posted a program for another calculator (the Prime, I think) that accepts a user-input modulus but I can't find it at the moment. Here is my 50g version:

Code:

\<< PUSH CASDIR MODULO \-> M
  \<< MODSTO POWMOD
    IF DUP 0 <
    THEN MODULO +
    END M MODSTO POP
  \>>
\>>

Input is x, y, m to return (x^y) mod m.
Find all posts by this user
Quote this message in a reply
Post Reply 




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