(41) Exponentiation & Residue Reduction
|
04-26-2022, 03:17 AM
(This post was last modified: 04-26-2022 06:10 AM by Thomas Klemm.)
Post: #4
|
|||
|
|||
RE: (41) Exponentiation & Residue Reduction
Let us start with the following Python program:
Code: def pow(b, x, m): With the help of the Python to RPN - source code converter it is translated to: Code: LBL "Z^Y%X" // Label. Identify programs and routines for execution and branching. Parameter: local or global label. Let's clear it up a bit:
Instead of: Code: X≠0? // while true? Code: X=0? // while not? With these changes we are already down at 51 bytes and could call it a day: Code: 00 { 51-Byte Prgm } But can we do better? You may have noticed that line 13 could be removed since x is still present from line 10. Furthermore, division by 2 and modulo 2 of x can be combined. Code: 00 { 47-Byte Prgm } So far we haven't bothered with registers or keeping results on the stack. But if we leave x on the stack, we save 2 STO and 1 RCL instructions at the cost of 2 RDN instructions. With this we not only save a register, but also another byte: Code: 00 { 46-Byte Prgm } Feel free to replace the 3 remaining registers with the synthetic registers M, N and O. |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
(41) Exponentiation & Residue Reduction - SlideRule - 04-06-2020, 01:31 PM
RE: (41) Exponentiation & Residue Reduction - Werner - 05-08-2020, 01:58 PM
RE: (41) Exponentiation & Residue Reduction - Albert Chan - 05-11-2020, 02:55 PM
RE: (41) Exponentiation & Residue Reduction - Thomas Klemm - 04-26-2022 03:17 AM
Errata: (41) Exponentiation & Residue Reduction - Thomas Klemm - 04-26-2022, 10:59 AM
Errata: (41) Exponentiation & Residue Reduction - Thomas Klemm - 04-26-2022, 04:05 PM
|
User(s) browsing this thread: 3 Guest(s)