Algebraic Operation System (AOS)
|
04-17-2022, 12:57 AM
(This post was last modified: 04-18-2022 10:54 AM by Thomas Klemm.)
Post: #1
|
|||
|
|||
Algebraic Operation System (AOS)
Description
This program allows you to use the Algebraic Operation System (AOS) similar to how old Texas Instruments calculators work. The shunting yard algorithm is used with a data and an operator stack. Their stack size is configurable and is only limited by the amount of memory available. Functions The functions just operate on the X register in postfix notation. This is how the TI-57 and other older calculators from Texas Instruments work. For example, to calculate \( \sqrt{3^2 + 4^2} \) use: 3 x^2 + 4 x^2 = √x Alternatively we can use: ( 3 x^2 + 4 x^2 ) √x However, this requires one more keystroke. Apparently we use a mixture of infix notation for arithmetic operations and postfix notation for functions. Change Sign It behaves similarly to an ordinary function. E.g. an expression like \( - 3^4 \) has to be keyed in like: 3 y^x 4 = +/- Or alternatively: ( 3 y^x 4 ) +/- Intermediate Results The intermediate results of a calculation are viewed and may also be printed. Example \( \frac{1 \times 2 + 3 \times 4 + 5 \times 6 + 7 \times 8}{4} \) ( 1 * 2 + 3 * 4 + 5 * 6 + 7 * 8 ) / 4 = Code: ST X= 2 Implicit Data Entry The current value in the X register is used as data entry. This allows to reuse the first entry: 3 + = This results in \( 3 + 3 = 6 \). 3 * * = This results in \( 3^4 = 81 \). The Monster Formula The formula is from A case against the x<>y key: \( 1 - 2 \times 3^4 \div 5 + \sin\left(6 - \sqrt[3]{7^2} \right) \times 8! + \ln \left[ \left(-9^{2^3} \times 45 ^ \frac{6}{7} \right)^2 \right] \) Here's how it is entered with this program. 1 - 2 * 3 ^ 4 / 5 + ( 6 - 7 X^2 ^ 3 1/X ) SIN * 8 FACT + ( 9 ^ 2 ^ 3 * 45 ^ ( 6 / 7 ) ) CHS X^2 LN = 1657.008948 Intermediate Results Code: ST X= 81 Registers This is a list of the registers after the calculation: Code: 00: 5 Mark Hardman’s solution (05-10-2015 03:12 PM)Mark Hardman Wrote: TI-57 These are the key strokes for the TI-57: 1 - 2 × 3 y^x 4 ÷ 5 + ( 6 - 7 x^2 INV y^x 3 ) 2nd sin * 40320 + ( 9 y^x ( 2 y^x 3 ) × 45 ^ ( 6 ÷ 7 ) ) +/- x^2 lnx = We get the same result: 1657.0089 For this I used the TI-57 Programmable Calculator. However I had to cheat a little: since the factorial function is missing I just replaced \( 8! \) with \( 40320 \). Also since the \( y^x \) operation apparently is not right associative I used another pair of parenthesis to calculate: \( 9 ^ {2 ^ 3} = 9 ^ {(2 ^ 3)} \) Program This is the program for the HP-41C: Code: 01▸LBL "AOS" Key Assignments Of course you are free to choose differently buy I recommend the following key assignments: Code: | Label | Key | Code Registers The program needs 3 register to control the data and the operator stack: Code: | Register | Comment Synthetic Programming We could use the alpha registers M, N and O instead of register 00-02. With this the data stack could be started at register 00. For now I'm leaving that as an exercise for the dear reader. Operators The decimal part of the code is used as precedence. A negative code means left associativity. The code for the left parenthesis ( is 0. Thus we already have an implicit open parenthesis. This makes handling the right parenthesis ) and = similar. Code: | Operator | Label | Code | Precedence | Associativity Code Walkthrough Initialisation The registers and the stack is cleared with: XEQ AOS Here you can configure the start of the data and the operator stack. Be warned that there are no checks in the program. Thus the data stack could grow into the operator stack and vice versa. It's up to you to select reasonable values. Code: LBL "AOS" Enter Operator Each operator pushes a specific code onto the stack in which label, precedence and associativity is encoded. Code: LBL "+" New operator Each time we reach a new operator, we pop operators from the stack until we reach one that has lower precedence. In the case of a right associative operator, we also stop if we reach an operator of the same precedence. Code: | X | Y | Decision There's no lower precedence than -0.2, thus + and - always pop. On the other hand, ^ never pops previous operators. This leaves us with * and / which pop unless an operator on the stack has lower precedence like + or -. Stack diagram: ( x op -- x' ) Code: LBL 00 ; add new operator Push Operator The left parenthesis ( is just pushed onto the operator stack. The RTN command after ISG is used as a no-operation which is always skipped. Code: LBL "(" Right Parentheses and Equals Code: while the operator at the top of the operator stack is not a left parenthesis: Code: LBL ")" The = operator does not pop the implicit left parenthesis. But otherwise it behaves like the right parenthesis and removes any leftover operators from the operator stack. Pop Operator Stack diagram: ( a x op -- a a op x' ) Code: LBL 06 ; pop operator Implementation This is just the implementation of the operators: Code: LBL 01 ; + HP-42S The program also works with the HP-42S. However, we can assign the programs only to a custom menu. I'm using the following layout: Code: X^2 | SQRT | 10^X | LOG | E^X | LN Code: 00 { 186-Byte Prgm } References |
|||
04-17-2022, 03:17 AM
(This post was last modified: 04-17-2022 12:03 PM by Sylvain Cote.)
Post: #2
|
|||
|
|||
RE: Algebraic Operation System (AOS)
Great work Thomas, your suggested key assignment made it very easy to use.
Sylvain PS: I was too lazy to type in the program, so I used the barcode reader instead. Procedure to create a barcode from text with lifutils on macOS. Code: 1) use the "View a Printable Version" at the bottom of this page Code: comp41 aos.txt >aos.raw Source File: aos.txt Barcode File: aos.pdf |
|||
04-17-2022, 10:32 AM
Post: #3
|
|||
|
|||
RE: Algebraic Operation System (AOS)
Thank you for providing the barcode and instructions.
I wasn't aware that the lifutils are available on macOS. This begs the question: is there an emulator you can recommend for macOS? |
|||
04-17-2022, 02:12 PM
(This post was last modified: 04-17-2022 05:22 PM by Sylvain Cote.)
Post: #4
|
|||
|
|||
RE: Algebraic Operation System (AOS)
I use Genesis-41 from Laurent Spohr.
That was one of the best emulator that I have seen. Unfortunately that macOS emulator is no longer available since 2016. Windows application V41 works with Wine on Linux/macOS & CrossOver (a macOS customized version of Wine). Everything seems to works but the mcode console is way too slow even when full speed is selected. If that is your goal, you will have to use V41 under Parallels Desktop or VMware Fusion running a full version of Windows. Sylvain Genesis-41 V41 under CrossOver |
|||
04-18-2022, 06:15 AM
(This post was last modified: 04-18-2022 07:06 AM by C.Ret.)
Post: #5
|
|||
|
|||
RE: Algebraic Operation System (AOS)
(04-17-2022 12:57 AM)Thomas Klemm Wrote: TI-57 Thank you for this excellant program allowing us to use the AOS from the historic competitor on the HP-41C ! I get a lot of fun and a great time this morning by using AOS on my HP-41C and comparing with the results obtained on a newly restored TI Programmable 58C. Armed with the MASTER LIBRARY MODULE, the keystrokes sequences on Ti-58/59 are quite identical to the one for the TI-57. Except that the factorial function is available (Module program Pgm 16 , label A for entry n and label C to compute n!) and the x√y function is available with the INV y^x keystrokes. These are the key strokes for the TI-58/59 armed with the MASTER LIBRARY MODULE: 2nd Deg CLR 1 - 2 × 3 y^x 4 ÷ 5 + ( 6 - 7 x^2 INV y^x 3 ) 2nd sin * 8 2nd Pgm16 A C + ( 9 y^x ( 2 y^x 3 ) × 45 y^x 6 INV y^x 7 ) +/- x^2 lnx = We get the expected result: 1657.008948 For this I used the TI Programmable 58 C Calculator serial n°8208744. Despite the Ti-57, the infamous Ti-57 LCD allows a simpler keystrokes sequence since this model also has factorial n! and x√y functions(°): Press DRG until the RAD and GRAD annunciators are off. ON/C ON/C 1 - 2 × 3 y^x 4 ÷ 5 + ( 6 - 7 x^2 INV y^x 3 ) sin * 8 2nd n! + ( 9 y^x ( 2 y^x 3 ) × 45 y^x 6 INV y^x 7 ) +/- x^2 lnx = We get the same result as he TI 57: 1657.0089 on but on a LCD display as colorless as the HP-41. EDIT: (°) I am currently in a doubt, isn't the x√y function available on the red LED Ti-57 as the INV y^x keystrokes ? Please check for that, I have no TI-57 with LED and have an issue trying a simulator on Internet. |
|||
04-18-2022, 07:01 AM
(This post was last modified: 04-18-2022 07:15 AM by Ángel Martin.)
Post: #6
|
|||
|
|||
RE: Algebraic Operation System (AOS)
(04-17-2022 10:32 AM)Thomas Klemm Wrote: Thank you for providing the barcode and instructions. Nicely done Thomas, I've attached the RAW file to this post in case it's useful This subject seems to resurface every few years, I'm aware of two other versions of the same topic: 1. in the HP-67 Games ROM, by Jim Horn 2. In the GJM ROM, by Greg McClure Both manuals are available at Monte's site and at TOS, http://www.systemyde.com/hp41/documents.html Cheers, ÁM "To live or die by your own sword one must first learn to wield it aptly." |
|||
04-18-2022, 08:02 AM
Post: #7
|
|||
|
|||
RE: Algebraic Operation System (AOS)
(04-18-2022 06:15 AM)C.Ret Wrote: EDIT: Yes it is. I had to try several times due to the poor keyboard of my TI-57, but 8 INV y^x 3 = returns 2 |
|||
04-18-2022, 12:27 PM
(This post was last modified: 04-18-2022 12:58 PM by Thomas Klemm.)
Post: #8
|
|||
|
|||
RE: Algebraic Operation System (AOS)
(04-18-2022 06:15 AM)C.Ret Wrote: isn't the x√y function available on the red LED Ti-57 as the INV y^x keystrokes ? I totally forgot about that and have since corrected it. Thanks for the hint. And also thanks to Didier for the confirmation. (04-18-2022 07:01 AM)Ángel Martin Wrote: 1. in the HP-67 Games ROM, by Jim Horn I found the ROM on TOS, downloaded it and unzipped it: Code: wget http://*****/file/HP67_FUN.zip Then I dowloaded rom2raw, compiled it on Mac and used it to extract the listing: Code: wget https://thomasokken.com/free42/download/rom2raw.zip Here is the listing: Code: 01▸LBL "AOS" It appears that Free42 has a problem parsing this line: Code: 153 XEQ IND Z You better make sure to use the following instead: Code: 153 XEQ IND ST Z At first glimpse I noticed the following differences: The power function is left-associative. Thus we get: 9 YX 2 YX 3 = 531441 But then I noticed that this is apparently still the case with today's calculators from Texas Instruments. From Solution 12705: Differences Between Algebraic Operating System (AOS) and Equation Operating System (EOS).: Quote:The Algebraic Operating System (AOS) completes all operations according to their relative priorities, which are listed below: But for example Python does it right. The power operation ** is actually right-associative, as it should: Code: >>> dis(lambda a, b, c: a ** b ** c) Code: >>> dis(lambda a, b, c: a ** (b ** c)) The other arithmetic operations like / are left-associative: Code: >>> dis(lambda a, b, c: a / b / c) Code: >>> dis(lambda a, b, c: (a / b) / c) The NEG function is implemented. The program is about twice as long and big. Flag 22 is used to detect numeric input. I still haven't figured out why this is necessary. In my implementation, each operation always adds the current value of register X to the data stack. |
|||
04-18-2022, 04:08 PM
Post: #9
|
|||
|
|||
RE: Algebraic Operation System (AOS)
(04-18-2022 12:27 PM)Thomas Klemm Wrote: The power function is left-associative. Although associative order is wrong (*), this made parsing expression easier, scanning from left to right. Easy parsing translate to intepreted code run faster, which may be needed in the old days. (I just checked, HP71B power is also left-associative) To have power right-associative, we may need to parse expression in reverse order. (it can be done in forward order too, but I cannot make parsing expression as fast) see https://www.hpmuseum.org/forum/thread-12...#pid130808 (*) wrong is probably the wrong word, perhaps not right |
|||
04-18-2022, 05:24 PM
Post: #10
|
|||
|
|||
RE: Algebraic Operation System (AOS)
At the risk of beating a dead horse, here's the infamous Mach number:
\[ \sqrt{5 \left( \left( \left( \left( \left(1 + 0.2 \left(\frac{350}{661.5} \right)^{2} \right)^{3.5} - 1 \right) \times \left(1-6.875 \times 10^{-6} \times 25500 \right)^{-5.2656} \right)+1 \right)^{0.286}-1 \right)} \] ( 5 * ( ( ( ( ( 1 + .2 * ( 350 / 661.5 ) X^2 ) ^ 3.5 - 1 ) * ( 1 - 6.875E-6 * 25500 ) ^ -5.2656 ) + 1 ) ^ .286 - 1 ) ) SQRT 0.835724536 |
|||
04-19-2022, 12:25 AM
Post: #11
|
|||
|
|||
RE: Algebraic Operation System (AOS)
And the mach number problem is one of the examples I put into the HP-67 Games rom put together a couple of years ago.
Here's the manual (PDF): HP-67 Fun rom |
|||
04-19-2022, 12:53 AM
Post: #12
|
|||
|
|||
RE: Algebraic Operation System (AOS)
Jim Horn, who posts here fairly often, is the original author of the AOS program for the HP-67 that is now in the HP-67 fun rom.
|
|||
04-19-2022, 01:27 PM
(This post was last modified: 04-19-2022 01:47 PM by Ángel Martin.)
Post: #13
|
|||
|
|||
RE: Algebraic Operation System (AOS)
(04-18-2022 05:24 PM)Thomas Klemm Wrote: At the risk of beating a dead horse, here's the infamous Mach number: This is a good test case for the new Double-Length Stack ROM, just finished and ready to be released.. stay tuned To whet your appetite here's the programmatic version of the sequence of steps, entering the formula strictly from left to right: Code:
Most of those ENTER^^ steps are not required in manual mode, by virtue of the I/O_SVC interrupt - which isn't "active" in a running program. Cheers, ÁM "To live or die by your own sword one must first learn to wield it aptly." |
|||
04-19-2022, 03:00 PM
Post: #14
|
|||
|
|||
RE: Algebraic Operation System (AOS)
(04-18-2022 12:27 PM)Thomas Klemm Wrote: I found the ROM on TOS, downloaded it and unzipped it: that's the standard notation used on the HP-41, and also the expected syntax by hp41uc.exe Did you change your original code ? "To live or die by your own sword one must first learn to wield it aptly." |
|||
04-19-2022, 03:19 PM
(This post was last modified: 04-19-2022 03:20 PM by Ángel Martin.)
Post: #15
|
|||
|
|||
RE: Algebraic Operation System (AOS)
(04-19-2022 12:25 AM)Gene Wrote: And the mach number problem is one of the examples I put into the HP-67 Games rom put together a couple of years ago. And here's the link to Greg McClure's http://www*hp41*org/LibView.cfm?Command=...leID=30533 replace the * with dot characters "To live or die by your own sword one must first learn to wield it aptly." |
|||
04-19-2022, 03:40 PM
(This post was last modified: 04-19-2022 04:27 PM by Thomas Klemm.)
Post: #16
|
|||
|
|||
RE: Algebraic Operation System (AOS)
(04-19-2022 03:00 PM)Ángel Martin Wrote: Did you change your original code ? Apparently I didn't make that clear: in general you can just copy and paste a listing for the HP-41C into Free42 and it will be parsed. But for some reason XEQ IND Z is ignored. For the sake of simplicity, here is Jim's program from the HP67_FUN ROM for the HP-42S: Code: 00 { 363-Byte Prgm } |
|||
04-20-2022, 05:55 AM
Post: #17
|
|||
|
|||
RE: Algebraic Operation System (AOS)
(04-19-2022 03:40 PM)Thomas Klemm Wrote: Apparently I didn't make that clear: in general you can just copy and paste a listing for the HP-41C into Free42 and it will be parsed. Thanks for clarifying Thomas. Your version is indeed much shorter, and doesn't lack functionality, I'm not wrong. Best, ÁM "To live or die by your own sword one must first learn to wield it aptly." |
|||
04-20-2022, 07:07 AM
Post: #18
|
|||
|
|||
RE: Algebraic Operation System (AOS)
(04-18-2022 05:24 PM)Thomas Klemm Wrote: At the risk of beating a dead horse, here's the infamous Mach number: No issue calculating the Mach number in manual mode onto a DM41X or HP41C. |
|||
04-20-2022, 12:20 PM
Post: #19
|
|||
|
|||
RE: Algebraic Operation System (AOS)
(04-20-2022 05:55 AM)Ángel Martin Wrote:(04-19-2022 03:40 PM)Thomas Klemm Wrote: Apparently I didn't make that clear: in general you can just copy and paste a listing for the HP-41C into Free42 and it will be parsed. i just cobbled up together the three AOS versions into a ROM image so you can play around a little. Bulk Key-assignments for AOS57 (Thomas') and AOS67 (Jim's) are also included (not needed for Greg's AOSXM). As an extra bonus I added Valentin Albillo's "STACK-N" program, which is kind of related to the subject although coming from the opposite side, if you know what I mean. Enjoy, ÁM "To live or die by your own sword one must first learn to wield it aptly." |
|||
04-24-2022, 11:18 PM
Post: #20
|
|||
|
|||
RE: Algebraic Operation System (AOS)
(04-20-2022 07:07 AM)Chr Yoko Wrote: No issue calculating the Mach number in manual mode onto a DM41X or HP41C. Mach Formula I used this Python to RPN converter to translate the following function: Code: def mach(): But alas it gave me an error: Potential RPN stack overflow detected - expression too complex for 4 level stack - simplify! [5, 1, 0.2, 350, 661.5], line: 4 return SQRT( 5 * ( ( ( ( ( 1 + .2 * ( 350 / 661.5 ) ** 2 ) ** 3.5 - 1 ) * ( 1 - 6.875E-6 * 25500 ) ** -5.2656 ) + 1 ) ** .286 - 1 ) ) The fix was easy. I just had to move the multiplication by 5 to the end: Code: def mach(): This is the generated program for the HP-42S: Code: 00 { 75-Byte Prgm } It leads to: 0.835724535175 Monster Formula Again the naïve approach fails with: Potential RPN stack overflow detected - expression too complex for 4 level stack - simplify! ['_result_', 6, 7, 2, 3], line: 4 return 1 - 2 * 3 ** 4 / 5 + SIN( 6 - 7 ** (2 / 3 ) ) * FACT(8) + LN( ( - 9 ** 2 ** 3 * 45 ** ( 6 / 7 ) ) ** 2 ) We have to rearrange the terms a bit: Code: def monster(): This generated the following program for the HP-42S: Code: 00 { 58-Byte Prgm } It leads to: 1657.00894809 In both cases, the expression had to be slightly modified due to the 4-level stack constraint. Most of us probably do this intuitively, or rather work from the inside out. So stack overflow is not really a problem. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 4 Guest(s)