## My 42s software collection update

Contributions to this software library are always welcome. Please ensure that you post program listings rather than .raw files. They give a reasonable idea of what your program does without having to load them into a DM42 and you can also include comments in your code. Check out the following link for a decoder/encoder: https://technical.swissmicros.com/decoders/dm42/

You can then copy/paste the listing and post it in "code" tags.
richmit
Posts: 25
Joined: Tue Feb 16, 2021 2:51 am

### My 42s software collection update

I have updated my collection of 42s programs.
• Refactored the code to use 10x less RAM. Probably introduced some bugs
• Polynomial roots. Still a couple todo items on this one -- let's call it a beta.
• Find matrix characteristic polynomial
• The previous two allow you to find all the eigenvalues of a matrix
• Minor linear algebra stuff
• Construct identity matrix
• Construct diagonal matrix
• Compute trace
• Repeated measurements tool now supports rank stats (median, etc...)
• Function plotter improvements
• You can now select a range on the graph on which you want to find roots or integrate
• Auto-scale has a neat little progress bar.
• You can now graphically select an x-range, and redraw the graph with auto-scale for the y-axis
• The zoom-box has a slow & fast mode to help make up for no auto-repeat for GETKEY
• It is much faster now in "connect the dots" mode
• Faster standard normal CDF & ERF computation
• Several base-n additions: bit fields, field iteration, etc..
• Better support for Julian dates
• Lots of new Emacs LISP
• Much more sophisticated menu program generation
• Automatic code conversion & clean on tangle
• Copy annotated code and transform it before putting it on the clipboard
• Generate HTML & tangle code for marked files in dired-mode
• I now include raw files in the bin/ directory for all the code
• I also now include un-annotated code listings in the src_42s directory. These can be directly cut-n-pasted into free42
Everything is on github: https://richmit.github.io/hp42/
Kibabalu
Posts: 8
Joined: Sat Apr 03, 2021 2:36 pm

### Re: My 42s software collection update

You extended your repeated measurements tool. Thx for it!
whuyse
Posts: 143
Joined: Thu Dec 21, 2017 1:23 pm

### Re: My 42s software collection update

Very nice documentation!

To create an identity matrix, and a diagonal matrix from a vector without looping or matrix access:

Code: Select all

00 { 49-Byte Prgm }
01▸LBL "IDN"
02 1
03 NEWMAT
04 SIGN
05▸LBL "DIAG"
06 LSTO "."
07 DIM?
08 +
09 ENTER
10 DSE ST X
11 DIM "."
12 X<> "."
13 TRANS
14 X<> "."
15 STO ST Y
16 DIM "."
17 -
18 X<> "."
19 END
Cheers, Werner
42S #3249S01123
DM42 #00345
DM41X #01215
richmit
Posts: 25
Joined: Tue Feb 16, 2021 2:51 am

### Re: My 42s software collection update

whuyse wrote:
Tue Apr 27, 2021 2:16 pm
To create an identity matrix, and a diagonal matrix from a vector without looping or matrix access...
OMG. I just spent the last 10min staring at this little miracle. That's fantastically clever!

What is the - for on line 17?

Can I use this code or is it copyrighted?
whuyse
Posts: 143
Joined: Thu Dec 21, 2017 1:23 pm

### Re: My 42s software collection update

richmit wrote:
Tue Apr 27, 2021 5:58 pm
What is the - for on line 17?
Can I use this code or is it copyrighted?
The ‘-‘ is to drop the stack so that the original y and z are preserved.
Feel free to use it, of course!

Cheers, Werner
42S #3249S01123
DM42 #00345
DM41X #01215
richmit
Posts: 25
Joined: Tue Feb 16, 2021 2:51 am

### Re: My 42s software collection update

whuyse wrote:
Tue Apr 27, 2021 6:19 pm
richmit wrote:
Tue Apr 27, 2021 5:58 pm
What is the - for on line 17?
Can I use this code or is it copyrighted?
The ‘-‘ is to drop the stack so that the original y and z are preserved.
Feel free to use it, of course!
Thank you!

Now that I have FUNC, I don't think as much about the stack anymore.

BTW, a similar trick allows us to compute the trace of a matrix as well:

Code: Select all

LBL "MATTR"
FUNC 11     @@## REQ:free42>=2.5.24
L4STK       @@## REQ:free42>=3.0
LSTO "_M"
DIM?        @@@@ n n
1
+           @@@@ n+1 n
DIM "_M"    @@@@ n+1 n      -- _M is now nx(n+1) and old diag in first column
1           @@@@ 1   n+1
1           @@@@ 1   1 n+1
NEWMAT      @@@@ P   n+1
SIGN        @@@@ P   n+1    -- P is a 1x1 constant 1 matrix
LSTO "_P"   @@@@ P   n+1
Rv          @@@@ n+1   n
1           @@@@ 1     n+1
X<>Y        @@@@ n+1   1
DIM "_P"    @@@@ n+1   1    -- P is now 1x(n+1) e_1 matrix
RCL "_P"    @@@@ _P
RCL "_M"    @@@@ _M    _P
TRANS       @@@@ X     _P   -- X is (n+1)xn matrix with diag elements in first row
×           @@@@ X          -- X is now a 1xn row vector of the diag elements
RSUM        @@@@ X          -- X is now 1x1 matrix with sum of diag elements
DET         @@@@ TR         -- Det of 1x1 is the matrix element
RTN

whuyse
Posts: 143
Joined: Thu Dec 21, 2017 1:23 pm

### Re: My 42s software collection update

Why not, after DIM "_M": (to n x n+1)

Code: Select all

 RCL "_M"
TRANS
STO "_M" @ diag is now first row
1
R^ @ we are in 4STK mode ;-)
DIM "_M"
RSUM
Cheers, Werner
Last edited by whuyse on Tue May 11, 2021 8:20 am, edited 1 time in total.
42S #3249S01123
DM42 #00345
DM41X #01215
richmit
Posts: 25
Joined: Tue Feb 16, 2021 2:51 am

### Re: My 42s software collection update

whuyse wrote:
Wed Apr 28, 2021 9:05 am
Why not, after DIM "_M": (to n x n+1)
This is something I need to work on in general. I grew up on the 48 series, and the 4 level stack is still a little weird to me.

That said, I'm finding free42 programming to be a lot of fun!