Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,24 @@
|
|||
# produce an array of length n that is 1 at i and 0 elsewhere
|
||||
def indicator(i;n): [range(0;n) | 0] | .[i] = 1;
|
||||
|
||||
# Identity matrix:
|
||||
def identity(n): reduce range(0;n) as $i ([]; . + [indicator( $i; n )] );
|
||||
|
||||
def direct_matrix_exp(n):
|
||||
. as $in
|
||||
| if n == 0 then identity($in|length)
|
||||
else reduce range(1;n) as $i ($in; . as $m | multiply($m; $in))
|
||||
end;
|
||||
|
||||
def matrix_exp(n):
|
||||
if n < 4 then direct_matrix_exp(n)
|
||||
else . as $in
|
||||
| ((n|2)|floor) as $m
|
||||
| matrix_exp($m) as $ans
|
||||
| multiply($ans;$ans) as $ans
|
||||
| (n - (2 * $m) ) as $residue
|
||||
| if $residue == 0 then $ans
|
||||
else matrix_exp($residue) as $residue
|
||||
| multiply($ans; $residue )
|
||||
end
|
||||
end;
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
def pi: 4 * (1|atan);
|
||||
|
||||
def rotation_matrix(theta):
|
||||
[[(theta|cos), (theta|sin)], [-(theta|sin), (theta|cos)]];
|
||||
|
||||
def demo_matrix_exp(n):
|
||||
rotation_matrix( pi / 4 ) | matrix_exp(n) ;
|
||||
|
||||
def demo_direct_matrix_exp(n):
|
||||
rotation_matrix( pi / 4 ) | direct_matrix_exp(n) ;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
# For demo_matrix_exp(10000)
|
||||
$ time jq -n -c -f Matrix-exponentiation_operator.rc
|
||||
[[1,-1.1102230246251565e-12],[1.1102230246251565e-12,1]]
|
||||
user 0m0.490s
|
||||
sys 0m0.008s
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
# For demo_direct_matrix_exp(10000)
|
||||
$ time jq -n -c -f Matrix-exponentiation_operator.rc
|
||||
[[1,-7.849831895612169e-13],[7.849831895612169e-13,1]]
|
||||
user 0m0.625s
|
||||
sys 0m0.006s
|
||||
Loading…
Add table
Add a link
Reference in a new issue