3

I am a bit confused ; I noticed that if I do :

a[sqrt(2)] : 1;
arrays;

I would get :

[a]

So a is an array for Maxima… yet sqrt(2) is an irrational number.

I use to think of an array as a collection of items sorted by indices, where those indices are integer numbers… I acknowledge that my definition for "array" has been strongly influenced by other, "non-symbolic" programming languages. In those languages, arrays "map" to a certain contiguous region of a computer's memory. It is therefore natural to use integer number as indices since integer number are countable. However, real numbers are not countable.

Obviously, maxima seems to have a different definition for the term "array" : what is it exactly ? (the documentation does not define it, at least there is no introductory paragraph in the documentation section dedicated to arrays)

Gael Lorieul
  • 3,006
  • 4
  • 25
  • 50

1 Answers1

3

Maxima's concept of arrays, lists, and matrices is pretty confused, since various ideas have accreted in the many years of the project.

Maxima's "subscripted variable" = symbol with subscript (with arbitrary index) and no assigned value. E.g. a[sqrt(2)] with no value assigned.

Maxima's "undeclared array" = hash table with arbitrary keys, associated with array symbol as a symbol property, not a value. Your a[sqrt(2)] : 1 is an example of an undeclared array. Maxima creates the array a the first time a value is assigned.

Maxima's "declared array" = contiguous storage, associated with array symbol as a symbol property, not a value.

Maxima's "Lisp array" = contiguous storage, associated with array symbol as symbol value.

Maxima's "fast array" = hash table, associated with array symbol as a symbol value.

Yes, this is a mess. Sorry about that. These are all interesting ideas, but there is no unifying framework. I haven't even mentioned lists and matrices. Hope this helps all the same.

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48
  • Don't be sorry ! (^.^) I've got a few questions more for you : I don't really understand the difference between "symbol property" and "symbol value"… Other questions : the only way to create a "declared array" is to call `array()`, correct ? How would I do to create a "lisp array" or a "fast array" ? – Gael Lorieul Apr 29 '15 at 07:27
  • Lisp has a concept of a symbol having multiple "slots" (something like keys of a hash table). There is a function slot, a value slot, a properties slot, maybe others. If a symbol can have both a value and a function at the same time, it is called a Lisp-2; if only one at a time, it is called a Lisp-1. The properties list is just a list of keys and values; it is an easy way to associate arbitrary stuff with a symbol. The advantage of putting the storage for an array on the property list, instead of in the symbol value, is that when you enter, say, `a`, you just see `a`, not the whole array. – Robert Dodier Apr 29 '15 at 17:55
  • About declared arrays, yes, they are created by `array`. Lisp arrays are created by `make_array` and fast arrays are created automatically (as undeclared arrays) when the global flag `use_fast_arrays` is `true`. – Robert Dodier Apr 29 '15 at 17:55