From 1ee850fd3fcd7f1964c41c70b2475e558d27abd1 Mon Sep 17 00:00:00 2001 From: Noah Smith Date: Fri, 20 Sep 2024 13:49:36 +0200 Subject: [PATCH] ipwr py and for skeleton --- .gitignore | 3 +- .vscode/launch.json | 21 +++++ .vscode/tasks.json | 10 +++ {algebra => pdp10/algebra}/__init__.py | 0 pdp10/algebra/ipwr.for | 11 +++ pdp10/algebra/ipwr.py | 21 +++++ {algebra => pdp10/algebra}/simplex.py | 53 ++++++------- pdp10/docs/sec5-minimalist-walkthrough.md | 94 +++++++++++------------ 8 files changed, 137 insertions(+), 76 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json rename {algebra => pdp10/algebra}/__init__.py (100%) create mode 100644 pdp10/algebra/ipwr.for create mode 100644 pdp10/algebra/ipwr.py rename {algebra => pdp10/algebra}/simplex.py (97%) diff --git a/.gitignore b/.gitignore index 8f2f87d..e4ccca2 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,5 @@ lang-sentences* /venv310/ /cmake-build-debug-docker/ /build-docs/ -.vscode +/a.out.dSYM/ +a.out diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..fdbf0ab --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "for", + "type": "cppdbg", + "request": "launch", + "preLaunchTask": "ipwr", + "program": "${workspaceFolder}/a.out", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb" + }, + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..00dd186 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,10 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "shell", + "label": "ipwr", + "command": "gfortran pdp10/algebra/ipwr.for -g -O0 -fbacktrace -fcheck=all -ffpe-trap=zero,overflow,underflow -Wall -Wextra -Warray-temporaries -Wconversion -ffree-line-length-0", + } + ] +} diff --git a/algebra/__init__.py b/pdp10/algebra/__init__.py similarity index 100% rename from algebra/__init__.py rename to pdp10/algebra/__init__.py diff --git a/pdp10/algebra/ipwr.for b/pdp10/algebra/ipwr.for new file mode 100644 index 0000000..d1f05ae --- /dev/null +++ b/pdp10/algebra/ipwr.for @@ -0,0 +1,11 @@ + + + integer i + real pi + pi = 3.1415927 + i = 0 + i = i + 1 +10 format (f10.7) + write (*, 10) pi + end + \ No newline at end of file diff --git a/pdp10/algebra/ipwr.py b/pdp10/algebra/ipwr.py new file mode 100644 index 0000000..6327305 --- /dev/null +++ b/pdp10/algebra/ipwr.py @@ -0,0 +1,21 @@ +""" imaginary powers of base 10. starting with 10**(i/1024), and squaring successively ten times. this matches with feynman's table 22-3""" +from math import sqrt + +# non rounded version +y = .00225 # should be .0022486 +x = sqrt(1. - y**2) +for _ in range(11): + print('%10.7f %10.7f' % (x, y)) + x2 = x**2 - y**2 + y2 = 2 * x * y + x, y = x2, y2 + +# rounded version that more closely matches feynman's table 22-3 +y = .00225 # should be .0022486 +x = round(sqrt(1. - y**2), 7) +for _ in range(11): + print('%10.5f %10.5f' % (x, y)) + x2 = round(x**2 - y**2, 7) + y2 = round(2 * x * y, 7) + x, y = x2, y2 + \ No newline at end of file diff --git a/algebra/simplex.py b/pdp10/algebra/simplex.py similarity index 97% rename from algebra/simplex.py rename to pdp10/algebra/simplex.py index 5e82ca6..040578f 100644 --- a/algebra/simplex.py +++ b/pdp10/algebra/simplex.py @@ -1,28 +1,25 @@ -"""simplest possible simplex implementation""" -import numpy as np - - -def main(): - A = np.array([[-2, 1, 1, 0, 0], [-1, 2, 0, 1, 0], [1, 0, 0, 0, 1]]) - b = np.array([2, 7, 3]) - c = np.array([-1, -2, 0, 0, 0]) - x = simplex(A, b, c) - return x - - -def simplex(A, b, c): - """revised simplex method. """ - m, n, o = A.shape[0], A.shape[1], A.shape[1] - A.shape[0] - ns, v1, v2 = [i for i in range(n)], np.array(c[o:]), np.array(c[:o]) - Binv = np.linalg.inv(A[:, ns[o:]]) - while not np.min(v2 - v1 @ Binv @ A[:, ns[:o]]) > 0: - n1 = np.argmin(v2 - v1 @ Binv @ A[:, ns[:o]]) - t1, t2 = Binv @ b, Binv @ A[:, ns[n1]] - n2 = np.argmin([t1[i] / t2[i] if t2[i] > 0 else np.inf for i in range(m)]) - ns[n1], ns[n2 + o], v1[n2], v2[n1] = ns[n2 + o], ns[n1], v2[n1], v1[n2] - Binv = np.linalg.inv(A[:, ns[o:]]) - return Binv @ b - - -if __name__ == "__main__": - main() +"""simplest possible simplex implementation""" +import numpy as np + +def main(): + A = np.array([[-2, 1, 1, 0, 0], [-1, 2, 0, 1, 0], [1, 0, 0, 0, 1]]) + b = np.array([2, 7, 3]) + c = np.array([-1, -2, 0, 0, 0]) + x = simplex(A, b, c) + return x + +def simplex(A, b, c): + """revised simplex method. """ + m, n, o = A.shape[0], A.shape[1], A.shape[1] - A.shape[0] + ns, v1, v2 = [i for i in range(n)], np.array(c[o:]), np.array(c[:o]) + Binv = np.linalg.inv(A[:, ns[o:]]) + while not np.min(v2 - v1 @ Binv @ A[:, ns[:o]]) > 0: + n1 = np.argmin(v2 - v1 @ Binv @ A[:, ns[:o]]) + t1, t2 = Binv @ b, Binv @ A[:, ns[n1]] + n2 = np.argmin([t1[i] / t2[i] if t2[i] > 0 else np.inf for i in range(m)]) + ns[n1], ns[n2 + o], v1[n2], v2[n1] = ns[n2 + o], ns[n1], v2[n1], v1[n2] + Binv = np.linalg.inv(A[:, ns[o:]]) + return Binv @ b + +if __name__ == "__main__": + main() diff --git a/pdp10/docs/sec5-minimalist-walkthrough.md b/pdp10/docs/sec5-minimalist-walkthrough.md index 814631b..7b4153f 100644 --- a/pdp10/docs/sec5-minimalist-walkthrough.md +++ b/pdp10/docs/sec5-minimalist-walkthrough.md @@ -1,47 +1,47 @@ -assume you've started simh pdp10 and it's listening on 2010 for connections. - -# on raspi side, start kermit - - ./kermit/wermit - C-Kermit>set host localhost 2010 /raw-socket - C-Kermit>c - -# on tops10 side, start kermit - -assume you've created a subfolder [,,decwar] in your home folder [,]. - - .r setsrc - *cp [,,decwar] - *^C - .r kermit - Kermit-10>set file byte-size 36-bit - Kermit-10>server - -ctrl-\c back over to raspi kermit - -# in raspi kermit - - C-Kermit>set transfer mode manual - C-Kermit>set file type binary - C-Kermit>send utexas/*.* - C-Kermit>send compuserve/*.* - C-Kermit>send scripts/COM1.CMD - C-Kermit>send scripts/COM2.CMD - C-Kermit>send scripts/CAN1.CMD - -can leave this connection in this state for further usage and get on tops10 via another connection, but if you like to use just this connection - - C-Kermit>c - Kermit-10>^c^c^c - . - -# on tops10 side - - .compile @com1 - .compile @com2 - .r link - *@can1 - .get decwar - .ssave - -if it's not already there, create p,pn [1,27] using react, then copy DECWAR.EXE, DECWAR.GRP, DECWAR.HLP, DECWAR.NWS to its home folder to 'deploy/install' it. [1,27] is where decwar was deployed for compuserve. for utexas it was logical device name 'gam:', assigned to [5,30]. +assume you've started simh pdp10 and it's listening on 2010 for connections. + +# on raspi side, start kermit + + ./kermit/wermit + C-Kermit>set host localhost 2010 /raw-socket + C-Kermit>c + +# on tops10 side, start kermit + +assume you've created a subfolder [,,decwar] in your home folder [,]. + + .r setsrc + *cp [,,decwar] + *^C + .r kermit + Kermit-10>set file byte-size 36-bit + Kermit-10>server + +ctrl-\c back over to raspi kermit + +# in raspi kermit + + C-Kermit>set transfer mode manual + C-Kermit>set file type binary + C-Kermit>send utexas/*.* + C-Kermit>send compuserve/*.* + C-Kermit>send scripts/COM1.CMD + C-Kermit>send scripts/COM2.CMD + C-Kermit>send scripts/CAN1.CMD + +can leave this connection in this state for further usage and get on tops10 via another connection, but if you like to use just this connection + + C-Kermit>c + Kermit-10>^c^c^c + . + +# on tops10 side + + .compile @com1 + .compile @com2 + .r link + *@can1 + .get decwar + .ssave + +if it's not already there, create p,pn [1,27] using react, then copy DECWAR.EXE, DECWAR.GRP, DECWAR.HLP, DECWAR.NWS to its home folder to 'deploy/install' it. [1,27] is where decwar was deployed for compuserve. for utexas it was logical device name 'gam:', assigned to [5,30].