Arrays and matrices.

22 views
Skip to first unread message

Waldek Hebisch

unread,
May 11, 2013, 4:01:23 PM5/11/13
to fricas...@googlegroups.com
Logically two dimensional arrays and matrices are the same
thing. AFAICS our definitions differ in that that matrices
require R to be Join(SemiRng, AbelianMonoid) and in exchange
define a bunch of extra exports. However, several of matrix
export makes perfect sense for arrays.

I am tempted to use only a single construcion, not two.
Given that matrices are used much more frequently than
arrays I think of deleting definition of arrays
and using only matrices (after generalizing definition).

Similarly for OneDimensionalArray and Vector.

Opinions?

--
Waldek Hebisch
heb...@math.uni.wroc.pl

someone

unread,
May 11, 2013, 4:09:24 PM5/11/13
to fricas...@googlegroups.com
Hi,

> Opinions?

Not strictly an opinion on this topic, but there are a few recent
commits in OpenAxiom which might be related:

------------------------------------------------------------------------
r2832 | dos-reis | 2013-05-11 16:31:49 +0200 (Sat, 11 May 2013) | 3 lines

* algebra/array2.spad.pamphlet: Cleanu up.
------------------------------------------------------------------------

and

------------------------------------------------------------------------
r2830 | dos-reis | 2013-05-11 06:26:51 +0200 (Sat, 11 May 2013) | 1 line

Remove IndexedMatrix as unused
------------------------------------------------------------------------

and

------------------------------------------------------------------------
r2829 | dos-reis | 2013-05-11 03:24:23 +0200 (Sat, 11 May 2013) | 1 line

Introduce opcodes for arrays constructions
------------------------------------------------------------------------

At least the first two could give a hint.


For the technical pros and cons of you proposal
I can not say anything relevant.


One point I could see is that with two constructions one could try
to separate the mathematical algebraic structure "Matrix" and the
computer-science data-structure "2D-Array".
Maybe there are good reasons to do this?


-- Raoul

Gabriel Dos Reis

unread,
May 11, 2013, 4:55:48 PM5/11/13
to open-axi...@lists.sf.net, fricas...@googlegroups.com
someone <some...@bluewin.ch> writes:

| One point I could see is that with two constructions one could try
| to separate the mathematical algebraic structure "Matrix" and the
| computer-science data-structure "2D-Array".
| Maybe there are good reasons to do this?

I consider the current state of matrix code in OpenAxiom to be too much
of obfuscation, but I am still going to keep the distinction 2d arrays
vs. matrices. I think of the latter as linear algebra related whereas
the former is for more general stuff that do not necessarily have much
structures.

-- Gaby

Ralf Hemmecke

unread,
May 11, 2013, 5:49:31 PM5/11/13
to fricas...@googlegroups.com
> I am tempted to use only a single construcion, not two.
> Given that matrices are used much more frequently than
> arrays I think of deleting definition of arrays
> and using only matrices (after generalizing definition).

I tend to oppose to a removal of the array types.

For me arrays are data structures, containers for data. They live on the
lowest level and are not supposed to export any algebraic structure.
Well if they are considered as ADTs they do anyway, but I guess, it's
clear what I mean.

Vectors and Matricies would be build on array types. So in some sense
you are right that someone who programs mathematics might not need
arrays, but still, I somehow doubt. Matricies and Vectors for me always
come with a mathematical structure.

What I rather question is that Matrix and Vector have no size in the
type, so Vector(K) does not represent a vector space, but rather it
represents the union over all n-dimensional vector spaces for all n.
Same for matrix. *This* is what bothers me.

However, I agree that for an end user, it's rather convenient not to be
bothered with size information like Vector(K,5) or so.

I'd rather like to think about dropping either DirectProduct or Vector.

Vector and Matrix are end-user domains that I wouldn't encourage to use
inside other algebra library code, i.e. Vector and Matrix are for .input
files but not .spad files.

OK, this probably goes in another direction, but you wanted opinions.

Ralf

Waldek Hebisch

unread,
May 11, 2013, 7:11:24 PM5/11/13
to fricas...@googlegroups.com
Ralf Hemmecke wrote:
>
> > I am tempted to use only a single construcion, not two.
> > Given that matrices are used much more frequently than
> > arrays I think of deleting definition of arrays
> > and using only matrices (after generalizing definition).
>
> I tend to oppose to a removal of the array types.
>
> For me arrays are data structures, containers for data. They live on the
> lowest level and are not supposed to export any algebraic structure.
> Well if they are considered as ADTs they do anyway, but I guess, it's
> clear what I mean.

You want clear distinction, but things are fuzzy. Arrays have
rich algebraic structure due to indexing/slicing. Currently
part of this structure is only implemented for matrices...
Sometimes one needs additive structure and two dimensional
indexing. Currently, if base type has no multiplicative
structure we have no appropriate type (matrices want
multiplication in base type, array have no additive
structure). In other cases matrices are used because
arrays lack needed operations, but multiplicative
(and sometimes even additive) structure of matrices
is not used.

Also, think about incidence matrices of various
combinatorial structures. One point of view is
that they are mere data structures to store
needed information. But algebra of matrices
preved to be quite fruitful in such contexts.

I think that much power of Axiom philosophy comes from
fact that user can do operations even if original
implementer had different use in mind. Current
distinction between matrices and arrays for
me is an artificial limitation on what users
can do. Of course, we could generalize matices
to allow base types without multiplicative
structure and enrich arrays with some operations
which are currently only available for matrices.
But given current usage patterns I doubt if
we need sepatate arrays at all.

> Vectors and Matricies would be build on array types. So in some sense
> you are right that someone who programs mathematics might not need
> arrays, but still, I somehow doubt. Matricies and Vectors for me always
> come with a mathematical structure.
>
> What I rather question is that Matrix and Vector have no size in the
> type, so Vector(K) does not represent a vector space, but rather it
> represents the union over all n-dimensional vector spaces for all n.
> Same for matrix. *This* is what bothers me.
>
> However, I agree that for an end user, it's rather convenient not to be
> bothered with size information like Vector(K,5) or so.
>

Well, I tend to think that Matrices (and Vectors) form infinite
dimensional space. Simply, each matrix has only finitely
many nonzero entries and infintely many zeros. Due to practical
reasons we have to store info about possible range of nonzero
entries and we do not bother to porform operations on implicit
zeros. Of course, to be consistent with this view we would
have to implement operations between matrices of different
dimennsions. And out of bounds array references should
then produce zero instead of error. Given usefulness of
error checking I do not push forward this point of view.
But it is enough to stop me worring about size not being
part of type.

BTW: RectangularMatrix has size as part of type, so somebody
wanting finite dimensional vector space can use this.

> I'd rather like to think about dropping either DirectProduct or Vector.
>
> Vector and Matrix are end-user domains that I wouldn't encourage to use
> inside other algebra library code, i.e. Vector and Matrix are for .input
> files but not .spad files.

So what would you use? RectangularMatrix? What about cases when
size of result is not known to the caller (like reducedSystem).

--
Waldek Hebisch
heb...@math.uni.wroc.pl

someone

unread,
May 11, 2013, 7:22:42 PM5/11/13
to fricas...@googlegroups.com
> [...] but I am still going to keep the distinction 2d
> arrays vs. matrices. I think of the latter as linear algebra related
> whereas the former is for more general stuff that do not necessarily
> have much structures.

Isn't that what I tried to say?

Gabriel Dos Reis

unread,
May 11, 2013, 8:09:21 PM5/11/13
to fricas...@googlegroups.com
I believe we are in violent agreement that the previous message wasn't to
contradict what you said.

-- Gaby

Martin Baker

unread,
May 12, 2013, 10:35:22 AM5/12/13
to fricas...@googlegroups.com
On 11/05/13 21:01, Waldek Hebisch wrote:
> Logically two dimensional arrays and matrices are the same thing
> Opinions?

I seem to remember using 'TwoDimensionalArray String' in '.input' scripts to hold and output tabular results. 'List List String' is not output as a table and 'Matrix String' is not valid.

At one stage I was considering writing a 'table' domain specially for outputting tabular results. The idea was to allow nice formatting of tabular output so, for instance, rows and columns would have text headings. Individual cells could be highlighted in various ways and so on. In the end I came to the conclusion that this would not work very well with the command line interface, a better solution would be for FriCAS to have high level interface to a spreadsheet front end.


On 11/05/13 22:49, Ralf Hemmecke wrote:
> What I rather question is that Matrix and Vector have no size in the
> type, so Vector(K) does not represent a vector space, but rather it
> represents the union over all n-dimensional vector spaces for all n.
> Same for matrix. *This* is what bothers me.

Yes, this always seemed like an anomaly to me, I assumed that was due to my lack of knowledge about FriCAS. I thought it should be a general principle that, the type system should be given the maximum opportunity to find errors (such as when attempting to add a 2D vector to a 3D vector) at compile time rather than at runtime. I thought this was one of the main benefits of having dependant types? I agree that there are times when multiple dimension vectors are needed, but these should be of a different type, in the same way that we have both Lists and Arrays.

Martin
Reply all
Reply to author
Forward
0 new messages