You can use J as a calculator - just type sentences into the window and press Enter.
J is ready for input when the message in the status bar at the foot of the screen displays Ready.
Typically, the cursor is indented 3 spaces to distinguish user entries from the response of the computer, which are shown aligned to the left.
For example, add 5 to the three numbers 10 20 30:
In [ ]:
5 + 10 20 30
In [ ]:
5 + 10 20 30
In [ ]:
5 - 10 20 30
In [ ]:
5 * 10 20 30
In [ ]:
5 % 10 20 30
In [ ]:
5 ^ 10 20 30
In [ ]:
5 ^. 10 20 30
In [ ]:
*: 10 20 30
In [ ]:
a=: 5
In [ ]:
b=: 10 20 30
In [ ]:
log=: ^.
In [ ]:
plus=: +
In [ ]:
square=: *:
In [ ]:
sum=: +/
In [ ]:
text=: 'hello world'
In [ ]:
a plus b
In [ ]:
square b
In [ ]:
sum b
In [ ]:
c=: a plus b
In [ ]:
sum c
In [ ]:
text
In [ ]:
t=: 'earl of chatham'
In [ ]:
t
In [ ]:
#t
In [ ]:
~. t
In [ ]:
# ~. t
In [ ]:
sort t
In [ ]:
|. t
In [ ]:
2 # t
In [ ]:
3 # ,: t
In [ ]:
;: t
In [ ]:
sort ;: t
In [ ]:
# each ;: t
In [ ]:
i.10 NB. first 10 numbers
In [ ]:
i.4 3 NB. first 12 numbers in a 4 by 3 table
In [ ]:
i.3 4 5 NB. first 60 numbers in a 3 by 4 by 5 table
In [ ]:
+/ 10 20 30
In [ ]:
*/ 10 20 30
In [ ]:
+/i.10001 NB. 10001 - since J starts counting at 0
In [ ]:
+/i.3 4 5
"power insert" of 10 20 30 is a big number! It exceeds the representation used by the machine, so J returns infinity.
Can you figure out the other examples below?
(Try 3 ^ 4, then take 2 to the power of this number.)
The 'x' used here means "extended" and instructs J to use extended precision in performing the calculations, instead of converting to floating point.
In [ ]:
^/ 10 20 30
In [ ]:
^/ 2 3 4
In [ ]:
^/ 2 3 4x
In [ ]:
3b102 NB. base (102 in base 3)
In [ ]:
3r5 NB. ratio (3 % 5)
In [ ]:
3j5 NB. complex number
In [ ]:
3p5 NB. Pi (3 * Pi ^ 5)
In [ ]:
3x5 NB. Exponentional (3 * 2.71828... ^ 5)
In [ ]:
1p1 2p1 NB. Pi, 2 * Pi
In [ ]:
%: -i.6 NB. square roots of minus 0 to minus 5
In [ ]:
? 20#100
In [ ]:
? 20#100
In [ ]:
load 'stats'
In [ ]:
dstat ? 20#100
In [ ]:
normalrand 6
In [ ]:
dstat normalrand 10000
In [ ]:
load 'trig plot'
In [ ]:
sin i.6
In [ ]:
sin i.3 4
In [ ]:
plot sin i.3 4
In [ ]:
plot sin 0.2 * i.30 30
In [ ]:
'surface' plot sin 0.2 * i.30 30
In [ ]: