Jsoftware
High-Performance Development Platform

Apply to all axis

View: New views
7 Messages — Rating Filter:   Alert me  

Apply to all axis

by June Kim :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

As I posted a couple of days ago, "guard" is enclosing an array with
0,~0,] on all axis(well, to be precise, from rank-1 and up).

   (0,~0,])"3 (0,~0,])"2 (0,~0,])"1 i.2 2 2
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0

0 0 0 0
0 0 1 0
0 2 3 0
0 0 0 0

0 0 0 0
0 4 5 0
0 6 7 0
0 0 0 0

0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0


I did it with 1) power and 2) insert but I found no way of doing this
in J with pure tacit definition.

I think "apply to all axis" is sometimes useful in some cases such as:
reversing on all axis:

   |."2 |."1 i. 3 3
8 7 6
5 4 3
2 1 0

Is there a way to make a tacit definition of the verb for arbitrary rank arrays?

Maybe I'd better define an adverb, instead.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Apply to all axis

by Dan Bron :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

June Kim wrote:
>  Is there a way to make a tacit definition of the verb for arbitrary rank arrays?

This question has been raised before, and I have a nascent Essay on the Wiki about it.   If I ever finish it, it will demonstrate a suite of methods for operating on all axes.  My current favorite (first shown to me by Kirk Iverson when he was teaching me J) is the idiom   0&|:@:f^:(#@:$)    For example,

           f=:0 , ,&0
       
           ]A=:   0&|:@:f^:(#@:$)   i.2 2 2
        0 0 0 0
        0 0 0 0
        0 0 0 0
        0 0 0 0
       
        0 0 0 0
        0 0 1 0
        0 2 3 0
        0 0 0 0
       
        0 0 0 0
        0 4 5 0
        0 6 7 0
        0 0 0 0
       
        0 0 0 0
        0 0 0 0
        0 0 0 0
        0 0 0 0
       
           A -: (0,~0,])"3 (0,~0,])"2 (0,~0,])"1 i.2 2 2
        1
       
The approach is purely tacit, as you desire.  In fact, it can be written as a purely tacit adverb:

           oaa=:(0&|:@:)   (^:(#@:$))  NB.  on all axes
       
           A-: (0 , ,&0) oaa i. 2 2 2
        1

Your approach   f"n f"(n-1) .... f"0  y  is interesting  and I will think about ways of tacitizing it.  I already tried a couple of obvious routes, but the one that worked was cheating (used  128!:2  ) and the one that wasn't [as obviously] cheating didn't work.

> I think "apply to all axis" is sometimes useful in some cases such as:
>  reversing on all axis:

The most fun way to do this is:

    ];.0  y

Which is just how the monad   ;.0   is defined.  Roger posted it as a solution in a related thread:

    http://www.jsoftware.com/pipermail/programming/2005-December/000304.html

another thread that applies to operating on all axes was "shave" (the inspiration for and macguffin of my pending Essay):

    http://www.jsoftware.com/pipermail/programming/2007-October/008302.html

Hope this helps.  I'll let you know if I make any headway in tacitizing  f"n .... f"0  (*).  

-Dan

(*):  If the following proposal had been adopted, this problem would be trivial:

      http://www.jsoftware.com/jwiki/System/Interpreter/Requests06#head-6d80783f357671339d77503eaea000fe3e9b5f5f

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Apply to all axis

by Dan Bron :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

June Kim wrote:
> I think "apply to all axis" is sometimes useful in some cases such as:
>  reversing on all axis:

I responded:
>The most fun way to do this is:
>
>    ];.0  y

Currently,  u;.0 y  means  "apply  u  to  y  after reversing  y  along each axis; it is equivalent to  (0 _1 */$y) u;.0 y  ".  This and related threads suggest a better definition.    What do Jers think about the following proposal?

Let  u;.0 y  be changed to mean  "apply  u  along each axis of  y".  That is, let it solve the problem which is the topic of this and related threads (the question is raised often enough that it is almost a FAQ).

Formally, let

      u;.0 y    <==>    0&|:@:u^:(#@:$) y  

I doubt the monad  u;.0  finds much use in the wild; for the few exceptions, converting from the old definition to the new will be painless.  Anyone who currently uses the current definition of  u;.0 y  can simply replace the expression with  u |.;.0 y   or   (0 _1 */$y) u;.0 y  after the change.  Verb definitions with the monad  u;.0  embedded may simply subsitute  @:(|.;.0)  for  ;.0  .

Objections?  Seconds?  Comments?

-Dan

PS:  If adopted, the proposal would save me having to complete my Essay.  Which I may never do anyway.  In which case the adoption would ease my guilt :)

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

RE: Apply to all axis

by R.E. Boss :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Perhaps first the question could be answered why "reversing y along
each axis" was introduced in defining ;.0


R.E. Boss


> -----Oorspronkelijk bericht-----
> Van: programming-bounces@... [mailto:programming-
> bounces@...] Namens Dan Bron
> Verzonden: vrijdag 20 juni 2008 20:23
> Aan: Programming forum
> Onderwerp: Re: [Jprogramming] Apply to all axis
>
> June Kim wrote:
> > I think "apply to all axis" is sometimes useful in some cases such as:
> >  reversing on all axis:
>
> I responded:
> >The most fun way to do this is:
> >
> >    ];.0  y
>
> Currently,  u;.0 y  means  "apply  u  to  y  after reversing  y  along
> each axis; it is equivalent to  (0 _1 */$y) u;.0 y  ".  This and related
> threads suggest a better definition.    What do Jers think about the
> following proposal?
>
> Let  u;.0 y  be changed to mean  "apply  u  along each axis of  y".  That
> is, let it solve the problem which is the topic of this and related
> threads (the question is raised often enough that it is almost a FAQ).
>
> Formally, let
>
>       u;.0 y    <==>    0&|:@:u^:(#@:$) y
>
> I doubt the monad  u;.0  finds much use in the wild; for the few
> exceptions, converting from the old definition to the new will be
> painless.  Anyone who currently uses the current definition of  u;.0 y
> can simply replace the expression with  u |.;.0 y   or   (0 _1 */$y) u;.0
> y  after the change.  Verb definitions with the monad  u;.0  embedded may
> simply subsitute  @:(|.;.0)  for  ;.0  .
>
> Objections?  Seconds?  Comments?
>
> -Dan
>
> PS:  If adopted, the proposal would save me having to complete my Essay.
> Which I may never do anyway.  In which case the adoption would ease my
> guilt :)
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

RE: Apply to all axis

by Dan Bron :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

RE Boss asked:
> why "reversing y along each axis" was
> introduced in defining ;.0

My quick search didn't turn up a rationale, but in response to your (RE Boss') "Reversing all ranks" thread, which I linked to earlier, Roger had this to say:

      Ken told me that sometimes, when he came up with a neat
      solution to a problem, he'd be accused of putting in
      a special construct in the language just for that problem.
      (And that was why the solution was so neat.)  But the
      accusation lost its sting when it was repeated in problem
      after problem, in multiple diverse fields.

(From   http://www.jsoftware.com/pipermail/programming/2005-December/000322.html  )

As I read it, it was posted more-or-less in defense of the definition of  ;.0  , so maybe Ken saw this (reversing all ranks) as a recurring problem.  Roger, can you shed any light?

Actually, RE Boss, maybe you can.  You started that thread by asking for a replacement for  |."3@:(|."2)@:(|."1)  .  Do you remember why you wanted to do that?  I personally have not seen this problem recur in field after field.

In fact, after some research earlier today, it seems the recurring "all ranks" problem is in fact the one that started this thread:  padding an array on all dimensions.  Trimming (the opposite of padding) an array on all dimensions came in second.

-Dan

PS:  I don't remember ever wanting to "reverse all ranks", but I have wanted an "alternating reversal" sometimes.  That is, I wanted to reverse every other item of an array.  One of my prouder J moments was discovering   (A."_1~ _2 | i.@:#)  for this purpose.  There are other ways, too:

     http://www.jsoftware.com/pipermail/programming/2006-November/004198.html



----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: Apply to all axis

by Roger Hui :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Roger, can you shed any light?

The current choice of the monad u;.0 is minor as
it is just one instance of a more general dyadic case.
I don't know why Ken made this choice (reversing
each axis).  Perhaps it was motivated by something
from tensor analysis.



----- Original Message -----
From: Dan Bron <j@...>
Date: Friday, June 20, 2008 14:16
Subject: RE: [Jprogramming] Apply to all axis
To: Programming forum <programming@...>

> RE Boss asked:
> > why "reversing y along each axis" was
> > introduced in defining ;.0
>
> My quick search didn't turn up a rationale, but in response to
> your (RE Boss') "Reversing all ranks" thread, which I linked to
> earlier, Roger had this to say:
>
>       Ken told me that sometimes, when
> he came up with a neat
>       solution to a problem, he'd be
> accused of putting in
>       a special construct in the
> language just for that problem.
>       (And that was why the solution
> was so neat.)  But the
>       accusation lost its sting when it
> was repeated in problem
>       after problem, in multiple
> diverse fields.
>
> (From  
> http://www.jsoftware.com/pipermail/programming/2005-December/000322.html  )
>
> As I read it, it was posted more-or-less in defense of the
> definition of  ;.0  , so maybe Ken saw this (reversing
> all ranks) as a recurring problem.  Roger, can you shed any
> light?
> Actually, RE Boss, maybe you can.  You started that thread
> by asking for a replacement for  |."3@:(|."2)@:(|."1) 
> .  Do you remember why you wanted to do that?  I
> personally have not seen this problem recur in field after field.
>
> In fact, after some research earlier today, it seems the
> recurring "all ranks" problem is in fact the one that started
> this thread:  padding an array on all dimensions. 
> Trimming (the opposite of padding) an array on all dimensions
> came in second.
>
> -Dan
>
> PS:  I don't remember ever wanting to "reverse all ranks",
> but I have wanted an "alternating reversal" sometimes. 
> That is, I wanted to reverse every other item of an array. 
> One of my prouder J moments was discovering   (A."_1~
> _2 | i.@:#)  for this purpose.  There are other ways, too:
>
>     
> http://www.jsoftware.com/pipermail/programming/2006-November/004198.html


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

RE: Apply to all axis

by R.E. Boss :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It was rather specific when I wanted to reverse all ranks: I was trying to
construct 3 dimensional curves. Further details I do not remember after
almost 2.5 years.

I second your proposal for ;.0 although I estimate the chance of
implementation is far less than epsilon.

"Reversing y along each axis" seems to me as arbitrary as "trimming y along
each axis" or "padding y with 0 along each axis" or any other operation on y
"along each axis".


R.E. Boss


> -----Oorspronkelijk bericht-----
> Van: programming-bounces@... [mailto:programming-
> bounces@...] Namens Dan Bron
> Verzonden: vrijdag 20 juni 2008 23:16
> Aan: Programming forum
> Onderwerp: RE: [Jprogramming] Apply to all axis
>
> RE Boss asked:
> > why "reversing y along each axis" was
> > introduced in defining ;.0
>
> My quick search didn't turn up a rationale, but in response to your (RE
> Boss') "Reversing all ranks" thread, which I linked to earlier, Roger had
> this to say:
>
>       Ken told me that sometimes, when he came up with a neat
>       solution to a problem, he'd be accused of putting in
>       a special construct in the language just for that problem.
>       (And that was why the solution was so neat.)  But the
>       accusation lost its sting when it was repeated in problem
>       after problem, in multiple diverse fields.
>
> (From   http://www.jsoftware.com/pipermail/programming/2005-
> December/000322.html  )
>
> As I read it, it was posted more-or-less in defense of the definition of
> ;.0  , so maybe Ken saw this (reversing all ranks) as a recurring problem.
> Roger, can you shed any light?
>
> Actually, RE Boss, maybe you can.  You started that thread by asking for a
> replacement for  |."3@:(|."2)@:(|."1)  .  Do you remember why you wanted
> to do that?  I personally have not seen this problem recur in field after
> field.
>
> In fact, after some research earlier today, it seems the recurring "all
> ranks" problem is in fact the one that started this thread:  padding an
> array on all dimensions.  Trimming (the opposite of padding) an array on
> all dimensions came in second.
>
> -Dan
>
> PS:  I don't remember ever wanting to "reverse all ranks", but I have
> wanted an "alternating reversal" sometimes.  That is, I wanted to reverse
> every other item of an array.  One of my prouder J moments was discovering
> (A."_1~ _2 | i.@:#)  for this purpose.  There are other ways, too:
>
>      http://www.jsoftware.com/pipermail/programming/2006-
> November/004198.html
>
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
LightInTheBox - Buy quality products at wholesale price