You are on page 1of 2

Arithmetic Dyads

2 + 8
Plus
2 - 8
Minus
2 * 8
Times
2 % 8
Divide
2 | 8
Residue
2 ^ 8
Exponent
2 ^. 8
Log
3 %: 8
Root
2 >. 6
Greater
2 <. 6
Lesser
36 +. 24
GCD
36 *. 24
LCM
10 10 #. 8 3 Base
10 10 #: 83 Antibase
2 ! 8
CombOutOf
2 ? 8
Deal

10
_6
16
0.25
0
256
3
2
6
2
12
72
83
8 3
28
4 2

J Reference Card for version 6.01


Arithmetic Monads
<. 4.5
Floor
>. 4.5
Ceiling
* _4 0 3 Sign
! 4
Factorial
? 20
Random in i. y
? 0
Random in (0,1)

4
5
_1 0 1
24
7
0.452

Legend
x y args to verbs
m n nouns
u v verbs
italics optional

if f is [: result
its output
g
is omitted
( f
h )
x

Fork

result
( f
g )
x Hook

Assignments
AssignInd: value of n
gives name(s) to assign
'n1 n2' =. v1;v2 AssignMult: one level
of boxing is removed
'`add sub' =. +`- AssignAR
(n) =. v

Comparisons (result 1 if TRUE)


= Equal
> Greater
>: GreaterOrEqual
abcd
~: NotEqual
< Less
<: LessOrEqual
efgh
Match (rank _ _): equal in shape, boxing, and values;
-:
ijkl
but if empty, type does not matter
A is mnop
Selections
WindowedMatch
're' E.'reread'
1 0 1 0 0 0
1 0 2 # 'abc' Copy
acc
(ranks may be > 1)
1j1 0 2 # 'abc' CopyFill
a cc
Comparisons are tolerant; follow by !.0 for exact comparison
1j1 0 2 #!.'*' 'abc' CopyCustom
a*cc
Searches
Shorthands
1 0 1&#^:_1 'ab' Expand
a b
1
'people' i. 'pow'
0 2 6
IndexOf
<: 5
y-1 Decrement 4
1 0 1&#^:_1!.'*' 'ab' ExpandCustom a*b
'people' i: 'pow'
3 2 6
IndexOfLast1
>: 5
y+1 Increment
6
mnop
'pow' e. 'people'
1 1 0
ElementOf1
% 5
1%y Reciprocal 0.2
_1 1 { A ItemsFrom
efgh
Monad
I. 0 1 1 0 1
1 2 4
IndicesOfOnes
-. 0.3
1-y Complement 0.7
i. & i:
0 2 4 I. 2 3 _1 9
FindInsertionPoint12 1 2 0 3
bd
+: 9
y*2 Double
18
i. 3
(i. >./) 1 2 8 5
2
IndexOfLargest34
fh
-: 9
y%2 Halve
4.5
1 3 {"1 A FromEachRow
0 1 2
3 (= i. 1:) 1 3 3 0 FindFirstTrue456
1
jl
*: 9
y^2 Square
81
i. _3
3 ([: I. =) 1 3 3 0 IndicesWhereTrue67 1 2
np
%:
2%y SquareRoot 3
2 1 0
FastSearch (when used repeatedly)
^ 1
2.718 m&i. e.&n m&i:
e^y Exp
From
(All
axes
1
2 1 { A
j
i. 2 3
rank searched for is rank of items of other operand 2 min index
^. 7.389 e^.y NaturalLog 2
scalar)
3
4
5
0
1
2
before
which
item
can
be
inserted
in
order
or
<.
or
i:
or
0:
#. 1 0 1 2#.y FromBase2 5
From (Omitted efgh
6
3 4 5
1 3 { A
#: 5
2#:y ToBase2*
1 0 1 any comp. or e.
Operations on Ordered Sets
mnop
trailing axis)
7
i:
2
or +/ +./ *./ 'rare'-. 'er' RemoveItems a
m&#.^:_1 m#:y ToBasem*
_1
0
1
*ToBase2 and ToBasem produce as many
~. 'rare'
UniqueItems rae
1 2 { A From (Axis 1 efh
result items as needed to hold significance
complementary)
~: 'rare'
UniqueSieve 1 1 0 1
Operations on Booleans
i.~ 'rare'
SelfClassify 0 1 0 3
From (General feg
16b1a Base16 constant 26
1 3 1 0 2 { A
Join and Reshape
nmo
axes)
Dyads
Monad: -. NOT
ab
ca
,
abcd
Enfile
+. OR
*. AND
= XOR
cd
From (Omitted ge
+: NOR
*: NAND
~: XNOR
(<a:;2 0) { A
'ab' , 'cd'
abcd
Append
ki
early axis)
> < >: <: are also meaningful
0 1
Append
om
0 1
m b. (0m<16) Boolean function with truth
, 8 9
2 3
(unequal
1
1
FromUnboxed
2
3
table 2 2#:4 4#:m (1 b. is AND)
(<"1@[ { ]) A
fo
8 9
ranks)
3 2
(fast form)
m b. (16m<32) bitwise Boolean; applies
0 1
(m-16) b. to each bit of integers
Whole-Array Operations
0 1
Append
, ,8
2 3
2 3
|. 'abcde'
edcba
x 32 b. y
x 33 b. y
x 34 b. y
Reverse
(short)
8 0
2 |. 'abcde'
cdeab
RotateLeft
unsigned
signed
rotate y left x bits
0 1
_2
|.
'abcde'
deabc
RotateRight
shift L (x>0) or R (x<0) x bits
0 1
Append
, 8
2 3
2 |.!.'*' 'abcde' ShiftLeft
cde**
2 3
(atom)
Take and Drop
8 8
|.!.'*' 'abcde'
ShiftRightOne *abcd
2 {. i. 6
0 1
Take
hefg
abcd
a
_2 {. i. 6
4 5
TakeLast
,. 'ab'
EnfileItems
lijk
efgh
Rotate
b
2 }. i. 6
2 3 4 5
1 _1 |.
Drop
pmno
ijkl
(multiaxis)
_2 }. i. 6
0 1 2 3
DropLast
ac
dabc
mnop
'ab' ,. 'cd'
AppendItems
4 {. 2 3
2 3 0 0
Overtake
bd
abcd
aeim
4 {.!.9 (2 3) OvertakeCustom
2 3 9 9
Transpose
Itemize (adds
efgh
bfjn
$ ,: 'ab'
1 2
2 3
|:
(reverse
leading
axis)
2 _2 {. i. 4 4 TakeMultiAxis
ijkl
cgko
6 7
axes)
ab
mnop
dhlp
'ab'
,:
'cd'
Laminate
Monad
. First
: Last
cd
ReorderAxes (moves axes
apply to
0
2
x |: y
{ Take {. Head {: Tail
0 1 2
0 1
x to end of axes)
0 1
1 2 0 1
} Drop }. Behead }: Curtail
3 $
'c0 c1 c2' =. |: y AssignIndividualColumns
ReshapeItems 2 3
2 3
0 1
/: 3 1 4 1
1 3 0 2
GradeUp*
Box Operations B is 0 1 2 3 4 5 6 7 8
/:~ 3 1 4 1
1 1 3 4
SortUp*
0 1
3 ($,)
0 1 2
Reshape
'abcd' /: 3 1 4 1 SortUpUsing* bdac
2 3
L. B
2
Level
/:@/: 3 1 4 1
2 0 3 1
Ordinals*
3 ; (4 ; 5)
3 4 5
Link
$ L:0 B
,2 ,2 ,2 ,2
AtLevel
abcd
abcd
efgh
ef*h
3 ,&< (4 ; 5) JoinBoxed
3 4 5
'*' (<1 2)}
Amend
{. L:1 B
0 1 6 8
AtLevel
ijkl
ijkl
mnop
mnop
# S:0 B
2 2 2 2 1
Spread
Raze (expand items 0 1
|.&.> B

Each (fast)

1 {:: B

Fetch

6 7

Fetch

2 3

0 1 {:: B

4 5 2 3 0 1 7 6 8

0 1
,4 6
2 3

;: '2
0 2 0 {::B FetchList

4 5 0 1

;:^:_1

wds'
w1 w2

of opened boxes to 2 3
size of largest, then 4 0
6 6
append)
JWords
RazeWords

2 wds
w1 w2

ab
ab
ef
ef Amend
ij (gerund form) *+
mn
mn
y =. x m} y
AmendInPlace (fast form)
* use \: for descending ordering
'*+' [`(#@[)`]}

Partitions
<\ i. 3 Prefixes

,0 0 1 0 1 2

2 <\ i. 4 Infixes
_2 <\ i. 5

0 1 1 2 2 3

Infixes, no
overlap

0 1 2 3 ,4

<\. i. 3 Suffixes

0 1 2 1 2 ,2

3 <\. i. 5 Outfixes

3 4 0 4 0 1

Outfixes, no
_3 <\. i. 5
3 4 0 1 2
overlap
abcdefgh
u applied to
3 4
ijklmnop
u;.3 SubArrays1
2 2
(bold and italic) qrstuvwx
yx012345
u applied to
6789ABCD
3 4
1
u;._3 FullSubArrays EFGHIJKL
2 2
(bold)
MNOPQRST
abcdef
ghijkl
mnopqr
stuvwx

u applied to
1 _2
u;.0 SubArray2
3 2
(bold)
<;.1 'people' CutOnHead3
0 1 0 1 <;.1 i. 4 CutStartAtOne3
<;.2 'people' CutOnTail3

Gerunds
TwoVerbGerund
OneVerbGerund
Append verb 0 2 4
+:`*: `:0 i. 3
0 1 2
results
+`'' `:6
MakeVerb +
0 6 2
]`!`-@.* 0 3 _2 Agenda*
*u@.v (rank v) is x ((x v y){u)`:6 y
Control Structures
if. T do. B0 else. B1 end.
if. T do. B0 elseif. T1 do. B1 elseif. T2 do. B2 end.1
while. T do. B end.1
whilst. T do. B end.1 (skips T first tme)
for. T do. B end. loop #T times
for_xyz. T do. B end.2
break. jump out of loop continue. go to end of loop
select. T fcase. T0 do. B0 fcase T1 do. B1 end.1 (fcase falls through)
try. B0 catch. B1 catcht. B2 end. execute B1 if error in B03
returncode return.
1
omitted T is true 2 sets xyz and xyz_index for each loop 3 catcht. catches throw.
from a called function

u/ y
u/ 1 3 5
+/ 1 3 5
+/\ 1 3 5
+/\. 1 3 5
m/ y

0 1 0 1 <;.2 i. 4 CutEndAtOne

# i. 2 3

1 2 ,3

#@$ i. 2 3 RankOf 2

x u^:v y
x u^:v y
u^:_
x u^:v^:_ y
u^:a:

Adverbs and Conjunctions


Reflexive: y u y
Passive: y u x
Power: execute x&u for n times; if n<0, execute
inverse of x&u for n times; if n=0, result is y
Power, where n is given by x v y
If: y if x v y is false (0), x u y if x v y is
true (1)
Converge: repeat u until result is constant
DoWhile: repeat u while x v y is 1
ConvergeHistory: repeat u until result is
constant, return all intermediate values
ChaseChain: follow chain of record positions
Inverse: like u, but inverse is v
Adverse: u, but execute v if error during u
At: u x v y
Atop*: x u@:v"mv y
3 8 NB. (+/ 1*3) , (+/ 2*4)
11
NB. +/ 1 2 * 3 4
Appose: (v x) u v y
Compose*: x u&:v"mv y
Dual: v^:_1 (v x) u v y
Dual*: x u&.:v"mv y
2 3 4

>:&.:> 1 2 3
2 3 4
m&v y or u&n y MonadFromDyad: m v y or y u n
x m&v y
same as (m&v)^:x y (x u&n y similarly)
* mv is monadic rank of v

1
2 4
3
1
1 5
3

u`v
u`''

Trigonometry and Calculus


1 o. 1r3p1
0.866
Sin
2 o. 1r3p1
0.5
Cos
3 o. 1r3p1
1.732
Tan
other o. y
Trig Functions
o. 1
3.1416
PiTimes
1 _3 _2
p. 6 5 1
Roots
p. 1 _3 _2

Coeffs

12 10 2

1 2 1 p. 2
9
EvalPoly
0 1 0 1
1 _1 _1 p. 2 EvalPoly
+/"0
9
2 3 2 3
p.. 1 2 1
2 2
PolyDeriv
0 1 2 1 2 3
9 p.. 1 2 1
1 2 +"0
PolyIntegral 9 1 1 0.33
3 4 5 5 6 7
*: d. 1
+:
Derivative
0 1 2 1 3 5
*: D. 1
PartialDeriv
1 2 3 +"1
3 4 5 4 6 8
*:`+: D. 1
AssignDeriv
0 1 2 length 1e_8 u D: n y SecantSlope of nth derivative
1 2 3 +"0
^ t. 1 2 3
TaylorCoeff 1 0.5 0.167
3 4 5 error
u`v t. n
AssignTaylor
x u/ y applies u between each
^ t: 1 2 3
1 1 1
ExpTaylor
cell of x and all of y
^ T. 3
TaylorApprox 1 1 0.5&p.
m H. n
Matrix Operations
HypergeometricSeries
%. y
MatrixInverse
Mathematics
x %. y
MatrixDivide
A. 2 0 1
AnagramIndex 4
x +/ .* y MatrixMultiply
4 A. 'abc'
cab
Anagram
-/ .* y
Determinant
C. 2 1 0
1 2 0
PermForm
+/ .* y
Permanent
Complex Numbers
2x1
ExpNum
2*e^1
1p2
CircNum
1*^2
+ 3j4
3j_4
Conjugate
+. 3j4
3 4
RealImag
*. 3j4
5 0.927
LenAngle
| 3j4
Magnitude 5
j. 1j2
_2j1
TimesJ
3 j. 4
3j4
Complex
r. 1r3p1 Cis (^j. y) 0.5j0.87
2 r. 1p1 TimesCis
_2j0

Copyright 2006 Henry H. Rich

{~^:a:&0
u :.v
u ::v
x u@:v y
x u@v y
1 2 +/@* 3 4
1 2 +/@:* 3 4
x u&:v y
x u&v y
x u&.:v y
x u&.v y
>:&.> 1 2 3

0
2
0
+/"1
2
+/

0 1 2 3

99 ". '2 5.5 xx'


Numbers 2 5.5 99
5j2 ": 1.468 2.3
1.47 2.30
Format
Format
7j_2 ": 2.3
2.30e0
Format
'n[CR]4.' 8!:2 ]3 _5 Format
3 5CR

x u^:n y

TallyOf 2

peo ple

'people' </. i. 6 Key


0 3 1 5 ,2 ,4
The operation, shown in bold in the examples as < or u, can be replaced
by any verb, or with a gerund m in which case the components of m are
applied cyclically, one per partition.
1
x is boundary,:shape. Subarrays start at all possible combinations
of multiples of the atoms of boundary, and have the shape |shape.
A negative component of shape reverses that axis in each subarray.
2
x is corner,:shape. The subarray starts at corner and has shape
|shape. A negative component of corner causes the subarray to
extend backward in that component; a negative component of shape
reverses that axis in the subarray.
3
;._1 omits the first, and ;._2 the last, item in each partition.

u~ y
x u~ y

Shape and Rank


$ i. 2 3 ShapeOf 2 3

pe ople
3

Insert
Insert u between items of y
1 u 3 u 5
Insert
9
Sum
1 4 9
RunningSum
RevRunningSum 9 8 5
Insert verbs from gerund m

1 2 0 C. 'abc' Permute
C.!.2 y
PermParity
p: 3
YthPrime
x p: y
PrimeInfo
q: 56
PrimeFactors
_ q: 56
PrimeExps
__ q: 56

PrimeFacExp

x: 1%3
x:^:_1 (1r3)
2 x: 1r2

Exact
Inexact
NumDenom

cba
_1 0 1
7
various
2 2 2 7
3 0 0 1
2 7
3 1
1r3
0.3333
1 2

Selected Foreigns & Miscellaneous


5 Execute sentence
Info on u: y=_1 inverse; 0 ranks; 1 identity function
Datatype of y
Binary representation of y as coded character string
Binary representation of y as displayable hex array
Numeric/bytestring conversion. x>0: convert list y to char
x 3!:4 inty
list, 2^x (int) or 2^>:x (float) chars/number. x<0:
x 3!:5 floaty
convert char list y to numeric list, 2^-x (int) or 2^1-x
(float) chars/number. x=0: 2-byte short to unsigned int
4!:0 <'name'
Class of name, _1 if undefined
5!:5 <'name'
String which, if interpreted, creates the value of name
6!:0 ''
Current time Y M D H M S
x 6!:2 'sentence' Time to execute sentence x times
7!:2 'sentence'
Space to execute sentence
$. Sparse matrix $: Recursion s: Symbol u: Unicode
". '2 + 3'
u b. y
3!:0 y
3!:1 y
3!:3 y

You might also like