September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
18
Task/Matrix-arithmetic/Jq/matrix-arithmetic-1.jq
Normal file
18
Task/Matrix-arithmetic/Jq/matrix-arithmetic-1.jq
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Eliminate row i and row j
|
||||
def except(i;j):
|
||||
reduce del(.[i])[] as $row ([]; . + [$row | del(.[j]) ] );
|
||||
|
||||
def det:
|
||||
def parity(i): if i % 2 == 0 then 1 else -1 end;
|
||||
if length == 1 and (.[0] | length) == 1 then .[0][0]
|
||||
else . as $m
|
||||
| reduce range(0; length) as $i
|
||||
(0; . + parity($i) * $m[0][$i] * ( $m | except(0;$i) | det) )
|
||||
end ;
|
||||
|
||||
def perm:
|
||||
if length == 1 and (.[0] | length) == 1 then .[0][0]
|
||||
else . as $m
|
||||
| reduce range(0; length) as $i
|
||||
(0; . + $m[0][$i] * ( $m | except(0;$i) | perm) )
|
||||
end ;
|
||||
22
Task/Matrix-arithmetic/Jq/matrix-arithmetic-2.jq
Normal file
22
Task/Matrix-arithmetic/Jq/matrix-arithmetic-2.jq
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
def matrices:
|
||||
[ [1, 2],
|
||||
[3, 4]],
|
||||
|
||||
[ [-2, 2, -3],
|
||||
[-1, 1, 3],
|
||||
[ 2, 0, -1]],
|
||||
|
||||
[ [ 1, 2, 3, 4],
|
||||
[ 4, 5, 6, 7],
|
||||
[ 7, 8, 9, 10],
|
||||
[10, 11, 12, 13]],
|
||||
|
||||
[ [ 0, 1, 2, 3, 4],
|
||||
[ 5, 6, 7, 8, 9],
|
||||
[10, 11, 12, 13, 14],
|
||||
[15, 16, 17, 18, 19],
|
||||
[20, 21, 22, 23, 24]]
|
||||
;
|
||||
|
||||
"Determinants: ", (matrices | det),
|
||||
"Permanents: ", (matrices | perm)
|
||||
11
Task/Matrix-arithmetic/Jq/matrix-arithmetic-3.jq
Normal file
11
Task/Matrix-arithmetic/Jq/matrix-arithmetic-3.jq
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
$ jq -n -r -f Matrix_arithmetic.jq
|
||||
Determinants:
|
||||
-2
|
||||
18
|
||||
0
|
||||
0
|
||||
Permanents:
|
||||
10
|
||||
10
|
||||
29556
|
||||
6778800
|
||||
8
Task/Matrix-arithmetic/Jq/matrix-arithmetic-4.jq
Normal file
8
Task/Matrix-arithmetic/Jq/matrix-arithmetic-4.jq
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# Requires lup/0
|
||||
def det:
|
||||
def product_diagonal:
|
||||
. as $m | reduce range(0;length) as $i (1; . * $m[$i][$i]);
|
||||
def tidy: if . == -0 then 0 else . end;
|
||||
lup
|
||||
| (.[0]|product_diagonal) as $l
|
||||
| if $l == 0 then 0 else $l * (.[1]|product_diagonal) | tidy end ;
|
||||
1
Task/Matrix-arithmetic/Jq/matrix-arithmetic-5.jq
Normal file
1
Task/Matrix-arithmetic/Jq/matrix-arithmetic-5.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
matrices | det
|
||||
Loading…
Add table
Add a link
Reference in a new issue