Live data from Hacker News

Manipulate Functions with the J Language

adamtornhill.com

11–20 of 34 posts

Re: Manipulate Functions with the J Language

#11
post #4

What's the advantage of using array programming versus using list/array types in other languages? Nothing I saw in this article seems particularly unique to J except the syntax.

Parallelization automatically, special constructs for sparse matrixes, complex manipulation of multidimensional arrays without need for making sure they are constructed correctly. Not to mention never having to worry about an indexing error, unless you are specifically asking for an index, in which case the bug is in your design, not the program. Built in methods for sorting and searching that are very efficient, as well as filtering. Also, J is faster when you give it all the data you can at once, rather than moving through index by index. A lot of these advantages take time to really be aware of, much like Erlang's bread and butter often hiding behind much more than one article.

Re: Manipulate Functions with the J Language

#12
I had a similar experience when I first started learning machine learning; thinking in terms of, and manipulating data as, matrices and vectors was not easy at the beginning -- even if the rest of language (Python) was 'classic'.

I guess pushing the envelop with a language like J, where everything is an array, plus the unusual function manipulation, would make it even more alien; it's like touring another planet. At least that's what I felt while reading this.

---

That said, it's really boggles me that every time someone tries to explain a new paradigm or idiom, they feel obliged to make it look as superior way of doing things. (Such as in : "J helps us get better at expressing that universal pattern.").

Can't we just express difference just like that; a different new thing. It doesn't have to be better, or worse.

Otherwise, I really enjoyed the article.

Re: Manipulate Functions with the J Language

#13
post #8

J is a beautiful, beautiful language. It is quite hard to learn -- as a benchmark, I'd say Haskell is easy by comparison -- but once you reach a critical mass of knowledge it can more addictive, and more fun to program in, than anything else I've tried. While J is fast, and can be practical, I would never recommend it for that reason, if only because it's so niche. But if you want to glimpse what a small sliver of al…

I love J. It's elegant, expressive, and concise. Just like regex, it looks like line noise at first, but that is because it's designed to get its job done as efficiently as possible.

I think it would be a wonderful way to write deep learning modules, since it is such a powerful tensor manipulation language. Unfortunately however, even although it should be perfectly suited to SIMD and GPU acceleration, this work hasn't been done yet.

So it ends up not really being fast enough for modern numeric programming - but I hope one day someone smarter than me will invest in making this happen.

I should add that the J community is wonderfully helpful. If you decide to take the plunge in learning this great language, be sure to join the mailing list.

Re: Manipulate Functions with the J Language

#14

I had a similar experience when I first started learning machine learning; thinking in terms of, and manipulating data as, matrices and vectors was not easy at the beginning -- even if the rest of language (Python) was 'classic'. I guess pushing the envelop with a language like J, where everything is an array, plus the unusual function manipulation, would make it even more alien; it's like touring another planet. At…

The author programs in a lot of languages including Lisp and Smalltalk, so I doubt he feels J is all around superior. You have to admit the syntax is pretty universal (meaning it covers everything) and consistent. With Python you learn a bit of the language/syntax and then how to apply all the functions and methods where they belong.

Re: Manipulate Functions with the J Language

#15
post #13
post #8

J is a beautiful, beautiful language. It is quite hard to learn -- as a benchmark, I'd say Haskell is easy by comparison -- but once you reach a critical mass of knowledge it can more addictive, and more fun to program in, than anything else I've tried. While J is fast, and can be practical, I would never recommend it for that reason, if only because it's so niche. But if you want to glimpse what a small sliver of al…

I love J. It's elegant, expressive, and concise. Just like regex, it looks like line noise at first, but that is because it's designed to get its job done as efficiently as possible. I think it would be a wonderful way to write deep learning modules, since it is such a powerful tensor manipulation language. Unfortunately however, even although it should be perfectly suited to SIMD and GPU acceleration, this work hasn…

If you get the chance, check out Aaron Hsu's work. He wrote a compiler that converts Dyalog APL to C++ for high performance stuff...I can't remember if GPU or what. He goes over the code in several YouTube videos and HackerNews posts. First class stuff. I think Dyalog sells it as a product.

Re: Manipulate Functions with the J Language

#16
post #13
post #8

J is a beautiful, beautiful language. It is quite hard to learn -- as a benchmark, I'd say Haskell is easy by comparison -- but once you reach a critical mass of knowledge it can more addictive, and more fun to program in, than anything else I've tried. While J is fast, and can be practical, I would never recommend it for that reason, if only because it's so niche. But if you want to glimpse what a small sliver of al…

I love J. It's elegant, expressive, and concise. Just like regex, it looks like line noise at first, but that is because it's designed to get its job done as efficiently as possible. I think it would be a wonderful way to write deep learning modules, since it is such a powerful tensor manipulation language. Unfortunately however, even although it should be perfectly suited to SIMD and GPU acceleration, this work hasn…

APL (and J by extension) are more tricky to parallelise than you might expect. The frequent reliance on boxing leads to irregular pointer structures, and the absence of compile-time type information makes it hard to generate code at all. APL is usually based on efficient implementations of primitives, but that is certainly too fine-grained to be sufficient for bandwidth-starved devices such as GPUs. I contributed to an APL-to-GPU compiler[0], and it was hard to make it work on more than a small (well-behaved) subset.

[0]: https://github.com/melsman/apltail

Re: Manipulate Functions with the J Language

#17
post #4

What's the advantage of using array programming versus using list/array types in other languages? Nothing I saw in this article seems particularly unique to J except the syntax.

I'd take this a step further and say the website for J language doesn't move a finger to entice anyone to learn the language or use it. I don't know if it's academia or what - but if I spent the effort on creating a whole programming language that I believed was actually good - I'd have a very different front page.

Although some academics (like myself) are intrigued by them, APL-like languages (APL, J, K, Q, etc.) have very little to do with academia historically, and were developed pretty much isolated from the academic programming languages community. APL itself does have distant roots in academia, growing out of notation Iverson developed at Harvard in the 1950s, but its history as a programming language goes via IBM and a variety of other companies generally focused on enterprise and finance (I.P. Sharp, Morgan Stanley, Dyalog, Kx Systems).

As for J, it was released by a startup, J Software, founded by Kenneth Iverson and Roger Hui in 1990 for that purpose. It was later open sourced in 2011.

Re: Manipulate Functions with the J Language

#18

The problem I've seen with these languages is they are tough to debug syntax and semantics errors. A typed array programming language would be interesting. When are J or APL expressions well-formed and would some kind of type system help incrementally build and compose expressions?

J syntax is very strictly enforced; the rules for verbs are unambiguous and fairly easy to parse as a human. The difficulty arises in learning and committing these rules to memory. For example, every verb is infix, but the right side is evaluated before the left. thus expressions like '2+3 4' is unambiguously different from '4 3+2' (the former evaluates to 14 while the latter is 24). J is a language similar to C in t…

If you add spaces around your (single) asterix, hn won't interpret it as signalling itallics: * itallics * .

Re: Manipulate Functions with the J Language

#19
To me the most interesting part of this article is the part that nobody else seems to be commenting on: the ability to automatically invert a function, even a programmer-defined function. That seems magical! What if I define a hash function? How can it possibly invert that? Clearly there's something interesting going on behind the scenes, and I wish the article discussed what it is, and how (and when) it works.

Everything else in the article seems like plain old functional programming to me, with a little syntax sugar here and there.

Re: Manipulate Functions with the J Language

#20
post #19

To me the most interesting part of this article is the part that nobody else seems to be commenting on: the ability to automatically invert a function, even a programmer-defined function. That seems magical! What if I define a hash function? How can it possibly invert that? Clearly there's something interesting going on behind the scenes, and I wish the article discussed what it is, and how (and when) it works. Every…

The only other language where I’ve seen this is Factor, with its “undo” word. I presume they work similarly, so I can speak to the general idea.

It’s not that the compiler can invert a hash, or automatically derive a logarithm function from an exponentiation function, or anything like that.

Essentially, if you have a composition of functions in a “pipeline” (h ∘ g ∘ f):

    [ f g h ]   
Then to get the inverse of the composition, you just invert each function and reverse the whole thing (f⁻¹ ∘ g⁻¹ ∘ h⁻¹):

    [ f g h ] undo
    [ \ h undo \ g undo \ f undo ]
“undo” is defined for a set of primitive words. If there isn’t an inverse defined for some function you used in the composition, then it fails; however, you can just define a custom inverse for your function. And obviously this relies on having some kind of reified representation of functions available.

“undo” can be used for things like pattern-matching: a destructuring function, which takes some value and produces its fields, is the inverse of a constructor, which takes the fields and constructs a value.

Post reply on HN