Mailing List Archive: 49091 messages

## [REBOL] Matrix Arithmetic Rules? Help needed!

### From: robbo1mark:aol at: 10-Jan-2002 12:57

```
After reading Joel Neely's most recent
excellent article on REBOL forces on
Iterators, Recursion & Algebra, I hit
upon the idea of expanding the REBOL
arithmetic & logic functions to handle
series & matrix arguments as well as
their current scalar arguments.

There's a little bit synchronicity here
as I've recently been reading & studying
Kenneth Iverson's "J" programming language
which is a dialect of APL, surely one of
the wierdest notations yet with the some
of the most powerful built-in functions
for computing maths expressions in any
programming language that I've seen.

Anyway, I would like to redefine the
prefix REBOL arithmetic & logic functions
to be able to handle series & matrix arguments
as well as scalar arguments, trouble is I
can't figure out all the correct "RULES"
for series & matrix operations and Iam
looking for HELP from list members to
design correct behaviour & optimal functions.

Here's some examples of what I would like to be
able to say in REBOL.

== [3 4]
>> add [2 3] [2 3]
== [4 6]
>> multiply 2 [2 3]
== [4 6]
>> multiply [2 3] [2 3]
== [4 9]
>> subtract 1 [2 3]
== [-1 -2]
>> subtract [2 3] 1
== [1 2]
>> subtract [4 5] [2 3]
== [2 2]
>> divide 12 [2 3]
== [6 4]
>> divide [36 24] 12
== [3 2]
>> greater? 4 [3 5]
== [true false]
>> equal? 4 [3 4 5]
== [false true false]
>> equal? [2 3 4] [2 4 6]
== [true false false]

I'm sure you get the picture of what I mean
here and to be honest these funcs are pretty
trivial examples of what Iam looking for and
can be coded quite easily.

MY PROBLEM / QUERY are these

Firstly What is the correct behavior of performing
arithmetic and logic functions on arbitarily
nested blocks, ie matrixes, and secondly what is
the correct behaviour when series or matrix are of
differing lengths, ie missing arguments.

Here's some examples of what I mean, how should
these evaluate?

>> multiply [2 3] [3 4 5]
== ????
>> add [2 3] [3 4 5]
== ????
>> add [2 3] [3 [4 ]]
== ????
>> greater? [2 3 4] [2 1]
== ????
>> equal? [2 [3 4]] [[2 3] 4]
== ????
>> subtract [3 4 5] [2 2 2 2]
== ????

Even these are fairly trivial examples of problems
compared to some deeply nested matrix or huge
series operations you could imagine.

Rules I have ascertained are these;

1. If any argument is a series! then the result is a series!

2. If one arg is a scalar and the other arg is a series then
the function applies the operation on the scalar to each value
in the series resulting in a series!.