Post Reply 
[VA] SRC#003- New Year 2019 Special
01-17-2019, 06:04 PM
Post: #7
RE: [VA] SRC#003- New Year 2019 Special
Not being well-versed in the mathematics behind this, my attempt was simply a naïve/brute force loop to compare successive results until the first duplicate was encountered (50g/RPL):
Code:











\<<
   [['\pi' 2019. 2019.][1. '\pi' 2019.][1. 1. '\pi']] \->NUM
   DUP
   0.
   DO
      UNROT
      OVER *
      DUP 3. GET
      OVER 6. GET
      /
      4. ROLL
   UNTIL
      OVER SAME
   END
   NIP NIP
\>>
Result: 12.6389823194
Execution time: about 12s on a real 50g.
Size: 146.5 bytes, of which 84 bytes is spent building the initial matrix. If I take that part out and require the initial matrix being left on the stack as an argument, the size drops to 62.5 bytes.

A similar approach using Thomas' first optimization:
Code:











\<<
   [['\pi' 2019. 2019.][1. '\pi' 2019.][1. 1. '\pi']] \->NUM
   0. DUP 1. \->V3
   0.
   DO
      UNROT
      OVER SWAP *
      DUP OBJ\-> DROP2
      /
      4. ROLL
   UNTIL
      OVER SAME
   END
   NIP NIP
\>>
Result: 12.6389823194
Execution time: about 8.5s on a real 50g
Size: 149 bytes (with embedded matrix build), 65 bytes (initial matrix as argument)

All of which pales in comparison, of course, to Thomas' ultimate eigenvalue solution. If I assume the initial matrix is on the stack as an argument, the following code gives the result in the same format as the other routines (I optimized the retrieval of the needed matrix element as well as adding "RE" to standardize the result):
Code:
\<<
   EGV DROP 4. GET INV RE
\>>
Result: 12.6389823194
Execution time: about 3.8s on a real 50g
Size: 28 bytes

Great job Thomas! (as usual). And thanks to Valentin for an interesting problem -- I hope to see more about the underlying concepts. I think this is the first time I've actually encountered eigenvalues being used outside of a Linear Algebra course many moons ago. I've forgotten most everything I was supposed to have learned in that class, I'm afraid.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] SRC#003- New Year 2019 Special - DavidM - 01-17-2019 06:04 PM



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