by melling · 5y ago · 0 comments
I’ve now got the crazy desire to see matrices and vectors built into every language in a clean and succinct way.
For example:
10 DIM A(3,3),B(3,3),C(3,3)
20 MAT READ A
30 DATA 1,-5,7, .45,23,9, -5,-1,0
40 MAT B=A:REM assignment
50 MAT B=ZER:REM zero array
60 MAT B=CON:REM all 1s
70 MAT B=IDN:REM identity
80 MAT B=TRN(A):REM transpose
90 MAT B=(2)*A:REM scale
100 MAT B=INV(A),D:REM invert array, determinant in scalar D
110 MAT C=A*B:REM matrix multiplication
120 MAT PRINT C:REM prints something close to an IDN arrayThe GE-635 (https://en.wikipedia.org/wiki/GE-600_series) that it ran on most of its life could have 4 CPUs, had protected memory and floating point hardware, and supported at least 200 kilowords of memory (http://www.bitsavers.org/pdf/ge/GE-6xx/CPB-371A_GE-635_Syste...)
At 36 bits/word, that’s 900 kilobytes.
The first version of Microsoft basic (https://en.wikipedia.org/wiki/Altair_BASIC) ran in 4 kilobytes (leaving about ¾ kilobytes for programs and data), so it’s understandable that it lacked some features (it didn’t even have else clauses in if statements, had SIN, but not COS or TAN, didn’t support integer or string variables, etc))
It’s not as if they don’t know matrices exist. Excel has matrix operations (https://support.microsoft.com/en-us/office/mmult-function-40...)
His only computer was a Commodore 64 and he had written all the software himself in BASIC over the years, just translating a lifetime of professional experience into these little interactive programs on floppies.
Maybe the modern equivalent would be to use Excel.
That said, I would love to have good data science library support (bindings to stuff like BLAS/LAPACK, Torch, Stan, etc) in Idris.
Imagine vector and matrix dimensions checked at compile time. Probabilities guaranteed to be between 0 and 1, checked at compile time. Compile-time enforcement that you are handling "nil/null" data inputs correctly when reading data from a database or CSV file. Writing a web scraper with linear types to help catch bugs & performance leaks. Maybe even proving theorems about the math code you're writing ("is this a valid way to express X"?).
Maybe not ideal for rapid exploratory model development, but it'd be pretty damn cool for writing data science tooling/libraries and "production" ML code in my opinion.
not rhetorical, genuine question.
Once you get your head around everything being a vector, R can be a lot of fun.
I love Julia but I wish I didnt need to explicitly broadcast functions across a vector.
5 * A
does not require broadcasting because multiplication of a matrix by a scalar is mathematically well-defined, whereas 5 + A
(assuming you want element-wise addition) does require broadcasting, i.e., 5 .+ A
because addition of a vector and a matrix is not mathematically well-defined.The Julia approach also has some drawbacks, I was writing some code the other day and forgot to broadcast exp() across a matrix. exp(A) and exp.(A) gives very different results but it's not immediately obvious looking at code, especially when the code is a mixture of broadcasted and native matrix function calls which dots peppered all over the place.
I understand it's an easy mistake to make when you're used to R or Numpy, but I'd say it's their fault you're making this mistake, not Julia's.