Post Reply 
Algebraic Operation System (AOS)
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 


Messages In This Thread
RE: Algebraic Operation System (AOS) - Thomas Klemm - 04-24-2022 11:18 PM



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