Post Reply 
[VA] SRC #012a - Then and Now: Probability
10-18-2022, 11:16 AM
Post: #70
RE: [VA] SRC #012a - Then and Now: Probability
(10-18-2022 08:00 AM)J-F Garnier Wrote:  
(10-17-2022 08:16 PM)Albert Chan Wrote:  Here is a version that simulate swapping of array name.
Array P of x ≡ A(P, x)
Array Q of x ≡ A(Q, X)
Note: P, Q are now numbers 0 or 1, P+Q=1, not the array itself.
[..]

20 OPTION BASE 0 @ REAL A(1,(R+1)*(R+4)/2) @ P=0
I don't see the benefit of this version, you are still using the same amount of memory, and the access to the array A is slower which is not compensated by the gain of the MAT copy.

That's why it is called simulate swapping of array name.
True variable name swapping should be almost cost free.

It is a proof of concept, showing MAT Q=P is not needed.
The code is useful for machine that use slow FOR-NEXT for MAT copy.
Simulated array name swapping removed the slow FOR-NEXT loops.

Perhaps add MAT SWAP to HP Article VA044 - HP-71B Math Pac 2 Comments and Proposals.pdf ?



Flattened A array of 1 dimension, array access cost almost matched removal of MAT COPY
However, for optimized code, it may be hard to deduce where A is pointing to.
That's why I posted the slower A(P, x) version, instead of faster A(P + x)

Anyway, this was my flattened A version.

Note: we reduced array elements required by 1, but still safe.
Note: Build Q part, to simplify code, T is triangular number minus one, plus Q

10 DESTROY ALL @ INPUT "[VA]SRC012A R,S= ";R,S @ SETTIME 0
20 OPTION BASE 0 @ P=0 @ Q=(R+1)*(R+4)/2 @ REAL A(2*Q)
30 A(2)=1 @ M=2
40 FOR K=1 TO S
50 VARSWAP P,Q @ T=Q+2 @ A(T)=A(T)*3 ! BUILD Q
60 FOR I=1 TO M-(M=R)-1 @ T=T+2 @ A(T)=A(T)*1.5 @ T=T+I @ A(T)=A(T)*1.5 @ NEXT I
70 IF M<>R THEN 100
80 FOR X=T+3 TO T+R @ A(X)=A(X)*1.5 @ NEXT X
90 T=T+2 @ A(T)=A(T)*3 @ A(X)=A(X)*3
100 T=Q+1 @ Y=P-Q @ FOR I=1 TO M @ FOR X=T+1 TO T+I ! BUILD P
110 A(X+Y)=A(X-I-1)+A(X-I)+A(X-1)+A(X+1)+A(X+I+1)+A(X+I+2)
120 NEXT X @ T=X @ NEXT I
130 M=M+(M<R)
140 DISP K;TIME
150 NEXT K
160 T=0 @ K=P+R*(R+1)/2 @ FOR X=K+1 TO K+R @ T=T+A(X) @ NEXT X
170 DISP TIME;R;S;T/6^S


>RUN
[VA]SRC012A R,S= 30,60
...
84.49      30 60      9.51234350205E-6

Very close to fastest MAT Q=P version, clocked at 83.1 sec.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] SRC #012a - Then and Now: Probability - Albert Chan - 10-18-2022 11:16 AM



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