hypercomplex dilate and condense

Don't hold back

hypercomplex dilate and condense

PostPosted by drab » Wed Mar 15, 2017 8:09 am

Much practical work with complex and hypercomplex numbers involves separating, individually manipulating, and re-joining their coefficients (such as the real and imaginary parts).

Currently, monadic system function ⎕dc provides an indispensable means for doing this.
It can both separate and join individual complex coefficients.

But these operations are so fundamentally basic that they should be given full status as first class citizens among the primitive functions.


So, I propose two new primitive monadic functions dilate > and condense < .


Dilate separates out the 1 or 2 or 4 or 8 real coefficients in a complex or hypercomplex value.

(⍴real),1 ←→ ⍴ real1← > real
(⍴complex),2 ←→ ⍴ real2← > complex
(⍴quaternion),4 ←→ ⍴ real4← > quaternion
(⍴octonion),8 ←→ ⍴ real8← > octonion


Condense joins the 1 or 2 or 4 or 8 real coefficients into a complex or hypercomplex value.

s ←→ ⍴ real← < real1← (s,1)⍴ real
s ←→ ⍴ complex← < real2← (s,2)⍴ real
s ←→ ⍴ quaternion← < real4← (s,4)⍴ real
s ←→ ⍴ octonion ← < real8← (s,8)⍴ real

where

r ←→ <>r

for any non-nested r of any shape of any numeric type, including real (which has only 1 coefficient).

(BTW-- ⎕dc does not go this far with 1-component reals.)
drab
 
Posts: 289
Joined: Thu Oct 09, 2014 6:23 am

Re: hypercomplex dilate and condense

PostPosted by forummaster » Thu Mar 16, 2017 9:36 am

Very interesting proposal. I'm in the midst of various projects right now, but I very much like your idea.
forummaster
 
Posts: 545
Joined: Wed Jan 23, 2013 1:00 pm

Re: hypercomplex dilate and condense

PostPosted by drab » Thu Mar 16, 2017 10:50 am

The argument of Dilate (>) may be any non-nested numeric array of any shape.
A nested argument is a domain error.
A non-numeric argument is a domain error.

The argument of Condense (<) may be any non-nested non-scalar numeric array with shape last element 1 or 2 or 4 or 8.
Any other shape is a length error.
A nested argument is a domain error.
A non-numeric argument is a domain error.
drab
 
Posts: 289
Joined: Thu Oct 09, 2014 6:23 am

Re: hypercomplex dilate and condense

PostPosted by drab » Thu Mar 16, 2017 11:07 am

Actually, Dilute and Condense could also be used to convert back and forth between multi-byte and single byte characters.

For regular 2-byte characters (in origin 0)

>r ←→ (¯1⌽⍳1+⍴⍴r)⍉⎕av[(2⍴256)⊤⎕av⍳r]

<r ←→ ⎕av[256⊥⎕av⍳(1⌽⍳1+⍴⍴r)⍉r]

The most important parts are ⊤ and ⊥ with ⎕av.
The transposition is merely to keep the working dimension last.

The extension to 4-byte characters (if we had them) would be trivial.
drab
 
Posts: 289
Joined: Thu Oct 09, 2014 6:23 am

Re: hypercomplex dilate and condense

PostPosted by drab » Sat Mar 18, 2017 5:03 am

As described, dilate > and condense < operate on the last dimension.

But variants ≥ and ≤ could operate on the first dimension ...

1,⍴real ←→ ⍴ real1← ≥ real
2,⍴complex ←→ ⍴ real2← ≥ complex
4,⍴quaternion ←→ ⍴ real4← ≥ quaternion
8,⍴octonion ←→ ⍴ real8← ≥ octonion

s ←→ ⍴ real← ≤ real1← (1,s)⍴ real
s ←→ ⍴ complex← ≤ real2← (2,s)⍴ real
s ←→ ⍴ quaternion← ≤ real4← (4,s)⍴ real
s ←→ ⍴ octonion ← ≤ real8← (8,s)⍴ real

≥c ←→ ⎕av[(2⍴256)⊤⎕av⍳c]

≤c ←→ ⎕av[256⊥⎕av⍳c]
drab
 
Posts: 289
Joined: Thu Oct 09, 2014 6:23 am

Re: hypercomplex dilate and condense

PostPosted by forummaster » Sun Apr 09, 2017 5:04 pm

Excellent idea! Please test it in the latest Alpha version:

http://www.nars2000.org/download/binaries/alpha/

and review the documentation in Dilate and Condense.

The implementation of ≤R and ≥R will have to wait for a while. The "last coordinate" versions were already done in ⎕DC; the "first coordinate" versions will take rather more work. In the meantime, you'll have to do the transposes yourself as in ≤R ←→ ⍉<⍉R and ≥R ←→ ⍉>⍉R.

Also, character conversions will have to wait. First we need to support one- and four-byte characters as well as the full two-byte characters. At the moment we support UCS-2 which is fixed width UTF-16 without the high and low surrogates in U+D800 to U+DFFF. The whole set of Unicode character encodings include UTF-8, UTF-16, and UTF-32 where the latter two also have LE (Little Endian) and BE (Big Endian) variants -- that's five character conversions alone.

BTW, excellent choice of names! I'm a stickler for good names which is why I (unsuccessfully) argued with Dyalog against calling the Left and Right Tack functions "Left" and "Right" (I call them "Lev" and "Dex"). Among other things, I think it's important to use a name which is unlikely to be confused with normal usage of regular words. A good example is "Catenate" which (as I've been told) was originally to be called "Concatenate" but when the designers (namers?) looked up Concatenate they were led to its synonym Catenate, and since that word was both accurate and unfamiliar (and APL is a minimal language), it was chosen.

For example, alternative names for those functions include Combine and Separate, but those are too easily confused with their normal usage. Your choices have just the right blend of accuracy with unfamiliarity, not to mention that they also are listed as antonyms in my various dictionaries. What sources did you use to come up with those names, or did they just come to out of the blue?
forummaster
 
Posts: 545
Joined: Wed Jan 23, 2013 1:00 pm

Re: hypercomplex dilate and condense

PostPosted by drab » Mon Apr 10, 2017 7:01 am

I'm also a stickler for good names. Very much so. In fact, I've always considered it absolutely critical to have the very best names for everything.

Whenever I need to implement anything new, I always consult the thesaurus and the dictionary first.

Actually, I usually consult my OWN thesaurus first. Long ago I wrote an interactive application called Concept to do this.
It can focus on any set of words, which may or may not be closely related. It can also choose or eliminate parts of speech. Then it finds all the synonyms of every word in the focus list, and also all synonyms of synonyms -- there are often hundreds of them. It assigns a score to each possible synonym, based on a relevance algorithm. The table of possible synonyms can be sorted by straight score, or alphabetically. It can also be sorted by a modified score which takes in account each word's typical frequency of usage (how commonly it is used). Any word in the list of possible synonyms can be added to the focus list. Any word in the focus list can be given a weight, and any weight can be changed any time. A weight can even be made negative, to imply an antonym. So, I can rapidly iterate, and drill down to find the very best words for what I want.
drab
 
Posts: 289
Joined: Thu Oct 09, 2014 6:23 am

Re: hypercomplex dilate and condense

PostPosted by drab » Mon Apr 10, 2017 7:06 am

I even use my Concept application to find good names for variables in programs that I write.

It also has a feature to give preference to shorter words, if that's what I want.
drab
 
Posts: 289
Joined: Thu Oct 09, 2014 6:23 am


Return to Open Discussion

Who is online

Users browsing this forum: No registered users and 0 guests

cron