[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-apl] Matrix Permanents: Episode 1
From: |
Mike Duvos |
Subject: |
[Bug-apl] Matrix Permanents: Episode 1 |
Date: |
Tue, 25 Aug 2015 20:14:57 -0700 |
Here's a simple little recursive function to compute matrix permanents.
∇
[0] Z←PERM X;⎕IO;N
[1] Z←1 ⋄ ⎕IO←0
[2] →(0=⍴N←⍳↑⍴X)/0
[3] Z←+/X[0;]×PERM¨N {⍵[N~0;N~⍺]}¨⊂X
∇
⎕←A←10 10⍴11↑1
1 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 1
PERM A
[I get tired of waiting, and hit ATTENTION]
^CATTENTION
PERM[1] ⎕IO←0
^
)si
PERM[1]
PERM[3]
PERM[3]
PERM[3]
PERM[3]
PERM[3]
PERM[3]
PERM[3]
PERM[3]
PERM[3]
PERM[3]
⋆
⋆
)reset
VALUE ERROR
PERM[1] ⎕IO←0
^
)reset
VALUE ERROR
PERM[3] Z←+/X[0;]×PERM¨N λ1¨⊂X
^
→
VALUE ERROR
PERM[3] Z←+/X[0;]×PERM¨N λ1¨⊂X
^
[Isn't reset supposed to clear the whole state indicator, and not just pop one function call at a time off it?]
)load perm
VALUE ERROR
PERM[3] Z←+/X[0;]×PERM¨N λ1¨⊂X
^
[I don't understand this at all]
)clear
VALUE ERROR
PERM[3] Z←+/X[0;]×PERM¨N λ1¨⊂X
^
[nor this]
→
VALUE ERROR
PERM[3] Z←+/X[0;]×PERM¨N λ1¨⊂X
^
→
VALUE ERROR
PERM[3] Z←+/X[0;]×PERM¨N λ1¨⊂X
^
→
VALUE ERROR
PERM[3] Z←+/X[0;]×PERM¨N λ1¨⊂X
^
→
VALUE ERROR
PERM[3] Z←+/X[0;]×PERM¨N λ1¨⊂X
^
)si
PERM[3]
PERM[3]
PERM[3]
⋆
⋆
[almost there]
)reset
VALUE ERROR
PERM[3] Z←+/X[0;]×PERM¨N λ1¨⊂X
^
)reset
)si
[finally]
PERM 3 3⍴⍳9
ATTENTION
PERM[1] ⎕IO←0
^
[I didn't hit attention this time. It apparently remembered the last attention.]
PERM 3 3⍴1 2 3 4 5 6 7 8 9
450
[Which is the correct answer, on a smaller matrix that takes less time.]
- [Bug-apl] Matrix Permanents: Episode 1,
Mike Duvos <=