Post Reply 
Happy New Year 2024 ... and 2023's last teaser !
01-02-2024, 10:53 AM (This post was last modified: 01-04-2024 09:47 AM by ramon_ea1gth.)
Post: #16
RE: Happy New Year 2024 ... and 2023's last teaser !
I'm having fun with the challenge. After programming a cute RPL recursive program in my HP 50g to manage matrices/permanents and realise, as said in other posts, that the required calculations grow insanely, now I'll try the binary way, base-2 approach, with shifting registers, but with the usual base-10 numbers. Let's see Smile

Edit:
I'm testing this binary shifting approach to obtain the cofactors. A 5x5 matrix full of ones takes about 25 seconds to compute in my HP 50g. With zeroes, the code saves operations. Thus, I will let the calculator work overnigth and let's see if I get something in the morning (I started a TICKS command so I can measure the elapsed time). I know, I know: if I were serious I should have tried to make an estimation of the required time for the algorithm Smile

Edit 2:
I got it! (after about 11 hours computing!). At least, after such a long calculation, the result is the expected Smile I'll write my code later here, just as a curiosity, though it's not the most efficient solution.

Edit 3:
And this is my version of PERMANT. It takes two arguments from the stack:
  • Level 2: a list with the matrix rows, considered as binary words, translated to base-10 reals.
  • Level 1: the number of rows, i.e., 12.
Thus, the contents of the stack must be:
Code:

2: {3007, 773, 2839, 516, 3071, 775, 2967, 1533, 2823, 4095, 517, 2999}
1: 12
And the code of PERMANT:
Code:

« 0 0 0 → vec rows n a per   @ get from stack the list (vec) and nr of rows. Init n, a, per
  « vec 2 / 'vec' STO         @ binary shift right and store (fractional part included)
    rows 1 FOR n              @ go from last row to first
     vec n GET FP 2 * 'a' STO @ matrix element: get the LSB as the fractional part of row n times 2
     IF rows 1 ≠ a AND THEN   @ if rows larger than 1 and matrix element 'a' is nonzero
      vec OBJ→ 1 + n - ROLL DROP rows 1 - →LIST @ remove row n from vec
      IP rows 1 - PERMANT     @ get the integer part (like remove column) and recall PERMANT
      a * 'per' STO+          @ returned cofactor from PERMANT times 'a', and add to cumulative 'per'
     ELSE a 'per' STO+        @ just add 'a' to cumulative 'per'
     END
    -1 STEP                   @ decrease n and next iteration
    per                       @ return the obtained permanent
 »
»
Edit 4:
And the previous code even more optimised for binary matrices:
Code:

« 0 0 → vec rows n per
  « vec 2 / 'vec' STO
    rows 1 FOR n
     IF vec n GET FP THEN
      IF rows 1 ≠ THEN
      vec OBJ→ 1 + n - ROLL DROP rows 1 - →LIST
      IP rows 1 - PERMANT
      ELSE 1
      END
      'per' STO+
     END
    -1 STEP
    per
 »
»
Edit 5:
With the optimised code, computing time is 9 hours in a physical HP 50g, instead of the previous 11 hours.

Ramón
Valladolid, Spain
TI-50, Casio fx-180P, HP48GX, HP50g, HP Prime G2
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Happy New Year 2024 ... and 2023's last teaser ! - ramon_ea1gth - 01-02-2024 10:53 AM



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