Live data from Hacker News

J Notation as a Tool of Thought

hillelwayne.com

1–10 of 60 posts

Re: J Notation as a Tool of Thought

#2
Interesting blog post. All of these are implemented as trivial operations in numpy, so while J or APL might be the originator of the syntax, this 'tool of thought' is not as esoteric as the author makes it sound, and learning J if you already know numpy (or TensorFlow or PyTorch or..) isn't that remarkable.

>> np.array([1, 2, 3]) * 2

array([2, 4, 6])

>>> np.array([1, 2, 3]) * np.array([4, 5, 6])

>>> np.arange(0, 16).reshape(4, 4) + np.array([5, 5, 5, 5])

array([[ 5, 6, 7, 8], [ 9, 10, 11, 12], [13, 14, 15, 16], [17, 18, 19, 20]])

Re: J Notation as a Tool of Thought

#3
post #2

Interesting blog post. All of these are implemented as trivial operations in numpy, so while J or APL might be the originator of the syntax, this 'tool of thought' is not as esoteric as the author makes it sound, and learning J if you already know numpy (or TensorFlow or PyTorch or..) isn't that remarkable. >> np.array([1, 2, 3]) * 2 array([2, 4, 6]) >>> np.array([1, 2, 3]) * np.array([4, 5, 6]) >>> np.arange(0, 16).…

You've reproduced the most trivial example, which many languages make easy. I would be very interested to see another language with a rank operator, for instance.

  ------------------------------------------------------------------------
Challenge for you: rewrite a nontrivial program in one of those frameworks, with the following restrictions:

- No iteration (including implicit iterations—map, filter; reduce is ok)

- No loops whatsoever. Recursion is ok, but should be avoided wherever possible.

- No explicitly named arguments; everything in pointfree style.

(I know, map/filter can be implemented recursively. But compared with the equivalent constructs in apl, they're about 10× as verbose, and harder to reason about and understand. Even reduce is somewhat of a gimme.)

Re: J Notation as a Tool of Thought

#4
post #2

Interesting blog post. All of these are implemented as trivial operations in numpy, so while J or APL might be the originator of the syntax, this 'tool of thought' is not as esoteric as the author makes it sound, and learning J if you already know numpy (or TensorFlow or PyTorch or..) isn't that remarkable. >> np.array([1, 2, 3]) * 2 array([2, 4, 6]) >>> np.array([1, 2, 3]) * np.array([4, 5, 6]) >>> np.arange(0, 16).…

Exactly, one of the things I like about numpy is how it drew from APL and J. It is a more verbose language, and truth be told, J still has more expressive power (non regular processing of data, even state-machine-like processing) which can still influence numpy, or Julia.

Re: J Notation as a Tool of Thought

#5
post #2

Interesting blog post. All of these are implemented as trivial operations in numpy, so while J or APL might be the originator of the syntax, this 'tool of thought' is not as esoteric as the author makes it sound, and learning J if you already know numpy (or TensorFlow or PyTorch or..) isn't that remarkable. >> np.array([1, 2, 3]) * 2 array([2, 4, 6]) >>> np.array([1, 2, 3]) * np.array([4, 5, 6]) >>> np.arange(0, 16).…

You've reproduced the most trivial example, which many languages make easy. I would be very interested to see another language with a rank operator, for instance. ------------------------------------------------------------------------ Challenge for you: rewrite a nontrivial program in one of those frameworks, with the following restrictions: - No iteration (including implicit iterations—map, filter; reduce is ok) -…

I have want to chime in. Agree, it is great that ideas from APL have made it into the language... But there is, fortunately, a long and fruitful path still to explore... I love that J is like an alternative path to functional approaches like Haskell and how it plays in terms of providing expressive power. Still, I will not create code in J that is maintained jointly with other users from other domains (which is the case usually when you are using numpy, for example)

Re: J Notation as a Tool of Thought

#6
post #2

Interesting blog post. All of these are implemented as trivial operations in numpy, so while J or APL might be the originator of the syntax, this 'tool of thought' is not as esoteric as the author makes it sound, and learning J if you already know numpy (or TensorFlow or PyTorch or..) isn't that remarkable. >> np.array([1, 2, 3]) * 2 array([2, 4, 6]) >>> np.array([1, 2, 3]) * np.array([4, 5, 6]) >>> np.arange(0, 16).…

Comparing numpy to J is like comparing a dirty rag to a designer suit. The examples you've listed are trivial; the power of J and other array languages cannot be appreciated from afar.

The philosophy behind array languages runs much deeper than adding two arrays or transposing matrices.

Re: J Notation as a Tool of Thought

#7
post #2

Interesting blog post. All of these are implemented as trivial operations in numpy, so while J or APL might be the originator of the syntax, this 'tool of thought' is not as esoteric as the author makes it sound, and learning J if you already know numpy (or TensorFlow or PyTorch or..) isn't that remarkable. >> np.array([1, 2, 3]) * 2 array([2, 4, 6]) >>> np.array([1, 2, 3]) * np.array([4, 5, 6]) >>> np.arange(0, 16).…

You've reproduced the most trivial example, which many languages make easy. I would be very interested to see another language with a rank operator, for instance. ------------------------------------------------------------------------ Challenge for you: rewrite a nontrivial program in one of those frameworks, with the following restrictions: - No iteration (including implicit iterations—map, filter; reduce is ok) -…

Rank Is actually implicitly done by numpy using a mechanism called broadcasting. For example:

  >>> np.array([10, 20, 30]) + np.array([[1,2,3], [4,5,6], [7,8,9]])
  array([[11, 22, 33],
       [14, 25, 36],
       [17, 28, 39]])
Sieves exist in numpy, called masks:

  >>>np.array([10, 20, 30]) > 15
  array([False, True, True])
Of course they can be operated on just like any other numpy array.

Grades exist in numpy:

  >>>np.array([5,4,3,2,1]).argsort()
  array([4, 3, 2, 1, 0])
Of course they are a little more verbose since all of those operations are from the library and not native to python.

Re: J Notation as a Tool of Thought

#8
post #6
post #2

Interesting blog post. All of these are implemented as trivial operations in numpy, so while J or APL might be the originator of the syntax, this 'tool of thought' is not as esoteric as the author makes it sound, and learning J if you already know numpy (or TensorFlow or PyTorch or..) isn't that remarkable. >> np.array([1, 2, 3]) * 2 array([2, 4, 6]) >>> np.array([1, 2, 3]) * np.array([4, 5, 6]) >>> np.arange(0, 16).…

Comparing numpy to J is like comparing a dirty rag to a designer suit. The examples you've listed are trivial; the power of J and other array languages cannot be appreciated from afar. The philosophy behind array languages runs much deeper than adding two arrays or transposing matrices.

Can you give an example of something that can be done in J that can't be done easily in numpy?

Re: J Notation as a Tool of Thought

#9

Earlier quoted context omitted.

You've reproduced the most trivial example, which many languages make easy. I would be very interested to see another language with a rank operator, for instance. ------------------------------------------------------------------------ Challenge for you: rewrite a nontrivial program in one of those frameworks, with the following restrictions: - No iteration (including implicit iterations—map, filter; reduce is ok) -…

Rank Is actually implicitly done by numpy using a mechanism called broadcasting. For example: >>> np.array([10, 20, 30]) + np.array([[1,2,3], [4,5,6], [7,8,9]]) array([[11, 22, 33], [14, 25, 36], [17, 28, 39]]) Sieves exist in numpy, called masks: >>>np.array([10, 20, 30]) > 15 array([False, True, True]) Of course they can be operated on just like any other numpy array. Grades exist in numpy: >>>np.array([5,4,3,2,1])…

To do sieves in J like the blog post mentioned, the equivalent numpy would be:

>>> arr = np.array([10, 20, 30])

>>> arr[arr > 15]

array([20, 30])

Re: J Notation as a Tool of Thought

#10
This reminded me very much of working in R or working with Numpy.

I however always thought having an array as the primitive in R was great only because R is focused on statistics and data science.

My understanding is that J claims to be general purpose programming and as such I’m surprised the paradigm holds.

Post reply on HN