Mailing List Archive: 49091 messages

# Matrix Arithmetic Rules? Help needed!

### [1/7] 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 [5]]]
== ????
>> 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!. Please help me to flesh out these rules / logic and point out any flaws or mistakes you can see in my examples, and also if your willing to help design these functions and their attributes. Anybody interested? Joel, Ladislav, Larry........? thanks, Mark Dickson

### [2/7] from: joel:neely:fedex at: 10-Jan-2002 13:36

Hi, Mark, [Robbo1Mark--aol--com] wrote:
> Anyway, I would like to redefine the > prefix REBOL arithmetic & logic functions > to be able to handle series & matrix arguments... >
...
> >> multiply [2 3] [2 3] > == [4 9] >
Part of the issue is that there are two different multiplications for vectors, "inner" and "outer" product. innerproduct [2 3] [5 7] == 31 outerproduct [2 3] [5 7] == [[10 14] [15 21]] OTOH, some would insist that the distinction is based on the orientation of the dimensions, so that multiply [2 3] [5 7] == 31 multiply [2 3] [[5 7]] == [[10 15] [14 21]] and other variations...
> 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. >
The first issue is to define what your application(s) is/are, because that will tell you which notational conventions the practitioners in that/those area(s) will expect. Do you want to support: - simple vectors and matrices from high-school algebra? - specific geometric/graphical applications (e.g., 3-d graphics with perspective)? - quantum mechanics? I'd suggest taking a specific target domain and writing code to meet the needs and conventions of that area. Then look at another area and see how much (if anything) you'd have to change/extend to meet that new challenge. -jn-

### [3/7] from: cyphre:seznam:cz at: 11-Jan-2002 9:57

Hi Mark and all, ----- Original Message ----- From: <[Robbo1Mark--aol--com]> To: <[rebol-list--rebol--com]> Sent: Thursday, January 10, 2002 6:57 PM Subject: [REBOL] Matrix Arithmetic Rules? Help needed!
> After reading Joel Neely's most recent > excellent article on REBOL forces on
<<quoted lines omitted: 3>>
> series & matrix arguments as well as > their current scalar arguments.
I believe that this feature will be build natively in rebol because RT are planning to make built-in 3D dialect in the future. I'm also curious if RT will implement "only" 3D dialect which will use DRAW routines or if they implement either own native 3D engine(texture mapping, z-buffering etc.) or wrapper over each platform so Rebol's 3D apps will be dependent for example on DirectX, OpenGL etc. What about a new datatype matrix! ? ;-) regards, Cyphre

### [4/7] from: robbo1mark::aol::com at: 11-Jan-2002 4:11

Joel, thank you for your prompt reply, you seem to be quite well versed in this, could you please point me to any websites you know of where I might investigate these further, thanks, mark In a message dated Thu, 10 Jan 2002 2:51:13 PM Eastern Standard Time, Joel Neely <[joel--neely--fedex--com]> writes:

### [5/7] from: robbo1mark:aol at: 11-Jan-2002 4:53

Hello everybody, well I wouldn't lime to presume on RT future plans because these things are always uncertain especially concerning timescales, however after pondering Joel Neely's earlier response my opinion is now that REBOL is intended for the general purpose and not especially special applications like 3D graphics or quantum physics, although these too should be possible. I did'nt have any specific applications in mind when I made my original post it was just an intellectual exercise / puzzle based on what I'd seen & liked in J language. That being the case I think we should try initially for the most common case which Joel termed "High School" or general vector operations. Again not being a maths buff Iam requesting math / logic help for this exercise, I know how to do the programming I just don't know the correct "rules" or "expectations". cheers, Mark Dickson In a message dated Fri, 11 Jan 2002 4:06:53 AM Eastern Standard Time, "Cyphre" <[cyphre--seznam--cz]> writes:

### [6/7] from: chris:starforge:demon at: 11-Jan-2002 10:17

[Robbo1Mark--aol--com] wrote:
> That being the case I think we should try initially > for the most common case which Joel termed "High School" > or general vector operations. > > Again not being a maths buff Iam requesting math / logic help for this exercise, I know how to do the > programming I just don't know the correct "rules" > or "expectations". >
The big problem is that there are no single set of rules - the way things work (row/column orders, how results should be presented etc) change depending upon the application. You could implement "general vector operations" or "general matrix operations" but then you have to decide *which* general ones to implement - the ones that mathematicians prefer, the ones used by 3D procgrammers (which are slightly different) etc. I expect one of the reasons RT have avoided this issue is simply because matrix maths are such a thorny area... Chris -- .------{ http://www.starforge.co.uk }-----. .--------------------------. =[ Explorer2260, Designer and Coder \=\ P: TexMaker, ROACH, site \ =[___You_will_obey_your_corporate_masters___]==[ Stack: EETmTmTRRSS------ ]

### [7/7] from: cyphre:seznam:cz at: 11-Jan-2002 11:43

Hi again, ----- Original Message ----- From: <[Robbo1Mark--aol--com]> To: <[rebol-list--rebol--com]> Sent: Friday, January 11, 2002 10:53 AM Subject: [REBOL] Re: Matrix Arithmetic Rules? Help needed!
> Again not being a maths buff Iam requesting math / logic help for this
exercise, I know how to do the
> programming I just don't know the correct "rules" > or "expectations". >
If I understand well, you might have a look at following links: http://www.sosmath.com/matrix/matrix.html http://lagrange.la.asu.edu/VirtualClass/Algebra/ I have also nice Algebra book from Technical university in Brno but it is written in only czech language... regards, Cyphre

Notes
• Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted