The J programming language: is it useful for mathematics?
J is very useful. While it has its quirks, once you get used to them, as gar said, you can really understand the language quite well. I consider myself a novice at J, but being exposed to it, I can definitely tell what the example in the accepted answer's "mysterious code". It's easy enough to say you don't know what a program does, that's the same for many languages.
I for one cannot understand, without running it, some C programs, especially ones that rely on pointers, me being mainly a JavaScript programmer. Does that make C useless and unreadable? Granted, J has a higher scale of unreadability, but it still can be readable. There's a line between readable and unreadable, and J lies right on the line.
As for your question, I believe it is very useful for math (I use it for geometry) and mathematicians (it's a nice calculator if you have a computer with you, and are used to it). While you may not appreciate J, I strongly suggest you try learning it. J, APL, etc. can seem like a bunch of nonsense, but it's just another way to program and to learn.
You can stop reading if you're convinced—I'm mainly showing examples now.
J is good for its conciseness. You want a multiplication table for numbers 0
to 10
? Boom:
*/~i.11
This yields a very appealing table:
0 0 0 0 0 0 0 0 0 0 0
0 1 2 3 4 5 6 7 8 9 10
0 2 4 6 8 10 12 14 16 18 20
0 3 6 9 12 15 18 21 24 27 30
0 4 8 12 16 20 24 28 32 36 40
0 5 10 15 20 25 30 35 40 45 50
0 6 12 18 24 30 36 42 48 54 60
0 7 14 21 28 35 42 49 56 63 70
0 8 16 24 32 40 48 56 64 72 80
0 9 18 27 36 45 54 63 72 81 90
0 10 20 30 40 50 60 70 80 90 100
Want to make it look like a "real" multiplication table (without the zero columns)? No problem:
*/~1+i.10
While this looks like a bunch of jargon to the casual observer, it makes a great deal of sense. Observe:
*/~ 1 + i. 10
i. n
makes an integer range $[0, n)$. 1 + i. n
creates an integer range $[1, n]$. ~
makes a one-argument function (or monad) take its argument twice, making it a two-argument function (or dyad). E.g., +~ n = n + n
and *~ n = n * n
or n^2
.
/
inserts the function before it (*
/multiplication) between every member (so +/
is summation over a list), or, when having two arguments as in +/~
, it essentially makes a table in our desired fashion.
While this is only a bit of J, you can see the effect it has for its brevity. It makes calculation swifter and easier—so long as you devote the time to learning it. Which I suggest you do.
In my opinion it's not better than other languages like C++ or Fortran. I don't know it very well but I cannot see anything that cannot be done with other "computer" programming languages.
Surely it's not more readable: for example I cannot see clearly what this code does without I see it in action:
G=: 3 : '(0&,. , 1&,.@|.)^:y i.1 0'
and probably if you try to make it more readable you avoid its main feature, because it's very coincisive.
If you want to do some mathematics with computer language, I prefer to use something like Mathematica
or Matlab
. Even is the free software octave
and similare are very powerful.
From a program language point of view, their disadvantage is that they are script code and not compiled one, but I don't care about it for mathematical experiment.
If you want to create some machine native code, I prefer some mainstream programming language, like C++ or even fortran when needed, because if you search you can find libraries for almost everything (more about numeric calculus that symbolic one), like boost::math
or biginteger
.
At the end, in my opinion it's not useful because it has nothing that cannot be done with other available instruments, and its code syntax its unreadable unless you use it for many months.
My belief is that the language is not meant to write code for others to understand, rather we can save a lot of keystrokes once we get used to the language.
I mainly use J for simulating problems on probability, and also for the fun of functional programming! ( I try to maintain a list of the stackexchange problems simulations on my github profile )