Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,53 @@
|
|||
PROGRAM MAT_PROD
|
||||
|
||||
!$MATRIX
|
||||
|
||||
!-----------------
|
||||
! calculate A[]^N
|
||||
!-----------------
|
||||
|
||||
CONST ORDER=1
|
||||
|
||||
DIM A[1,1],B[1,1],ANS[1,1]
|
||||
|
||||
BEGIN
|
||||
|
||||
DATA(3,2,2,1)
|
||||
DATA(10) ! integer power only
|
||||
|
||||
FOR I=0 TO ORDER DO
|
||||
FOR J=0 TO ORDER DO
|
||||
READ(A[I,J])
|
||||
END FOR
|
||||
END FOR
|
||||
|
||||
READ(M) N=M-1
|
||||
|
||||
IF N=0 THEN ! A[]^0=matrice identit…
|
||||
for I=0 TO ORDER DO
|
||||
B[I,I]=1
|
||||
END FOR
|
||||
ELSE
|
||||
B[]=A[]
|
||||
FOR Z=1 TO N DO
|
||||
ANS[]=0
|
||||
FOR I=0 TO ORDER DO
|
||||
FOR J=0 TO ORDER DO
|
||||
FOR K=0 TO ORDER DO
|
||||
ANS[I,J]=ANS[I,J]+(A[I,K]*B[K,J])
|
||||
END FOR
|
||||
END FOR
|
||||
END FOR
|
||||
B[]=ANS[]
|
||||
END FOR
|
||||
END IF
|
||||
|
||||
! print answer
|
||||
FOR I=0 TO ORDER DO
|
||||
FOR J=0 TO ORDER DO
|
||||
PRINT(B[I,J],)
|
||||
END FOR
|
||||
PRINT
|
||||
END FOR
|
||||
|
||||
END PROGRAM
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
(1) -> A:=matrix [[0,-%i],[%i,0]]
|
||||
|
||||
+0 - %i+
|
||||
(1) | |
|
||||
+%i 0 +
|
||||
Type: Matrix(Complex(Integer))
|
||||
(2) -> A^4
|
||||
|
||||
+1 0+
|
||||
(2) | |
|
||||
+0 1+
|
||||
Type: Matrix(Complex(Integer))
|
||||
(3) -> A^(-1)
|
||||
|
||||
+0 - %i+
|
||||
(3) | |
|
||||
+%i 0 +
|
||||
Type: Matrix(Fraction(Complex(Integer)))
|
||||
(4) -> inverse A
|
||||
|
||||
+0 - %i+
|
||||
(4) | |
|
||||
+%i 0 +
|
||||
Type: Union(Matrix(Fraction(Complex(Integer))),...)
|
||||
|
|
@ -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