Essays/Identity Matrix
From J Wiki
< Essays
Generate the identity matrix of order n , n>0 .
Contents
- 1 Self-Classify
- 2 Raze-In
- 3 Outer Product
- 4 Reshape
- 5 Rotate
- 6 Shift
- 7 Copy
- 8 Take
- 9 Drop
- 10 Prefix
- 11 Suffix
- 12 Infix
- 13 Outfix
- 14 Oblique
- 15 Prepend
- 16 Amend
- 17 Membership
- 18 Cut
- 19 Indices of Ravel
- 20 Row and Column Indices
- 21 Transpose
- 22 Binary Representation
- 23 Anagram
- 24 Cycle
- 25 Vector Calculus
- 26 Polynomial
- 27 Matrix Multiplication
- 28 Random Matrix
- 29 Recursion
- 30 Interval Member
- 31 Power Take
- 32 Double Antibase
- 33 Function Table Diagonal
- 34 Primes and Factoring
Self-Classify
The self-classification of an array with all distinct items is the identity matrix. Thus:
I0a=: =@i. I0b=: =@?~
Raze-In
I1=: e.@i.
Outer Product
I2a=: =/~@i. I2b=: ="1 0~@i. I2c=: (<: *. >:)"0/~ @ i. I2d=: (<:/ *. >:/)~ @ i.
Reshape
I3a=: ,~ $ >: {. 1: I3b=: ,~ $ 1 , $&0 I3c=: ($&0 , 1:)"0@i.
Rotate
I4a=: -@i. |."0 1 {.&1 I4b=: _1&|.^:(i.@#) @ ({.&1)
Shift
I4c=: |.!.0^:(<`({.&1))
Copy
I5a=: 0 1 0 #"1~ i. ,. 1 ,. i.@- I5b=: 0 1 #"1~ i. ,. 1:
Take
I6=: -@>:@i. {."0 1:
Drop
I7=: i.@- }."0 1 {.&1@-
Prefix
I8a=: |.\ @ ({.&1) I8b=: |.@~:\ @ ($&0) I8c=: (={:)\ @ i.
Suffix
I9=: ]\.&.|. @ ({.&1)
Infix
I10=: - ]\ *: $ 1 , $&0
Outfix
I11=: 3 : '-. 1 (i.y)&e.\. i.y'
Oblique
I12=: {. |./.@(#"0 {.&1)
Prepend
I13=: 0&,^:(i.`1:)
Amend
I14a=: 3 : '1 (,&.>~ i.y)} (,~y) $ 0' I14b=: 1 (<0 1)&|:@i.@$@]} ,~ $ 0: I14c=: 1 (>: * i.)@#@]} ,~ $ 0:
Membership
I15=: i.@,~ e. >: * i.
Cut
I16=: [: |.;.1 i.@(2&!)@>: e. 2&!@>:@i.
Indices of Ravel
I17a=: 0 = >: | i.@,~ I17b=: i.@,~ = >: * i.
Row and Column Indices
I18a=: =/&> @ { @ (;~) @ i. I18b=: =/"1@(#:i.)@,~
Transpose
I19a=: (=|:) @ i. @ ,~ I19b=: (=|:) @ (-/~) @ i.
Binary Representation
I20a=: #: @ (2&^) @ i. @ - I20b=: [: #: +:^:(i.@-`1:)
Anagram
I21=: |.!.''@:(+/\)@:!@:i.@:- A. {.&1
Cycle
I22=: ~.@(0&,)&.>@i. C."0 1 {.&1
Vector Calculus
I23=: ]D.1@i.
Polynomial
I24=: p.@($&0&.>)@i.
Matrix Multiplication
The identity matrix is the neutral for matrix multiplication.
I25=: +/ .*/ @ i. @ (0&,)
Random Matrix
The probability of the adverse being invoked is very small and decreases with increasing matrix size.
I26=: (+/ .* %.)@(,~ ?@$ 2147483647x"_) :: $:
Recursion
I27=: 3 : 0 if. 1=y do. 1 1$1 else. (,~y) {. ((,. , ,.~) 0*]) I27 >.-:y end. )
Interval Member
I28=: E."0 1~@i.
Power Take
I29=: ({.~ -@>:@#)^:(<`1:)
Double Antibase
I30=: +:&.#.&.|. ^: (<`1:)
Function Table Diagonal
I32a=: (1 = =/~)@i. NB. 1 Equal I32b=: (0 = ~:/~)@i. NB. 0 Not equal I32c=: (+: = +/~)@i. NB. Double Addition I32d=: (0 = -/~)@i. NB. 0 Subtraction I32e=: (*: = */~)@i. NB. Square Multiplication I32f=: (1 = %/~)@i. NB. 1 Division I32g=: (1 = !/~)@i. NB. 1 Out Of I32h=: (j.~ = j./~)@i.
Primes and Factoring
I33=: _&q: @ p: @ i.