Appendix: J Notation

A brief summary of J notation is provided below to assist in the use of the Scratchpad or the extended data entry feature for variables. For more details regarding J, see the J Software website (http://www.jsoftware.com).

Expressions in J are evaluated strictly from right to left, but parentheses can be used to alter the order of evaluation. For example, 5*3+2 gives 25, while (5*3)+2 is 17.

Negative numbers are preceded by an underscore.

Functions in J generally operate on lists of numbers as they do on single values. If one operand is a vector of length n, the other operand must be either of the same length or a scalar value. For example, if the variable x and y are assigned the values

  x=: 1 2 3 4 5

  y=: 1 0 1 1 0

then

  x*2

2 4 6 8 10

  x*y

1 0 3 4 0

The primitive J functions consist of one or two characters, as indicated in the table below for a few of the J functions likely to be most useful to you. In each definition, the meaning of the symbol is given for the monadic (symbol x) and dyadic (x symbol y) cases. The symbol →, below, indicates the result of the expression on the left.



Function
Symbol Monadic Dyadic Examples
+
addition 3+2 → 5
- negate subtraction -2 → _2
5-2 → 3
* sign multiplication 3*2 → 6
*_3 → _1
% inverse division %2 → 0.5
8%4 → 2
^ exponential power ^1 → 2.71828
3^2 → 9
^. natural log logarithm ^.2 → 0.6931
10^.2→ 0.301
=
equals 5 = 5 → 1
<
less than 1<2 → 1
>
greater than 1>2 → 0
<. floor lesser of <. 1.23 → 1
2 <. 3 → 2
>. ceiling greater of >. 1.23 → 2
2 >. 3 → 3
*.
and 1 *. 0 → 0
+.
or 1 +. 0 → 1
! factorial out of !3 → 6
3 ! 6 → 20
# tally copy # 5 6 7 → 3
3#2 → 2 2 2