The Display Register or X Register shows the result after the execution of a Program.
In the Python code, the X Register corresponds to the variable "x".
The Display History shows the values of the Display Register each time the Program encounters the "2nd Pause" key.
The real Calculator would pause for a second while the Emulator keeps track of the X Register.
In the Python code, the Display History is stored in the "regx" list.
The Display Register is editable. Enter a list of numbers separated by spaces to change the Data. Then click elsewhere to see the effect of the change in the Program. Or press the Enter key to run the Program with the new Data. For example, suppose the Data begins with 10 STO 1 20 STO 2 30 STO 3 and you want to replace the first two with 11 STO 1 22 STO 2. You can either edit the program directly or enter 11 22 in the Display Register. This is handy especially with games.
# | History |
---|---|
Current. | 0 |
Program Instructions/Keys
# Scores vs Performance (Linear Regression)
# You want to evaluate a test for prospective employees.
# You have both the employee test score and the actual sales performance.
# What are the slope, the y intercept and the correlation?
# What sales performance would a test score of 9 predict?
# What test score would indicate a sales performance 75% above target?
# Answer: 2.68, 6.14, 0.75, 0.87, 30.29, 25.66.
# Run the Program then check the details in the History.
# Source: "TI-57 Making Tracks into Programming.pdf#page=182", p. 9-14
import re
from math import *
from goto import with_goto # pip install goto-statement
@with_goto
def main():
global ee, mem, rounding, stack, unit, x
label .label_rst
# Data Input
x = 5 # 5
y = mem[7] # x<>t (22)
mem[7] = x
x = y
x = 10 # 10
mem[0] += 1 # 2nd S+ (88)
mem[1] += x
mem[2] += x * x
mem[3] += mem[7]
mem[4] += mem[7] * mem[7]
mem[5] += mem[7] * x
mem[7] += 1
x = 13 # 13
y = mem[7] # x<>t (22)
mem[7] = x
x = y
x = 30 # 30
mem[0] += 1 # 2nd S+ (88)
mem[1] += x
mem[2] += x * x
mem[3] += mem[7]
mem[4] += mem[7] * mem[7]
mem[5] += mem[7] * x
mem[7] += 1
x = 8 # 8
y = mem[7] # x<>t (22)
mem[7] = x
x = y
x = 30 # 30
mem[0] += 1 # 2nd S+ (88)
mem[1] += x
mem[2] += x * x
mem[3] += mem[7]
mem[4] += mem[7] * mem[7]
mem[5] += mem[7] * x
mem[7] += 1
x = 10 # 10
y = mem[7] # x<>t (22)
mem[7] = x
x = y
x = 40 # 40
mem[0] += 1 # 2nd S+ (88)
mem[1] += x
mem[2] += x * x
mem[3] += mem[7]
mem[4] += mem[7] * mem[7]
mem[5] += mem[7] * x
mem[7] += 1
x = 15 # 15
y = mem[7] # x<>t (22)
mem[7] = x
x = y
x = 60 # 60
mem[0] += 1 # 2nd S+ (88)
mem[1] += x
mem[2] += x * x
mem[3] += mem[7]
mem[4] += mem[7] * mem[7]
mem[5] += mem[7] * x
mem[7] += 1
x = 20 # 20
y = mem[7] # x<>t (22)
mem[7] = x
x = y
x = 50 # 50
mem[0] += 1 # 2nd S+ (88)
mem[1] += x
mem[2] += x * x
mem[3] += mem[7]
mem[4] += mem[7] * mem[7]
mem[5] += mem[7] * x
mem[7] += 1
x = 4 # 4
y = mem[7] # x<>t (22)
mem[7] = x
x = y
x = 20 # 20
mem[0] += 1 # 2nd S+ (88)
mem[1] += x
mem[2] += x * x
mem[3] += mem[7]
mem[4] += mem[7] * mem[7]
mem[5] += mem[7] * x
mem[7] += 1
x = 16 # 16
y = mem[7] # x<>t (22)
mem[7] = x
x = y
x = 60 # 60
mem[0] += 1 # 2nd S+ (88)
mem[1] += x
mem[2] += x * x
mem[3] += mem[7]
mem[4] += mem[7] * mem[7]
mem[5] += mem[7] * x
mem[7] += 1
x = 18 # 18
y = mem[7] # x<>t (22)
mem[7] = x
x = y
x = 50 # 50
mem[0] += 1 # 2nd S+ (88)
mem[1] += x
mem[2] += x * x
mem[3] += mem[7]
mem[4] += mem[7] * mem[7]
mem[5] += mem[7] * x
mem[7] += 1
x = 6 # 6
y = mem[7] # x<>t (22)
mem[7] = x
x = y
x = 20 # 20
mem[0] += 1 # 2nd S+ (88)
mem[1] += x
mem[2] += x * x
mem[3] += mem[7]
mem[4] += mem[7] * mem[7]
mem[5] += mem[7] * x
mem[7] += 1
# Data Preprocessing
rounding = 2 # 2nd Fix 2 (48)
sbr_0() # SBR 0 (61 0)
regx.append(fix(x)) # 2nd Pause (36)
sbr_1() # SBR 1 (61 0)
regx.append(fix(x)) # 2nd Pause (36)
sbr_2() # SBR 2 (61 0)
regx.append(fix(x)) # 2nd Pause (36)
x = sqrt(x) # Vx (24)
regx.append(fix(x)) # 2nd Pause (36)
x = 9 # 9
sbr_3() # SBR 3 (61 0)
regx.append(fix(x)) # 2nd Pause (36)
x = 75 # 75
sbr_4() # SBR 4 (61 0)
regx.append(fix(x)) # 2nd Pause (36)
# Data Processing (49 steps)
return # R/S (81)
# Subroutine: Calculate the slope (m)
@with_goto
def sbr_0():
global ee, mem, rounding, stack, unit, x
label .label_0 # 2nd lbl 0 (86 0)
x = mem[5] # RCL 5 (33 0)
stack.append(x) # : (45)
x = mem[0] # RCL 0 (33 0)
y = stack.pop() # - (65)
x = y / x
stack.append(x)
x = mem[1] / mem[0] # 2nd x (89)
stack.append(x) # X (55)
x = mem[3] / mem[0] # INV 2nd x (- 89)
y = stack.pop() # = (85)
x = y * x
y = stack.pop()
x = y - x
stack.append(x) # : (45)
x = (mem[4] - mem[3] * mem[3] / mem[0]) / mem[0] # INV 2nd s2 (- 80)
y = stack.pop() # = (85)
x = y / x
label .end # INV SBR (- 61)
# Subroutine: Calculate the y intercept (b)
@with_goto
def sbr_1():
global ee, mem, rounding, stack, unit, x
label .label_1 # 2nd lbl 1 (86 0)
sbr_0() # SBR 0 (61 0)
stack.append(x) # X (55)
x = mem[3] / mem[0] # INV 2nd x (- 89)
x = -x # +/- (84)
y = stack.pop() # + (75)
x = y * x
stack.append(x)
x = mem[1] / mem[0] # 2nd x (89)
y = stack.pop() # = (85)
x = y + x
label .end # INV SBR (- 61)
# Subroutine: Calculate the correlation (r²)
@with_goto
def sbr_2():
global ee, mem, rounding, stack, unit, x
label .label_2 # 2nd lbl 2 (86 0)
sbr_0() # SBR 0 (61 0)
x *= x # x^2 (23)
stack.append(x) # : (45)
x = (mem[2] - mem[1] * mem[1] / mem[0]) / mem[0] # 2nd s2 (80)
y = stack.pop() # X (55)
x = y / x
stack.append(x)
x = (mem[4] - mem[3] * mem[3] / mem[0]) / mem[0] # INV 2nd s2 (- 80)
y = stack.pop() # = (85)
x = y * x
label .end # INV SBR (- 61)
# Subroutine: Calculate y given x
@with_goto
def sbr_3():
global ee, mem, rounding, stack, unit, x
label .label_3 # 2nd lbl 3 (86 0)
mem[7] = x # STO 7 (32 0)
sbr_0() # SBR 0 (61 0)
mem[7] *= x # 2nd Prd 7 (39 0)
sbr_1() # SBR 1 (61 0)
mem[7] += x # SUM 7 (34 0)
x = mem[7] # RCL 7 (33 0)
label .end # INV SBR (- 61)
# Subroutine: Calculate x given y
@with_goto
def sbr_4():
global ee, mem, rounding, stack, unit, x
label .label_4 # 2nd lbl 4 (86 0)
mem[7] = x # STO 7 (32 0)
sbr_1() # SBR 1 (61 0)
mem[7] -= x # INV SUM 7 (- 34 0)
sbr_0() # SBR 0 (61 0)
mem[7] /= x # INV 2nd Prd 7 (- 39 0)
x = mem[7] # RCL 7 (33 0)
label .end # INV SBR (- 61)
# Internal functions
def degrees2dms(degrees):
"""Convert decimal degrees to degrees, minutes, seconds."""
degrees = float(degrees)
is_positive = degrees >= 0
if not is_positive:
degrees = -degrees
minutes, seconds = divmod(degrees * 3600, 60)
degrees, minutes = divmod(minutes, 60)
# Internal mantissa has 11 digits on TI-57
seconds = f"{seconds:016.13f}".replace(".", "")
dms = f"{int(degrees)}.{int(minutes):02}{seconds}".rstrip("0")
if not is_positive:
dms = "-" + dms
return dms
def dms2degrees(dms):
"""Convert degrees, minutes, seconds to decimal degrees."""
match = re.fullmatch(
r"(?P[+-])?(?P[0-9]+)\.?(?P[0-9]{1,2})?(?P[0-9]{1,2})?(?P[0-9]*)",
str(dms),
)
if match is None:
raise Exception(f"Calculator error: invalid DMS angle {dms}")
angle = match.groupdict()
degrees = float(angle["degrees"])
if angle["minutes"]:
if len(angle["minutes"]) == 1:
angle["minutes"] += "0"
degrees += float(angle["minutes"]) / 60
if angle["seconds"]:
if len(angle["seconds"]) == 1:
angle["seconds"] += "0"
degrees += float(angle["seconds"]) / 3600
if angle["remainder"]:
degrees += float("0." + angle["remainder"]) / 3600
if angle["sign"] == "-":
degrees = -degrees
return degrees
def fix(number):
"""Round a number and/or convert it to the scientific notation."""
global ee, rounding
if ee:
# The scientific notation is on
if rounding is None:
# Default to the calculator 7 digit precision
number = f"{number:.7E}"
# Remove trailing 0s
number = re.sub("0+E", "E", number)
else:
# Round as exponent with the given precision
number = f"{number:.{rounding}E}"
elif rounding is not None:
# Rounding is on
number = f"{number:.{rounding}f}"
else:
# No rounding
number = str(number)
return number
def grd2rad(gradian):
"""Convert gradian to radian."""
return (gradian / 200) * pi
def get_calculator_state():
"""Return the calculator sate."""
global ee, error, mem, regx, rounding, stack, unit, x
return {
"ee": ee,
"error": error,
"fixed_x": fix(x),
"mem": mem,
"regx": regx,
"rounding": rounding,
"stack": stack,
"unit": unit,
"x": x,
}
def init_calculator_state(state={}):
"""Initialize the calculator state.
Must be called before running the program, see run().
ee -- Scientific notation (EE)
error -- Syntax error etc.
mem -- Memories (STO)
regx -- History of values displayed before a pause (2nd pause)
rounding -- Number of digit after the decimal point (2nd Fix)
stack -- Internal memory stack used for computing nested operations
unit -- Angle unit (2nd Deg, 2nd Rad, 2nd Grad)
x -- Display register or X register
"""
global ee, error, mem, regx, rounding, stack, unit, x
ee = state["ee"] if "ee" in state else False
error = state["error"] if "error" in state else None
mem = state["mem"] if "mem" in state else [0 for i in range(8)]
regx = state["regx"] if "regx" in state else []
rounding = state["rounding"] if "rounding" in state else None
stack = state["stack"] if "stack" in state else []
unit = state["unit"] if "unit" in state else "Deg"
x = state["x"] if "x" in state else 0
def rad2grd(radian):
"""Convert radian to gradian."""
return (radian / pi) * 200
def rad2unit(number):
"""Convert radian to degree or gradian."""
global unit
number = float(number)
if unit == "Deg":
number = degrees(number)
elif unit == "Grd":
number = rad2grd(number)
return number
def run_program():
"""Run the program (the entry point).
The calculator must be initialized beforehand, see init_calculator_state().
"""
global error, x
try:
main()
except ZeroDivisionError:
x = 9.9999999
except UserWarning: # R/S key
pass
except Exception as e:
error = str(e)
def unit2rad(number):
"""Convert degree or gradian to radian."""
global unit
number = float(number)
if unit == "Deg":
number = radians(number)
elif unit == "Grd":
number = grd2rad(number)
return number
# Program execution, uncomment to run the file on its own.
# init_calculator_state()
# run_program()
# calculator_state = get_calculator_state()
# print(calculator_state)