Hacker News new | ask | show | jobs
by IKantRead 947 days ago
As a huge Lisp/Scheme fan, I don't find it surprising that Python became the language of choice for neural networks over Lisp.

NN in general just boil down to doing lots of linear algebra, which is a lot about mutating very large matrices. For this you really just want a wrapper around BLAS/LAPACK, so you can leverage existing optimized libraries.

Working with matrices in Lisp always feels a bit clunky, and doubly so when you want to do a lot of stateful operations on them. The real compitetor in this space to Python is something like Matlab, which has probably the best interface for doing linear algebra (but is worse at everything else).

The one area where Lisp and Python both shine is the ability to perform automatic differentiation. Lisps are great for this task since it's all symbolic manipulation. However, this is only important once you have a solid interface for working with matrices.

If you want to get a feel for the difference I would suggest reading through the surprisingly excellent The Little Learner. I think you'll find that while it really demonstrates the power of Scheme (Racket in this case) in areas where it excels, you wouldn't want to use the framework in that book for anything other than toy examples.

1 comments

But is there is something inherent to Lisp that makes it "clunky" to work with matrices?

Lisp can be at least as high level and expressive as any other language.

> But is there is something inherent to Lisp that makes it "clunky" to work with matrices?

s-exps are basically coding at the level of the AST, which for many programming tasks is a powerful level of both abstraction and control.

But this interface tends to work much better on tree-like structures (the most simple of which is the list, which in it's simplest case is a cons cell, Lisp's most fundamental particle).

Most programming tasks can boil down to tree manipulation, but large matrices feel a bit out of place with this interface because you are basically to working with arrays (which in it's simplest cases is a pointer to a memory address, which is C's fundamental particle). C like languages (I know, technical ALGO-like), tend to feel more natural for these tasks.

But of course if you can manipulate trees easily, you can manipulate code easily which gives you...

> Lisp can be at least as high level and expressive as any other language.

In practice, for Lisp this is also a weakness. Again, I love Lisps in general, and of course any Lisp and especially Common Lisp (with it's exceptionally excellent macro system) can do anything you want.

However, my (and many others) experience has been that this leads to is it becomes very easy to create code that is amazing for the original developer, but very difficult for new developers to get their head around. Hence the adage "Lisp is optimal for team sizes of one."

You could undoubtable build the worlds most elegant interface to working with matrices in Lisp, but now you essentially have a new language.

I think matlab has the most succint language for writing matricies

  [1 2 3; 4 5 6; 7 8 9]
then lisp

   #2A((1 2 3) (3 4 5) (7 8 9))
then python comma freak show

   [[1,2,3],[4,5,6],[7,8,9]]
python's greatest achievement was bringing open source to matrix calculations and dethroning matlab. python is what it is today because it offered 99% of what matlab offered in open source and for $0 to uni students
I was curious about how Julia does 2D matrices and arrays, given they target mathemeticians. They seem to have no shortage of methods of creating them.

  julia> [1,2,3] # An array of `Int`s
  3-element Vector{Int64}:
   1
   2
   3

  julia> [1:2, 4:5] # Has a comma, so no concatenation occurs.
  2-element Vector{UnitRange{Int64}}:
   1:2
   4:5

  julia> [1:2  4:5  7:8]
  2×3 Matrix{Int64}:
   1  4  7
   2  5  8

  julia> [[1,2]  [4,5]  [7,8]]
  2×3 Matrix{Int64}:
   1  4  7
   2  5  8

  julia> [1 2
          3 4]
  2×2 Matrix{Int64}:
   1  2
   3  4

  julia> a=[1 2 5 8 9; 3 4 2 1 33]
  2×5 Array{Int64,2}:
   1  2  5  8   9
   3  4  2  1  33
https://docs.julialang.org/en/v1/manual/arrays/
What about Octave and R, which are open source and for $0?
octave was always seen as subpar version of matlab and r is a statistics programming language. in comparison python was already back then a proper practical programming language that people were using for things other than math
Lisps have n-dimensional arrays since decades. Often their implementations are a bit less efficient than the ones found written in C and used by Python.

> You could undoubtable build the worlds most elegant interface to working with matrices in Lisp, but now you essentially have a new language.

What?

I don't think so, I think it just happens to be that common lisp is more oriented around lists and not vectors.

Since we're in lisp, you can imagine some macros that make working with matrices easier!