Post Reply 
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
ST X=                 12
ST X=                 14
ST X=                 30
ST X=                 44
ST X=                 56
ST X=                100
ST X=                 25

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
ST X=                162
ST X=               32.4
ST X=              -31.4
ST X=      3.65930571002
ST X=      2.34069428998
ST X=      1646.72764773
ST X=      1615.32764773
ST X=                  8
ST X=           43046721
ST X=   8.57142857143ᴇ-1
ST X=      26.1239772883
ST X=      1124551561.74
ST X=      1657.00894809

Registers

This is a list of the registers after the calculation:
Code:
00:                 5
01:                10
02:              -4.1
03:                 0
04:                 0
05:                 0
06:     1615.32764773
07:          43046721
08:                45
09:                 6
10:                 0
11:              -1.2
12:                 0
13:              -3.1
14:               5.1
15:                 0
16:              -4.1
17:                 0
18:                 0
19:                 0

Mark Hardman’s solution

(05-10-2015 03:12 PM)Mark Hardman Wrote:  
Code:
              x          y          z          t
1 [Enter]     1          -          -          -
3 [Enter]     3          1          -          -
4             4          3          1          -
y^x          81          1          -          -
2             2         81          1          -
x           162          1          -          -
5             5        162          1          -
/            32.4        1          -          -
-           -31.4        -          -          -
6 [Enter]     6        -31.4        -          -
7             7          6        -31.4        -
x^2          49          6        -31.4        -
3             3         49          6        -31.4
1/x           0.3333    49          6        -31.4
y^x           3.6593     6        -31.4      -31.4
-             2.3407   -31.4      -31.4      -31.4
sin           0.0408   -31.4      -31.4      -31.4
8             8          0.0408   -31.4      -31.4
x!        40320          0.0408   -31.4      -31.4
x          1646.7276   -31.4      -31.4      -31.4
+          1615.3276   -31.4      -31.4      -31.4
45 [Enter]   45       1615.3276   -31.4      -31.4
6  [Enter]    6         45       1615.3276   -31.4
7             7          6         45       1615.3276
/             0.8571    45       1615.3276  1615.3276
y^x          26.1240  1615.3276  1615.3276  1615.3276
2 [Enter]     2         26.1240  1615.3276  1615.3276
3             3          2         26.1240  1615.3276
y^x           8         26.1240  1615.3276  1615.3276
9 [Chs]      -9          8         26.1240  1615.3276
x<>y          8         -9         26.1240  1615.3276
y^x        4.3047e07    26.1240  1615.3276  1615.3276
x          1.1246e09  1615.3276  1615.3276  1615.3276
x^2        1.2646e18  1615.3276  1615.3276  1615.3276
ln        41.6813     1615.3276  1615.3276  1615.3276
+       1657.0089     1615.3276  1615.3276  1615.3276

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"
02 CLRG
03 3
04 STO 00
05 10
06 STO 01
07 CLST
08 RTN
09▸LBL "+"
10 -1.2
11 GTO 00
12▸LBL "-"
13 -2.2
14 GTO 00
15▸LBL "*"
16 -3.1
17 GTO 00
18▸LBL "/"
19 -4.1
20 GTO 00
21▸LBL "^"
22 5.1
23▸LBL 00
24 STO 02
25 FRC
26 X>0?
27 GTO 11
28▸LBL 09
29 RCL IND 01
30 X=0?
31 GTO 10
32 FRC
33 X<Y?
34 GTO 10
35 X<> Z
36 LASTX
37 XEQ 06
38 R^
39 GTO 09
40▸LBL 10
41 RDN
42▸LBL 11
43 RDN
44 RCL 02
45 XEQ 07
46 ISG 00
47 RTN
48 STO IND 00
49 RTN
50▸LBL "<"
51 0
52▸LBL 07
53 ISG 01
54 RTN
55 STO IND 01
56 RDN
57 RTN
58▸LBL ">"
59 XEQ 08
60 DSE 01
61 RTN
62▸LBL "="
63▸LBL 08
64 RCL IND 01
65 X=0?
66 GTO 13
67 XEQ 06
68 GTO 08
69▸LBL 13
70 RDN
71 RTN
72▸LBL 06
73 DSE 01
74 X<>Y
75 RCL IND 00
76 DSE 00
77 X<>Y
78 XEQ IND Z
79 VIEW X
80 RTN
81▸LBL 01
82 +
83 RTN
84▸LBL 02
85 -
86 RTN
87▸LBL 03
88 *
89 RTN
90▸LBL 04
91 /
92 RTN
93▸LBL 05
94 Y^X
95 END

Key Assignments

Of course you are free to choose differently buy I recommend the following key assignments:
Code:
| Label | Key    | Code
|-------|--------|-----
| +     | +      |  61
| -     | -      |  51
| *     | *      |  71
| /     | /      |  81
| ↑     | Y↑X    | -12
| =     | ENTER↑ |  41
| <     | X<>Y   |  21
| >     | R↓     |  22
| AOS   | CLx/A  | -44

Registers

The program needs 3 register to control the data and the operator stack:
Code:
| Register | Comment
|----------|----------------------
| 00       | top of data stack
| 01       | top of operator stack
| 02       | current operator

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
|----------|-------|-------|------------|--------------
| (        |       |   0   |            |
| +        | 01    |  -1.2 | -0.2       | left
| -        | 02    |  -2.2 | -0.2       | left
| *        | 03    |  -3.1 | -0.1       | left
| /        | 04    |  -4.1 | -0.1       | left
| ^        | 05    |   5.1 |  0.1       | right

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"
CLRG
3                ; top of data stack
STO 00
10               ; top of operator stack
STO 01
CLST
RTN

Enter Operator

Each operator pushes a specific code onto the stack in which label, precedence and associativity is encoded.

Code:
LBL "+"
-1.2
GTO 00           ; new operator

LBL "-"
-2.2
GTO 00           ; new operator

LBL "*"
-3.1
GTO 00           ; new operator

LBL "/"
-4.1
GTO 00           ; new operator

LBL "^"
5.1

LBL 00           ; new operator

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
|------|------|-----------
| -0.2 | -0.2 | pop
| -0.1 | -0.2 | pop
|  0.1 | -0.2 | pop
| -0.2 | -0.1 | no more
| -0.1 | -0.1 | pop
|  0.1 | -0.1 | pop
| -0.2 |  0.1 | no more
| -0.1 |  0.1 | no more
|  0.1 |  0.1 | no more

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
STO 02           ; save new operator
FRC              ; precedence of new operator
X>0?             ; it is ^
GTO 11           ; no more pop
LBL 09           ; while higher precedence
RCL IND 01       ; top of stack operator
X=0?             ; is left parenthesis ?
GTO 10           ; no more pop
FRC              ; precedence of top of stack operator
X<Y?             ; has lower precedence ?
GTO 10           ; no more pop
X<> Z            ; x
LASTX            ; top of stack operator
XEQ 06           ; pop operator
R^               ; precedence of new operator
GTO 09           ; while higher precedence
LBL 10           ; no more pop
RDN              ; drop precedence of top of stack operator
LBL 11           ; no more pop
RDN              ; drop precedence of new operator
RCL 02           ; current operator
XEQ 07           ; push operator
ISG 00           ; push data
RTN              ; no op
STO IND 00       ; store data
RTN


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 "("
0

LBL 07           ; push operator
ISG 01           ; increment top operator
RTN              ; no op
STO IND 01       ; store operator
RDN              ; drop operator
RTN

Right Parentheses and Equals

Code:
while the operator at the top of the operator stack is not a left parenthesis:
    pop the operator from the operator stack into the output queue
pop the left parenthesis from the operator stack and discard it

Code:
LBL ")"
XEQ 08
DSE 01          ; pop left parenthesis
RTN

LBL "="
LBL 08          ; while not (
RCL IND 01      ; top of operator stack
X=0?            ; is left parenthesis ?
GTO 13          ; pop (
XEQ 06          ; pop operator
GTO 08          ; while not (
LBL 13          ; pop (
RDN             ; drop operator
RTN

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
DSE 01           ; decrement top of operator stack
X<>Y             ; ( a op x )
RCL IND 00       ; y: top of data stack
DSE 00           ; pop data
X<>Y             ; ( a op y x )
XEQ IND Z        ; execute operator
VIEW ST X        ; view result
RTN

Implementation

This is just the implementation of the operators:
Code:
LBL 01           ; +
+
RTN

LBL 02           ; -
-
RTN

LBL 03           ; *
*
RTN

LBL 04           ; /
/
RTN

LBL 05           ; ^
Y^X
END

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
------+------+------+------+------+------
   +  |   -  |   *  |   /  |   ↑  |   =
------+------+------+------+------+------
   (  |   )  |  1/X |  N!  |      |  AOS
But compared to the HP-41C, the user experience is modest.

Code:
00 { 186-Byte Prgm }
01▸LBL "AOS"
02 CLRG
03 3
04 STO 00
05 10
06 STO 01
07 CLST
08 RTN
09▸LBL "+"
10 -1.2
11 GTO 00
12▸LBL "-"
13 -2.2
14 GTO 00
15▸LBL "*"
16 -3.1
17 GTO 00
18▸LBL "/"
19 -4.1
20 GTO 00
21▸LBL "↑"
22 5.1
23▸LBL 00
24 STO 02
25 FP
26 X>0?
27 GTO 11
28▸LBL 09
29 RCL IND 01
30 X=0?
31 GTO 10
32 FP
33 X<Y?
34 GTO 10
35 X<> ST Z
36 LASTX
37 XEQ 06
38 R↑
39 GTO 09
40▸LBL 10
41 R↓
42▸LBL 11
43 R↓
44 RCL 02
45 XEQ 07
46 ISG 00
47 RTN
48 STO IND 00
49 RTN
50▸LBL "("
51 0
52▸LBL 07
53 ISG 01
54 RTN
55 STO IND 01
56 R↓
57 RTN
58▸LBL ")"
59 XEQ 08
60 DSE 01
61 RTN
62▸LBL "="
63▸LBL 08
64 RCL IND 01
65 X=0?
66 GTO 13
67 XEQ 06
68 GTO 08
69▸LBL 13
70 R↓
71 RTN
72▸LBL 06
73 DSE 01
74 X<>Y
75 RCL IND 00
76 DSE 00
77 X<>Y
78 XEQ IND ST Z
79 VIEW ST X
80 RTN
81▸LBL 01
82 +
83 RTN
84▸LBL 02
85 -
86 RTN
87▸LBL 03
88 ×
89 RTN
90▸LBL 04
91 ÷
92 RTN
93▸LBL 05
94 Y↑X
95 END

References
Find all posts by this user
Quote this message in a reply
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
2) copy paste the program into a text file
3) removed the first three columns of the text file (line numbers)
4) save it to file: aos.txt
Then from the command line:
Code:
comp41     aos.txt >aos.raw
prog41bar <aos.raw >aos.bc
barps AOS <aos.bc  >aos.ps
ps2pdf     aos.ps   aos.pdf
Then I used macOS preview to print the aos.pdf file and the bar code reader to load it into my HP-41. Cool

Source File: aos.txt
Barcode File: aos.pdf
Find all posts by this user
Quote this message in a reply
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?
Find all posts by this user
Quote this message in a reply
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
[Image: genesis41.jpg]

V41 under CrossOver
[Image: v41.jpg]
Find all posts by this user
Quote this message in a reply
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

These are the key strokes for the TI-57:

1 - 2 × 3 y^x 4 ÷ 5 + ( 6 - 7 x^2 ^ 3 1/x ) 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.

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. Smile



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.
Find all posts by this user
Quote this message in a reply
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.
I wasn't aware that the lifutils are available on macOS.
This begs the question: is there an emulator you can recommend for macOS?

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


Attached File(s)
.zip  AOS.zip (Size: 630 bytes / Downloads: 6)
Find all posts by this user
Quote this message in a reply
04-18-2022, 08:02 AM
Post: #7
RE: Algebraic Operation System (AOS)
(04-18-2022 06:15 AM)C.Ret Wrote:  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.

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
Find all posts by this user
Quote this message in a reply
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

unzip HP67_FUN.zip
Archive:  HP67_FUN.zip
  inflating: HP67_FUN_20161213.ROM
  inflating: HP67_FUN.mod

Then I dowloaded rom2raw, compiled it on Mac and used it to extract the listing:
Code:
wget https://thomasokken.com/free42/download/rom2raw.zip

unzip rom2raw.zip
Archive:  rom2raw.zip
  inflating: rom2raw.c
  inflating: rom2raw.exe

cc -o rom2raw rom2raw.c

./rom2raw -l HP67_FUN_20161213.ROM > HP67_FUN.txt

Here is the listing:
Code:
01▸LBL "AOS"
02 SF 27
03▸LBL a
04 CF 01
05 CF 02
06 CF 22
07 12
08 STO 23
09 -1
10 STO 24
11 CLX
12 RTN
13▸LBL "+"
14▸LBL A
15 61
16 GTO 00
17▸LBL "-"
18▸LBL B
19 51
20 GTO 00
21▸LBL "*"
22▸LBL C
23 42
24 GTO 00
25▸LBL "/"
26▸LBL D
27 32
28 GTO 00
29▸LBL "YX"
30▸LBL b
31 14
32 GTO 00
33▸LBL "NEG"
34▸LBL c
35 23
36 GTO 00
37▸LBL "<"
38▸LBL d
39 5
40▸LBL 00
41 10
42 /
43 STO 22
44 INT
45 X≠0?
46 GTO 00
47 FS? 01
48 XEQ 03
49▸LBL 00
50 RDN
51 FS?C 22
52 XEQ 02
53 RCL 22
54 INT
55 X=0?
56 GTO 00
57▸LBL 07
58 RCL 24
59 X<0?
60 GTO 00
61 RCL IND 24
62 FRC
63 RCL 22
64 FRC
65 X>Y?
66 GTO 00
67 RCL IND 24
68 INT
69 X=0?
70 GTO 00
71 XEQ 01
72 GTO 07
73▸LBL 00
74 ISG 24
75 ENTER↑
76 RCL 24
77 13
78 X<=Y?
79 ASIN
80 RCL 22
81 STO IND 24
82 RCL IND 23
83 CF 01
84 GTO 99
85▸LBL ">"
86▸LBL e
87 1
88 STO 22
89 X<>Y
90 FS?C 22
91 XEQ 02
92 RCL 24
93 X<0?
94 SQRT
95 RCL IND 24
96 INT
97 X=0?
98 GTO 08
99 XEQ 01
100 GTO e
101▸LBL 08
102 DSE 24
103 ENTER↑
104 RCL IND 23
105 SF 01
106 GTO 99
107▸LBL E
108▸LBL "="
109 1
110 STO 22
111 X<>Y
112 FS?C 22
113 XEQ 02
114 RCL 24
115 X<0?
116 GTO 00
117 RCL IND 24
118 XEQ 01
119 GTO E
120▸LBL 00
121 RCL IND 23
122 XEQ a
123 RDN
124 RDN
125 SF 22
126 GTO 99
127▸LBL 02
128 ISG 23
129 ENTER↑
130 21
131 RCL 23
132 -
133 X<0?
134 SQRT
135 RDN
136 STO IND 23
137 RCL 22
138 INT
139 X≠0?
140 RTN
141▸LBL 03
142 ISG 24
143 ENTER↑
144 4.2
145 STO IND 24
146 RDN
147 RTN
148▸LBL 01
149 RCL IND 23
150 DSE 23
151 RCL IND 23
152 X<>Y
153 XEQ IND Z
154 FS?C 02
155 ISG 23
156 ENTER↑
157 RCL 23
158 13
159 -
160 X<0?
161 SQRT
162 X<>Y
163 STO IND 23
164 DSE 24
165 RTN
166 RTN
167▸LBL 01
168 Y↑X
169 RTN
170▸LBL 02
171 CHS
172▸LBL 00
173 SF 02
174 RTN
175▸LBL 03
176 /
177 RTN
178▸LBL 04
179 *
180 RTN
181▸LBL 05
182 CHS
183▸LBL 06
184 +
185▸LBL 99
186 RTN
187 SF 22
188 END

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:

1) Trigonometric and hyperbolic functions, square roots, cube roots, factorials, reciprocals (inverse), angle conversions, combinations, permutations, percents, logarithms, sign changes (+/-), metric conversions, logical "not".
2) Universal powers, exponents and roots.
3) Multiplication and division.
4) Addition and subtraction.
5) Logical "and".
6) Other logical functions, such as "or", "xor" and "xnor".
7) Close parenthesis.
8) Equals.

Operations of priority 1 are immediate functions which means they are performed as soon as the operation keys are pressed.

Operations in priorities 2, 3, and 4 are completed by any operation with the same priority or with a lower priority.

The [=] key completes all operations.

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)
  1           0 LOAD_FAST                0 (a)
              2 LOAD_FAST                1 (b)
              4 LOAD_FAST                2 (c)
              6 BINARY_POWER
              8 BINARY_POWER
             10 RETURN_VALUE

Code:
>>> dis(lambda a, b, c: a ** (b ** c))
  1           0 LOAD_FAST                0 (a)
              2 LOAD_FAST                1 (b)
              4 LOAD_FAST                2 (c)
              6 BINARY_POWER
              8 BINARY_POWER
             10 RETURN_VALUE

The other arithmetic operations like / are left-associative:
Code:
>>> dis(lambda a, b, c: a / b / c)
  1           0 LOAD_FAST                0 (a)
              2 LOAD_FAST                1 (b)
              4 BINARY_TRUE_DIVIDE
              6 LOAD_FAST                2 (c)
              8 BINARY_TRUE_DIVIDE
             10 RETURN_VALUE

Code:
>>> dis(lambda a, b, c: (a / b) / c)
  1           0 LOAD_FAST                0 (a)
              2 LOAD_FAST                1 (b)
              4 BINARY_TRUE_DIVIDE
              6 LOAD_FAST                2 (c)
              8 BINARY_TRUE_DIVIDE
             10 RETURN_VALUE

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.
Find all posts by this user
Quote this message in a reply
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.
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.

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 Big Grin
Find all posts by this user
Quote this message in a reply
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
Find all posts by this user
Quote this message in a reply
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
Find all posts by this user
Quote this message in a reply
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.
Find all posts by this user
Quote this message in a reply
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:

\[
\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

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:

01  LBL "MACH"
02  5
03  ENTER^^
04  1
05  ENTER^^
06  .2
07  ENTER^^
08  350
09  ENTER^^
10  661.5
11  ^/
12  X^2
13  ^*
14  ^+
15  ENTER^^  - not needed in manual mode
16  3.5
17  ^Y^X
18  ENTER^^  - not needed in manual mode
19  1
20  ^-
21  ENTER^^  - not needed in manual mode
22  1
23  ENTER^^
24  6.875 E-6
25  ENTER^^
26  25500
27  ^*
28  ^-
29  ENTER^^  - not needed in manual mode
30  -5.2656
31  ^Y^X
32  ^*
33  ENTER^^  - not needed in manual mode
34  1
35  ^+
36  ENTER^^  - not needed in manual mode
37  .286
38  ^Y^X
39  ENTER^^  - not needed in manual mode
40  1
41  ^-
42  ^*
43  SQRT
44  END

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
Find all posts by this user
Quote this message in a reply
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:

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

that's the standard notation used on the HP-41, and also the expected syntax by hp41uc.exe

Did you change your original code ?
Find all posts by this user
Quote this message in a reply
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.

Here's the manual (PDF): HP-67 Fun rom

And here's the link to Greg McClure's
http://www*hp41*org/LibView.cfm?Command=...leID=30533

replace the * with dot characters
Find all posts by this user
Quote this message in a reply
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 }
01▸LBL "AOS"
02 SF 27
03▸LBL a
04 CF 01
05 CF 02
06 CF 22
07 12
08 STO 23
09 -1
10 STO 24
11 CLX
12 RTN
13▸LBL "+"
14▸LBL A
15 61
16 GTO 00
17▸LBL "-"
18▸LBL B
19 51
20 GTO 00
21▸LBL "*"
22▸LBL C
23 42
24 GTO 00
25▸LBL "/"
26▸LBL D
27 32
28 GTO 00
29▸LBL "YX"
30▸LBL b
31 14
32 GTO 00
33▸LBL "NEG"
34▸LBL c
35 23
36 GTO 00
37▸LBL "<"
38▸LBL d
39 5
40▸LBL 00
41 10
42 ÷
43 STO 22
44 IP
45 X≠0?
46 GTO 00
47 FS? 01
48 XEQ 03
49▸LBL 00
50 R↓
51 FS?C 22
52 XEQ 02
53 RCL 22
54 IP
55 X=0?
56 GTO 00
57▸LBL 07
58 RCL 24
59 X<0?
60 GTO 00
61 RCL IND 24
62 FP
63 RCL 22
64 FP
65 X>Y?
66 GTO 00
67 RCL IND 24
68 IP
69 X=0?
70 GTO 00
71 XEQ 01
72 GTO 07
73▸LBL 00
74 ISG 24
75 ENTER
76 RCL 24
77 13
78 X≤Y?
79 ASIN
80 RCL 22
81 STO IND 24
82 RCL IND 23
83 CF 01
84 GTO 99
85▸LBL ">"
86▸LBL e
87 1
88 STO 22
89 X<>Y
90 FS?C 22
91 XEQ 02
92 RCL 24
93 X<0?
94 SQRT
95 RCL IND 24
96 IP
97 X=0?
98 GTO 08
99 XEQ 01
100 GTO e
101▸LBL 08
102 DSE 24
103 ENTER
104 RCL IND 23
105 SF 01
106 GTO 99
107▸LBL E
108▸LBL "="
109 1
110 STO 22
111 X<>Y
112 FS?C 22
113 XEQ 02
114 RCL 24
115 X<0?
116 GTO 00
117 RCL IND 24
118 XEQ 01
119 GTO E
120▸LBL 00
121 RCL IND 23
122 XEQ a
123 R↓
124 R↓
125 SF 22
126 GTO 99
127▸LBL 02
128 ISG 23
129 ENTER
130 21
131 RCL 23
132 -
133 X<0?
134 SQRT
135 R↓
136 STO IND 23
137 RCL 22
138 IP
139 X≠0?
140 RTN
141▸LBL 03
142 ISG 24
143 ENTER
144 4.2
145 STO IND 24
146 R↓
147 RTN
148▸LBL 01
149 RCL IND 23
150 DSE 23
151 RCL IND 23
152 X<>Y
153 XEQ IND ST Z
154 FS?C 02
155 ISG 23
156 ENTER
157 RCL 23
158 13
159 -
160 X<0?
161 SQRT
162 X<>Y
163 STO IND 23
164 DSE 24
165 RTN
166 RTN
167▸LBL 01
168 Y↑X
169 RTN
170▸LBL 02
171 +/-
172▸LBL 00
173 SF 02
174 RTN
175▸LBL 03
176 ÷
177 RTN
178▸LBL 04
179 ×
180 RTN
181▸LBL 05
182 +/-
183▸LBL 06
184 +
185▸LBL 99
186 RTN
187 SF 22
188 END
Find all posts by this user
Quote this message in a reply
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.
But for some reason XEQ IND Z is ignored.

Thanks for clarifying Thomas.
Your version is indeed much shorter, and doesn't lack functionality, I'm not wrong.

Best,
ÁM
Find all posts by this user
Quote this message in a reply
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:

\[
\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

No issue calculating the Mach number in manual mode onto a DM41X or HP41C.
Find all posts by this user
Quote this message in a reply
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.
But for some reason XEQ IND Z is ignored.

Thanks for clarifying Thomas.
Your version is indeed much shorter, and doesn't lack functionality, I'm not wrong.

Best,
ÁM

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


Attached File(s)
.zip  HP41AOS.zip (Size: 3.74 KB / Downloads: 8)
Find all posts by this user
Quote this message in a reply
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():
    return SQRT( 5 * ( ( ( ( ( 1 + .2 * ( 350 / 661.5 ) ** 2 ) ** 3.5 - 1 ) * ( 1 - 6.875E-6 * 25500 ) ** -5.2656 ) + 1 ) ** .286 - 1 ) )

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():
    return SQRT( ( ( ( ( ( 1 + .2 * ( 350 / 661.5 ) ** 2 ) ** 3.5 - 1 ) * ( 1 - 6.875E-6 * 25500 ) ** -5.2656 ) + 1 ) ** .286 - 1 ) * 5 )

This is the generated program for the HP-42S:
Code:
00 { 75-Byte Prgm }
01 1
02 0.2
03 350
04 661.5
05 ÷
06 X↑2
07 ×
08 +
09 3.5
10 Y↑X
11 1
12 -
13 1
14 6.875ᴇ-06
15 25500
16 ×
17 -
18 -5.2656
19 Y↑X
20 ×
21 1
22 +
23 0.286
24 Y↑X
25 1
26 -
27 5
28 ×
29 SQRT
30 END

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():
    return LN( ( - ( 9 ** 2 ** 3 * 45 ** ( 6 / 7 ) ) ** 2 ) ) + SIN( 6 - 7 ** 2 ** INV(3) ) * FACT(8) + 1 - 2 * 3 ** 4 / 5

This generated the following program for the HP-42S:
Code:
00 { 58-Byte Prgm }
01 -9
02 2
03 3
04 Y↑X
05 Y↑X
06 45
07 6
08 7
09 ÷
10 Y↑X
11 ×
12 X↑2
13 LN
14 6
15 7
16 2
19 Y↑X
17 3
18 1/X
20 Y↑X
21 -
22 SIN
23 8
24 N!
25 ×
26 +
27 1
28 +
29 2
30 3
31 4
32 Y↑X
33 ×
34 5
35 ÷
36 -
37 END

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.
Find all posts by this user
Quote this message in a reply
Post Reply 




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