Post Reply 
(42S) matrix permanent
01-15-2024, 02:45 PM (This post was last modified: 01-16-2024 04:54 PM by Werner.)
Post: #3
RE: (42S) matrix permanent
Hi, Albert!
The SQRT is a quick way to turn a 4 into a 2 ;-)

The only part, I think, that requires some explanation is lines 23-51.
There, I determine j and dj (+/-2) from k, as John Keith explained.

So, j is the place of the least significant bit in k.
Let >>k be k shifted right till the least significant bit is 1,
then dj=2 if >>k MOD 4 equals 3, else dj=-2 (I *add* dj*Mj, so my signs are swapped).
I also technically calculate the permanent of the transposed matrix, which is of course the same - to save a TRANS(M) which on a 42S will duplicate the matrix. I subsequently fetch the j-th *column* of M instead of the row.

Instead of trying to find the least significant bit of k, successively dividing by 2, I perform k MOD 4 right away, and use GTO IND ST X to branch off:
- half of the time, it is either 1 or 3 and we're done (j=1 and dj=-2 for 1 and 2 for 3).
- if it is 0, divide k by 4, add 2 to j and loop
- if it is 2, add 1 to j, and k MOD 8 is now 2 or 6, and dj -2 or 2, respectively

I had a version using v,f and d vectors (even one using only the stack), but this latest version runs almost twice as fast, also because I store the vector v in REGS, so that I don't need to switch indexing/editing matrices, and the calculation of product(v) is faster.

Cheers, Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(42S) matrix permanent - Werner - 01-15-2024, 12:33 PM
RE: (42S) matrix permanent - Albert Chan - 01-15-2024, 02:24 PM
RE: (42S) matrix permanent - Werner - 01-15-2024 02:45 PM
RE: (42S) matrix permanent - Albert Chan - 01-15-2024, 04:06 PM
RE: (42S) matrix permanent - Werner - 01-15-2024, 04:22 PM
RE: (42S) matrix permanent - Albert Chan - 01-16-2024, 01:00 AM
RE: (42S) matrix permanent - Werner - 01-16-2024, 08:47 AM
RE: (42S) matrix permanent - Albert Chan - 01-16-2024, 12:24 PM
RE: (42S) matrix permanent - John Keith - 01-17-2024, 08:17 PM
RE: (42S) matrix permanent - John Keith - 01-26-2024, 10:28 PM



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