Post Reply 
(HP71B) integer determinant
02-16-2024, 10:36 PM (This post was last modified: 02-18-2024 10:34 PM by Albert Chan.)
Post: #1
(HP71B) integer determinant
Inspired from [VA] SRC #014 - HP-15C & clones: Accurate NxN Determinants
And, tested with examples from thread.

HP71B Code translated from @pycoder's Python code
see https://en.wikipedia.org/wiki/Bareiss_algorithm

10 DESTROY ALL @ OPTION BASE 1 @ INPUT "N? ";N
20 DIM M(N,N) @ MAT INPUT M @ S=1 @ P=1
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 @ P=M(I,I)
110 FOR J=I+1 TO N @ FOR K=I+1 TO N
120 X=P*M(J,K)-M(J,I)*M(I,K) @ M(J,K)=IROUND(X/P0)
130 NEXT K @ NEXT J @ NEXT I
140 DISP "DET =";S*M(N,N)

>run
N? 3
M(1,1)? 0,3,4
M(2,1)? 3,1,4
M(3,1)? 1,1,2
DET = 2
>run
N? 3
M(1,1)? 29,18,9
M(2,1)? 32,-28,-22
M(3,1)? 18,25,15
DET =-262
>run
N? 4
M(1,1)? -19,41,22,7
M(2,1)? 5,19,-14,0
M(3,1)? -36,16,9,26
M(4,1)? 42,-38,14,-38
DET =-2384
>run
N? 7
M(1,1)? 58,71,67,36,35,19,60
M(2,1)? 50,71,71,56,45,20,52
M(3,1)? 64,40,84,50,51,43,69
M(4,1)? 31,28,41,54,31,18,33
M(5,1)? 45,23,46,38,50,43,50
M(6,1)? 41,10,28,17,33,41,46
M(7,1)? 66,72,71,38,40,27,69
DET = 1
>run
N? 7
M(1,1)? 13,72,57,94,90,92,35
M(2,1)? 40,93,90,99,01,95,66
M(3,1)? 48,91,71,48,93,32,67
M(4,1)? 07,93,29,02,24,24,07
M(5,1)? 41,84,44,40,82,27,49
M(6,1)? 03,72,06,33,97,34,04
M(7,1)? 43,82,66,43,83,29,61
DET = 1
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



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