HP Forums
HP-50g Modular Arithmetic - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: General Forum (/forum-4.html)
+--- Thread: HP-50g Modular Arithmetic (/thread-12370.html)



HP-50g Modular Arithmetic - Visty - 02-06-2019 07:15 PM

Could someone help me understand how the Modulo functions work on the HP-50g


RE: HP-50g Modular Arithmetic - pier4r - 02-06-2019 09:26 PM

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.


RE: HP-50g Modular Arithmetic - Gerald H - 02-07-2019 05:21 AM

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


RE: HP-50g Modular Arithmetic - Thomas Klemm - 02-07-2019 08:22 AM

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


RE: HP-50g Modular Arithmetic - Albert Chan - 02-07-2019 01:20 PM

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.


RE: HP-50g Modular Arithmetic - John Keith - 02-07-2019 02:42 PM

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.