September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View 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 ;

View 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)

View file

@ -0,0 +1,11 @@
$ jq -n -r -f Matrix_arithmetic.jq
Determinants:
-2
18
0
0
Permanents:
10
10
29556
6778800

View 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 ;

View file

@ -0,0 +1 @@
matrices | det