Extending the expand operator

Let your imagination run wild

Extending the expand operator

PostPosted by manandpc » Tue Aug 14, 2012 10:50 am

I found out the the dyadic \ (expand) primitive operator L \ R or L \ [X] R is only using a boolean vector L as parameter

Here is an APL magic function for extending the primitive operator to an integer vector:

Code: Select all
      ⎕cr'Expand'
Z←L Expand[X] R                               
:if 0=⎕NC 'X' ⋄ X←⎕IO+(1<⍴⍴R) ⋄ :endif       
Z←(L+L=0)/[X](0<L←((L≥0)+(L<0)×|L)/L×L≥0)\[X]R

      ⎕cr'ExpandBar'
Z←L ExpandBar[X] R                           
:if 0=⎕NC 'X' ⋄ X←⎕IO ⋄ :endif               
Z←(L+L=0)⌿[X](0<L←((L≥0)+(L<0)×|L)/L×L≥0)⍀[X]R


The only thing is I dont have the knowledge to actually implement it.

The following examples are taken from APLX and DyalogAPL manuals.

Code: Select all
      1 0 3 ¯2 5 \ 3 8 2
DOMAIN ERROR
      1 0 3 ¯2 5 \ 3 8 2
                ∧

      1 0 3 ¯2 5 Expand 3 8 2
3 0 8 8 8 0 0 2 2 2 2 2

      1 ¯2 3 ¯4 5 \ 'A'
DOMAIN ERROR
      1 ¯2 3 ¯4 5 \ 'A'
                 ∧

      1 ¯2 3 ¯4 5 Expand 'A'
A  AAA    AAAAA

      M
 1 2 3
 4 5 6

      1 ¯2 2 0 1 Expand M
 1 0 0 2 2 0 3
 4 0 0 5 5 0 6

      1 ¯2 2 0 Expand[⎕IO] M
 1 2 3
 0 0 0
 0 0 0
 4 5 6
 4 5 6
 0 0 0

      1 ¯2 2 0 ExpandBar M
 1 2 3
 0 0 0
 0 0 0
 4 5 6
 4 5 6
 0 0 0

      1 ¯2 2 0 1 ExpandBar[⎕IO+1] M
 1 0 0 2 2 0 3
 4 0 0 5 5 0 6

      1 ¯2 1 Expand (1 2)(3 4 5)
 1 2  0 0  0 0  3 4 5
manandpc
 
Posts: 67
Joined: Tue Jun 19, 2012 9:39 am

Re: Extending the expand operator

PostPosted by forummaster » Fri Mar 17, 2017 12:08 am

So sorry it took so long to get to this excellent idea. It is now implemented in the latest Alpha version:

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

Thanks very much for the suggestion!
forummaster
 
Posts: 567
Joined: Wed Jan 23, 2013 1:00 pm


Return to New Primitive Operators

Who is online

Users browsing this forum: No registered users and 1 guest

cron