Post Reply 
(HP71B) integer determinant
02-21-2024, 01:31 PM
Post: #7
RE: (HP71B) integer determinant
(02-21-2024 08:23 AM)J-F Garnier Wrote:  The examples I posted in Valentin's thread are failing with the 71B implementation of the Bareiss' algorithm, but are correct processed with this Bird's implementation.

Thanks for HP71B Bird's implementation! It work!

For fair comparison, I replace dot product using built-in DOT, for extra internal precisions.
First, row/column order is swapped (order does not matter, just more efficient the other way)

< 120 X=P*M(J,K)-M(J,I)*M(I,K) @ M(J,K)=IROUND(X/P0)
> 120 X=P*M(K,J)-M(K,I)*M(I,J) @ M(K,J)=IROUND(X/P0)

--> X = [M(I,I), -M(I,J)] • [M(K,J), M(K,I)] = P • Q

10 DESTROY ALL @ OPTION BASE 1 @ INPUT "N? ";N
20 DIM M(N,N),P(2),Q(2) @ MAT INPUT M @ S=1 @ P(1)=1
25 DISP "BUILT-IN DET =";DET(M)
30 FOR I=1 TO N-1 @ IF M(I,I) THEN 100
40 FOR J=I+1 TO N @ IF M(J,I) THEN 60
50 NEXT J @ S=0 @ GOTO 140 ! no pivot
60 FOR K=1 TO N @ VARSWAP M(I,K),M(J,K) @ NEXT K @ S=-S
100 P0=P(1) @ P(1)=M(I,I)
110 FOR J=I+1 TO N @ P(2)=-M(I,J)
115 FOR K=I+1 TO N @ Q(1)=M(K,J) @ Q(2)=M(K,I)
120 X=DOT(P,Q) @ M(K,J)=IROUND(X/P0)
130 NEXT K @ NEXT J @ NEXT I
140 DISP "BAREISS DET =";S*M(N,N)

Both of your examples now calculated correctly.

>run
N? 7
M(1,1)? 274,213,400,322,341,308,446
M(2,1)? 202,210,383,295,360,295,450
M(3,1)? 154,175,332,175,322,361,413
M(4,1)? 176,147,265,272,328,277,351
M(5,1)? 111,131,249,182,324,296,340
M(6,1)? 155,179,329,218,381,399,444
M(7,1)? 147,127,229,174,245,258,297
BUILT-IN DET =-11.4070209786
BAREISS DET = 1

>run
N? 7
M(1,1)? 477,389,402,515,358,409,289
M(2,1)? 302,273,282,322,280,283,205
M(3,1)? 278,231,339,319,343,254,214
M(4,1)? 432,360,406,502,391,359,319
M(5,1)? 475,316,509,649,543,393,288
M(6,1)? 299,304,351,369,459,346,221
M(7,1)? 526,561,442,441,371,491,445
BUILT-IN DET =-54.0791415377
BAREISS DET = 1

OP version actually not too bad, getting DET of 3 for 1st, -1 for 2nd
We could calculate DET(M MOD 10) MOD 10, to correct for this. (this is a nice check anyway)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(HP71B) integer determinant - Albert Chan - 02-16-2024, 10:36 PM
RE: (HP71B) integer determinant - robve - 02-18-2024, 03:05 PM
RE: (HP71B) integer determinant - Albert Chan - 02-21-2024 01:31 PM



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