Showing posts with label subroutines. Show all posts
Showing posts with label subroutines. Show all posts

Sunday, April 26, 2026

Retro Review: HP 65

Retro Review: HP 65







Quick Facts



Company: Hewlett Packard

Years: 1974 - 1977

Type: Scientific, RPN (Reverse Polish Notation)

Memory: 9 memory registers, 100 steps



Batteries: originally Ni-Cad, there are battery packs that can use AAA batteries (Ebay seller: waterhosko, https://www.ebay.com/usr/waterhosko)



DISCLAIMER:  I am not page for referring the website on eBay, nor I do not guarantee that inventory is available.



The HP 65 is first programmable calculator. I recently purchased a HP 65 from Persnickity Antiquity in Pomona, California. I saw that HP 65 a year earlier. What got me to purchase was it was for two reasons, (1) I have a HP 67 and fell in love with the classical HP calculators and (2), it had the AAA battery pack (see waterhosko above).Originally the HP 65 is ran with rechargeable Ni-Cad batteries.



Format Settings



The HP 65 has two format settings:



Scientific Format: [ DSP ] # (0-9)

Fixed Format: [ DSP ] [ . ] # (0 – 9)





Modifier Keys



There are three modifier keys: two orange shifts [ f ] and [ f^-1 ] and one blue shift [ g ]. The label for the orange shift is above the key and the label for the blue shift is below the key.



Inverse Key Table

[ f ]

[ f^-1 ]

LN

e^x

LOG

10^x

√x

SIN

SIN^-1

COS

COS^-1

TAN

TAN^-1

R→P (to polar)

P→R (to rectangular)

D.MS+

D.MS-

→D.MS (decimal, minute, seconds)

D.MS→ (decimal)

→OCT (to octal base)

→DEC (to decimal base)

INT (integer part)

FRAC (fractional part)

SF 1/SF 2 (set flag 1 or 2)

CF 1/CF 2 (clear flag 1 or 2)

TF 1/TF 2 (is flag 1 or 2 set?)

TF^-1 1/TF^-1 2 (is flag 1 or 2 clear?)





Programming



Program Steps



In program mode, the HP 65 displays only the key code. The key code is usually two digits, the first is the row (top-down), second is column (left-right). The exception is the digit keys where they would be labeled in the format 0#.



Editing is limited to SST (single step forward) and delete key ([ g ] [ Clx ] (DEL)).



Partially Merged Steps



The first programmable calculator holds up to 100 steps. Steps are partially merged. The program commands that are merged are:

STO # (1 – 8)

* does not include storage arithmetic

Swap X and Y: x<>y

Comparisons: x≠y, x=y, x≤y, x>y

RCL # (1 - 8)

Roll Down: R↓

All but STO/RCL are followed by the [ g ] shift key.

NOP (No operation)

Roll Up: R↑






Memory Registers



The HP 65 has nine memory registers R1 through R9. There is no R0 (register zero), which would be added in later calculators.



Two registers are used for specific purposes:

R8: Register 8 is used the counter in the DSZ command (Decrement and Skip if Zero command).

R9: Register 9 is used as a temporary register from trigonometric function calculations, rectangular/polar conversions, and for comparison tests, R9 is used as a Last X register.



R8 and R9 can be used for general use, but would be subject to change.



Comparisons and Labels



The HP 65 has four comparisons (x = y, x ≠ y, x ≤ y, x > y) and the DSZ command operate somewhat like most RPN calculators: if the test is true, the next step is executed. However, if the result is false, the next two steps are skipped. That’s right, the next two steps.



Example:

x > y

[ if true, x > y, execute this step; if false, x ≤ y, skip this step ]

[ also skip this step if x ≤ y ]

[ third step ]



Why two steps? The goto (GTO) command takes two steps on the HP 65. The HP 65 has 15 labels, 0 – 9 and A – E. If both steps are not needed, one can be filled by the NOP (No Op (Operation)) command.



Subroutines and Instant Labels



The labels A through E (A, B, C, D, E) are user programs that can be accessed by keys. They are the only labels act as subroutines. There is no XEQ/GSB command, subroutines are automatically called by pressing the corresponding key. Only one subroutine can be called at a time.



One quirk for the HP 65, if there is a program without a label A, then pressing [ A ] in run mode, execution starts from the first step.



The HP 65 loads five short default programs every time the calculator is turned on, which function is printed above the key in white:

[ A ] 1/x

[ B ] √x

[ C ] y^x

[ D ] R↓

[ E ] x<>y





Non-Continuous Memory



The memory on the HP 65 is not continuous. When the calculator is turned off, all memory is lost. The only way to save the memory registers and the steps require the use of thin memory cards and the built-in card reader. Each card can hold 100 steps.



I love the classic RPN HP calculators from the early 1970s. I have three of them now, the HP 45 (1973), HP 65 (1974), and HP 67 (1976).








Sources


“HP 65” The Museum of HP Calculators (MoHPC). https://www.hpmuseum.org/hp65.htm Retrieved April 1, 2026.


“HP-65 Programming” The Museum of HP Calculators (MoHPC). https://www.hpmuseum.org/prog/hp65prog.htm Retrieved April 1, 2026.


Hewlett-Packard. HP-65 Owner’s Handbook. Cupertino, CA. July 1974.



Eddie


All original content copyright, © 2011-2026. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.


Sunday, August 11, 2024

Swiss Micros DM41X and fx-6500G: Complex Gudermannian Function and Its Inverse

Swiss Micros DM41X and fx-6500G: Complex Gudermannian Function and Its Inverse


Introduction


The Complex Gudermannian Function and the inverse are calculated as:


gd(x + yi) = u +vi where:

i = √-1

u = arctan( sinh x / cos y) = angle( cos y + i*sinh x )

v = arctanh( sin y / cosh x )


gd^-1(u + vi) = x + yi where:

i = √-1

x = arctanh( sin u / cosh v )

y = arctan( sinh v / cos u ) = angle(cos u + i*sinh v )


Notes:


* The calculator is set to radians mode during program execution.

* The arctangent function is handled using the rectangular to polar conversion (using the angle part). Doing so will increase the range between -π to π. The results are normalized.

* The results may not necessarily be the only answer but an attempt to get the principle branch.



Swiss Micros DM41X: Gudermannian and Inverse Gudermannian Functions


The DM41X is similar to the Hewlett Packard HP 41C series. Assuming we have no mathematical modules plugged in, the hyperbolic functions must be programmed as they were not included in the original function set.


Keeping with RPN notation, the imaginary part is placed on the Y stack and the real part is placed on the X stack. The memory registers used:


R01 = X

R02 = Y

R03 = U

R04 = V

gd(X + Yi) = U + Vi


The hyperbolic functions operate on real values only, and the in the Gudermannian and its inverse functions handle the real and imaginary parts separately.


DM41X: Hyperbolic Sine Routine: SINH


01 LBL^T SINH

02 ENTER↗

03 E↗X

04 X<>Y

05 CHS

06 E↗X

07 -

08 2

09 /

10 RTN

11 END


DM41X: Hyperbolic Cosine Routine: COSH


01 LBL^T COSH

02 ENTER↗

03 E↗X

04 X<>Y

05 CHS

06 E↗X

07 +

08 2

09 /

10 RTN

11 END


DM41X: Hyperbolic Arctangent Routine: ATANH


01 LBL^T ATANH

02 ENTER↗

03 ENTER↗

04 1

05 +

06 X<>Y

07 CHS

08 1

09 +

10 /

11 LN

12 2

13 /

14 RTN

15 END


Now to the main programs:


DM41X: Complex Gudermannian Function: CDG


01 LBL^T CGD

02 RAD

03 STO 01

04 X<>Y

05 STO 02

06 RCL 01

07 XEQ^T SINH

08 RCL 02

09 COS

10 R-P

11 X<>Y

12 STO 03

13 RCL 02

14 SIN

15 RCL 01

16 XEQ^T COSH

17 /

18 XEQ^T ATANH

19 STO 04

20 RCL 03

21 RTN

22 END


DM41X: Inverse Complex Gudermannian Function: CGDI


01 LBL^T CGDI

02 STO 03

03 X<>Y

04 STO 04

05 RAD

06 RCL 03

07 SIN

08 RCL 04

09 XEQ^T COSH

10 /

11 XEQ^T ATANH

12 STO 01

13 RCL 04

14 XEQ^T SINH

15 RCL 03

16 COS

17 R-P

18 X<>Y

19 STO 02

20 RCL 01

21 RTN

22 END


Casio fx-6500G: Gudermannian and Inverse Gudermannian Functions


The code can easily be adapted to other Casio calculators.


gd(X + Yi) = U + Vi


In these program listings, the real and imaginary parts are handled separately. For the fx-6500G (and same for the fx-7000G, 7500G, and 8000G), the Rectangular to Polar (Pol(x,y)) conversion stores the radius in the variable I and angle (θ) in the variable J. For the early Casio models, switch to Radians mode by pressing [ MODE ] [ 5 ].


gd(X + Yi) → U + Vi

Code:

Rad

“GD(X+YI)”

“X”:? → X

“Y”:? → Y

Pol(cos Y, sinh X)

J → U

tanh^-1 (sin Y ÷ cosh X) → V

“U + VI=”

U ⊿

V


gd^-1(U + Vi) → X + Yi


Code:

Rad

“GD^-1(U+YI)”

“U”:? → U

“V”:? → V

tanh^-1 (sin U ÷ cosh V) → X

Pol(cos U, sinh V)

J → Y

“X + YI=”

X ⊿

Y


Examples


Results are rounded to six decimal places. Be aware only one answer is given.


1. gd(3 + 4i) ≈ 1.635952 – 0.075314i

2. gd(-7 + 2i) ≈ -1.571555 + 0.001658i

3. gd(0 + 3i) ≈ 3.141593 + 0.142068i

4. gd(-3 + 0i) ≈ -1.471304 + 0i



Sources


“The Complex Gudermannian Function” analyticphysics.com. Uploaded June 16, 2021. Accessed June 23, 2024. https://analyticphysics.com/Complex%20Variables/The%20Complex%20Gudermannian%20Function.htm


“Gudermannian function” Wikipedia. Last Edited May 23, 2024. Accessed June 20, 2024.

https://en.wikipedia.org/wiki/Gudermannian_function#:~:text=The%20Gudermannian%20function%20relates%20the,sector%20is%20%CF%95%20%3D%20gd%20%CF%88.



Eddie


All original content copyright, © 2011-2024. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Monday, April 25, 2022

Retro Review: Texas Instruments TI-57 LCD

Retro Review:   Texas Instruments TI-57 LCD











Quick Facts:


Model:  TI-57 LCD

Company:  Texas Instruments

Years:  1982-1984

Type:  Programming

Batteries: 2 x LR44

Operating Mode:  AOS

Memory Registers: Minimum of 1, Maximum of 8

Program Steps:  Minimum of 0, Maximum of 48


Similar to many Texas Instruments programming calculators of the 1970s and 1980s, the memory can be partition between memory steps and program steps by the [ 2nd ] [ Part ] key sequence.  Each register has 8 program steps.  


Some Partitions:


Part 1:  1 register (R0), 48 steps

Part 2:  2 registers (R0, R1), 40 steps

Part 3:  3 registers (R0, R1, R2), 32 steps

Part 4:  4 registers (R0, R1, R2, R3), 24 steps


Features 


* trigonometric functions and inverses

* polar/rectangular conversions and degrees/degrees-minutes-seconds conversions

* integer part (Intg), fractional part (Frac), absolute value ( |x| )

* logarithms (log, ln x)

* storage arithmetic ([STO] followed by +, -, ×, ÷, y^x, INV y^x)


INV Key combinations


[ INV ] [ sin ]:  arcsin

[ INV ] [ cos ]: arccos

[ INV ] [ tan ]:  arctan

[ 2nd ] [ INV ] (P<>R):  rectangular to polar

[ 2nd ] [ INV ] (DMS-DD):  degrees to degrees-minutes-seconds

[ INV ] [ y^x ]:  y^(1/x)

[ INV ] [ log ]:  10^x

[ INV ] [ ln ]: e^x

[ 2nd ] [ INV ] (SBR):  RETURN - this ends subroutines

[ 2nd ] [ INV ] (Dsz):  Decrement R0 by 1 and skip if R0 ≠ 0


Polar to Rectangular:

r [ x<>t ] θ [ 2nd ] [ P<>R ]:   y [ x<>t ] x


Rectangular to Polar:

x [ x<>t ] y [ 2nd ] [ INV ] [ P<>R ]:   Î¸ [ x<>t ] r


Keystroke Programming


The TI-57 LCD is a keystroke programmable calculator.   However, programming steps are at a premium with a maximum of 48 steps (allowing for one memory register) to 0 (yes, zero) if you use all 8 registers (R0 to R7).  


Programming commands include:


*  Test with the t register:  x=t,  x≥t, and inverses

*  Decrement and Skip:  either skip on zero or not on zero.  This command works on register 0.  

*  Labels and Go to commands:  labels 0-9

*  Pause command

*  Subroutines (SBR)

*  Go to step zero (RST)


Thankfully some steps are merged, mainly with the [ INV ] key, [ GTO ] key (GO TO command), [ 2nd ] key, and storage arithmetic.  


What is interesting is that there are no statistical functions on the TI-57 LCD.   See the One Variable Statistics section for a 25-step program to add one-variable statistics.  


Keyboard


We need to talk about the keyboard.  The keyboard looks good.  I have the United States edition of the TI-57 LCD and I like the blue, gray, black, and white color scheme.   


Unfortunately, some keys are hard to press and other keys can produce a double-stroke.  With the calculator I got, one wrong press gives a double number (22 instead of 2, 00 instead of 0) while some keys pressed in the "wrong" way do not register.  This does not allow for fast typing.   I think I found the keys "sweet spots":  the right side of the keys.    


The keyboard difficulties are a common complaint with the TI-57 LCD.   They are corrected with the TI-57 II released in 1986.  


TI-57 LCD Program:  One Variable Statistics

Memory Registers Required: 3  (Part 3)


00  23.01     LBL 1   // data entry

01  61.85.01 STO+ 1

02  34 x^2

03  61.85.02 STO+ 2

04  1 1

05  61.85.00 STO+ 0

06  13 R/S

07  22.01     GTO 1


08  23.02     LBL 2   // calculation

09  71.01    RCL 1

10  55 ÷

11  71.00     RCL 0

12  95 =

13  13 R/S   // sample mean

14  71.02     RCL 2

15  55 ÷

16  71.00     RCL 0

17  75 -

18  53 (

19  71.01     RCL 1

20  55 ÷

21  71.00     RCL 0

22  54 )

23  34 x^2

24  95 =

25  35

26  13 R/S  // population deviation


Registers used:

R0 = number of data points = n

R1 = sum of the data points = Σx

R2 = sum of the data points squared = Σx^2


Mean:

x-bar = Σx / n


Population Deviation

σx = √( Σx^2/n - (Σx/n)^2 )


Instructions:

1.  If necessary, partition memory to fit 3 memory registers (R0, R1, R2).  [ 2nd ] (Part) [ 3 ].

2.  Enter the first point, press [ GTO ] [ 1 ], then [ R/S ].  1 is displayed when data points are entered.

3.  Enter each subsequent point, press [ R/S ].  Repeat until finished.  

4.  To calculate the mean and population deviation, press [ GTO ] [ 2 ].   The mean is displayed first, press [ R/S ] to display population deviation.  


[ RCL ] [ 0 ]:  number of points

[ RCL ] [ 1 ]:  sum of data points

[ RCL ] [ 2 ]:  sum of squares of data points


Example 1:


Data Set: 4, 5, 9, 8, 6


Results:

n = 5

Σx = 32

Σx^2 = 222

x-bar = 6.4

σx = 1.854723699


Example 2:


Data Set: 11058, 12360, 12445, 12761, 13002, 13360


Results:

n = 6

Σx = 74986

Σx^2 ≈ 9.40 * 10^8

x-bar = 12497.66667

σx = 725.9110757


Closing Thoughts


I wish the TI-57 LCD had both more memory and functions.   Honestly, Texas Instruments could combine the functions of the TI-57 LCD (tests, labels, go to, decrement and skip), the TI-55 III (better keyboard, linear regression, integrals, unit conversions, signum function, permutations, combinations), and the later TI-60 (the TI-55III with base conversions) with a total of 188 steps.  The programming set up with the TI-57 LCD wins with it's merged steps with INV, STO, LBL, and GTO.   


Overall, I like the appearance of the TI-57 LCD, despite the keyboard's set backs. That, the lack of functions and statistics, and the sometimes slow execution and we can see why the TI-57 LCD was not a best seller.  


HP 32S and HP 32SII Week:  May 2, 2022 - May 6, 2022


Until next time,


Eddie


All original content copyright, © 2011-2022.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 



Thursday, October 19, 2017

Adventures in Python: String Manipulation and Function/Derivative Table (Subroutines)

Adventures in Python:  String Manipulation and Function/Derivative Table (Subroutines)

String Manipulation

This script demonstrates several string functions:

length:  the number of characters in a string

stringname.replace(‘target string’,‘new string’):  replace a part of a string

stringname.capitalize(): capitalize the first letter of a string

stringname.split():  splits a string at its spaces

Other string functions:

stringname.lower(): makes all letters of a string to lower case

stringname.upper():  makes all letters of a string to upper case

You can join strings with the plus symbol ( + ).

The nice thing is that you won’t need to import any modules for the above string functions.

Script:

# program 008
print('Program 008: String Demo')
str1 = input('Please type some text.  ')
# input defaults to strings
# length
print('Length')
l = len(str1)
print('Length',l)
# capitalizes the first letter
print('Capitalize')
str2 = str1.capitalize()
print(str2)
# string splits at spaces
print('Split')
str3 = str1.split()
print(str3)
# replacement
str4 = str1
str4 = str4.replace('a','e')
str4 = str4.replace('u','a')
str4 = str4.replace('o','u')
str4 = str4.replace('i','o')
str4 = str4.replace('e','i')
print('Can you read this?')
print(str4)

Output:  with the “This is my demonstration.”

Program 008: String Demo
Please type some text.  This is my demonstration.
Length
Length 25
Capitalize
This is my demonstration.
Split
['This', 'is', 'my', 'demonstration.']
Can you read this?
Thos os my dimunstritoun.


Function/Derivative Table (Subroutines)

You can create user functions (subroutines) in python by the def structure.  You return results by the return command.

Script (you can enter whatever your function you like, I have imported the math module):

# Program 009 Using def and creating a table
# import math
import math

def fx(x):
     f = math.exp(-x**2/2)
     return f;
    
print('Function Table')
beg = float(input('start: '))
end = float(input('stop: '))
stp = float(input('step: '))

# loop begins
h = .00001
k = beg
print('k',':','f(x)',';','slope')
while k <= end:
     # function
     a = fx(k)
     # derivative
     b = fx(k+h)
     c = fx(k-h)
     d = (b - c)/(2 * h)
     print(k,',',a,',',d)
     print('- - - - - - - -')
     k = k + stp
           

Output (with start = 0, stop = 5, step = 1)

Function Table
start: 0
stop: 5
step: 1
k : f(x) ; slope
0.0 , 1.0 , 0.0
- - - - - - - -
1.0 , 0.6065306597126334 , -0.6065306596914066
- - - - - - - -
2.0 , 0.1353352832366127 , -0.27067056647955834
- - - - - - - -
3.0 , 0.011108996538242306 , -0.033326989618259056
- - - - - - - -
4.0 , 0.00033546262790251185 , -0.0013418505118650097
- - - - - - - -
5.0 , 3.726653172078671e-06 , -1.8633265866508763e-05
- - - - - - - -

Eddie


This blog is property of Edward Shore, 2017.

Sunday, November 17, 2013

HP Prime Programming Tutorial #6: Subroutines

Subroutines

This session will show how routines work in HPPL. Generally, subroutines have be declared before the main program. Declaration is important. The details of the subroutines are after the main program.

Definitely take a look at the example programs to get a better understanding.

SUB Routines for HP Prime

General Syntax:

sub(); //declare subroutines

EXPORT main()
BEGIN
commands go here, including sub()
END;

sub()
BEGIN
commands go here
END;



SUBEXAM

This is just a demonstration of how sub routines work. This program calculates one of two values:

If A is positive, then the program evaluates A. If not, the program values B instead. Where:

A = 2(x-y)/Φ + xy
B = Φ^2

and Φ = 2e^(x+y) - e^(x-y) - e^(y-x)

We will use Φ as the subroutine.

SUB1();

EXPORT SUBEXAM(X,Y)
BEGIN
LOCAL A, B;
A:=(2*(Y-X))/SUB1(X,Y)+X*Y;
B:=(SUB1(X,Y))^2;
IF A>B THEN
RETURN A;
ELSE
RETURN B;
END;
END;

SUB1(X,Y)
BEGIN
RETURN 2*e^(X+Y)-e^(X-Y)-e^(Y-X);
END;


Examples:

SUBEXAM(-4, 1) returns 21998.918189
SUBEXAM(2,3) returns 86283.2797974
SUBEXAM(-5,-6) returns 30.648061288
SUBEXAM(2,-3) returns 21810.6046664


Days Between Dates

DDAYS Using Subroutines for HP Prime: Best for 1901 to 2099

* Remember century years not divisible by 400 are NOT leap years. This program does not take this into account. If any such years are passed, subtract one day for such year manually.

Source: HP 12C Manual - Hewlett Packard

// Declare Subroutines
SUB1();
SUB2();
SUB3();

// Main program
EXPORT DDAYS(m1,d1,y1,m2,d2,y2)
BEGIN
// ΔDYS HP 12C
LOCAL x1, x2, z1, z2;
x1:=SUB1(m1); x2:=SUB1(m2);
z1:=SUB2(m1,y1); z2:=SUB2(m2,y2);
RETURN SUB3(y2,m2,d2,z2,x2)-
SUB3(y1,m1,d1,z1,x1);
END;

SUB1(X)
BEGIN
IF X≤2 THEN
RETURN 0;
ELSE
RETURN IP(.4*X+2.3);
END;
END;

SUB2(X,Y)
BEGIN
IF X≤2 THEN
RETURN Y-1;
ELSE
RETURN Y;
END;
END;

SUB3(Y,M,D,Z,X)
BEGIN
RETURN 365*Y+31*(M-1)+D+IP(Z/4)-X;
END;

(Thanks to Owitte for pointing out my typo)



Examples:
Days Between Dates:

7/3/1985 to 2/28/1995 is 3,527 days

3/14/1977 to 11/17/2013 is 13,397 days

12/10/2010 to 6/30/2014 is 1,298 days

1/5/2015 to 3/19/2227 returns 77,506 BUT this program treats 2100 and 2200 as leap years, which in reality they are not. Subtract 2 to get the correct answer of 77,504 days.

So that is how subroutines work. Please give comments, ask questions, and always thanks to my supporters and readers. Cheers!

Eddie

This blog is property of Edward Shore. 2013


DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues The programs are listed for the Swiss Micros DM42 an...