HP-50g Modular Arithmetic
02-06-2019, 07:15 PM
Post: #1
 Visty Junior Member Posts: 6 Joined: Feb 2019
HP-50g Modular Arithmetic
Could someone help me understand how the Modulo functions work on the HP-50g
02-06-2019, 09:26 PM
Post: #2
 pier4r Senior Member Posts: 1,989 Joined: Nov 2014
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 :)
02-07-2019, 05:21 AM (This post was last modified: 02-07-2019 05:22 AM by Gerald H.)
Post: #3
 Gerald H Senior Member Posts: 1,409 Joined: May 2014
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
02-07-2019, 08:22 AM
Post: #4
 Thomas Klemm Senior Member Posts: 1,448 Joined: Dec 2013
RE: HP-50g Modular Arithmetic
Arithmetic Modulo commands

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
02-07-2019, 01:20 PM (This post was last modified: 02-07-2019 01:24 PM by Albert Chan.)
Post: #5
 Albert Chan Senior Member Posts: 634 Joined: Jul 2018
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.
02-07-2019, 02:42 PM (This post was last modified: 02-07-2019 02:43 PM by John Keith.)
Post: #6
 John Keith Senior Member Posts: 416 Joined: Dec 2013
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.
 « Next Oldest | Next Newest »

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