Skip, I once made a mess of a J wiki page, so I am not yet prepared to
try again; but please feel free to edit the material and upload it, if you
like (I think it would make more sense if an article is written from your
perspective anyway).

I would like to add that there is a more general method to translate
explicit verbs to tacit verbs.  The idea is to represent pronouns by boxes
and use amend to update their values.  That is how the verbs tcCap
and tcAt in
http://www.jsoftware.com/pipermail/general/2003-April/014507.html were
generated and this is how your explicit verb can be converted to an
equivalent tacit verb using this method (you can find more details in my J
conference talk; see,
http://www.jsoftware.com/jwiki/Community/Conference2012#Schedule ):

jose1=: 4 : 0
 k =. y - 1{x            NB. k is the number of "kills"
 L =. i. y               NB. L is the position list
 whilst. k =. k-1 do.
     L =. (<:0{x) |. L   NB. Rotate by the skip number
     L =. }. L           NB. Remove the dead index.
 end.
)

becomes,

   o=. @:
   y=. o]
   f=. &{::

   'X Y K L'=. i.4                               NB. 4 pronouns for the
boxes

   k0=. <o ( (<: o (0 { (X f) )) |. (L f) ) L }] NB. Rotate by the skip
number
   k1=. <o ( }. o (L f)                   ) L }] NB. Remove the dead index.

   kill=. k1 o k0                                NB. Killing block

   j0=. ;                                        NB. Linking the arguments
   j1=. '. .'&(] , ;:@:[)                        NB. Appending two boxes
referenced by (K f) and (L f)
   j2=. <o ( Y f - 1 { X f ) K }]                NB. K is the number of
"kills"
   j3=. <o ( i. o (Y f) )    L }]                NB. L is the position list
   j4=. (K f) ((kill y) ^: [) ]                  NB. Killing (K f) times
   j5=. (L f)                                    NB. Returning (L f)

   ( jose20=. j5 o j4 o j3 o j2 o j1 o j0 f. )
3&({::)@:(2&({::) (<@:(}.@:(3&({::))) 3} ])@:(<@:(<:@:(0 { 0&({::)) |.
3&({::)) 3} ])@:]^:[ ])@:(<@:(i.@:(1&({::))) 3} ])@:(<@:(1&({::) - 1 {
0&({::)) 2} ])@:('. .'&(] , ;:@:[))@:;

This method produces over sized code but its performance is usually not too
bad:


   3 7 (jose1 ; jose20) 10000
┌────────────────────────────────┬────────────────────────────────┐
│8922 111 930 2691 3850 6154 6624│8922 111 930 2691 3850 6154 6624│
└────────────────────────────────┴────────────────────────────────┘


   ((10 st ]) o (('3 7 ' , ] , ' 10000'"_))each @: ;:) 'jose1 jose20'
┌──────────────────┬──────────────────┐
│┌──────┬─────────┐│┌──────┬─────────┐│
││133440│0.0653413│││264960│0.0830984││
│└──────┴─────────┘│└──────┴─────────┘│
└──────────────────┴──────────────────┘

Here there is a surprise, now the handmade tacit version (jose15) is
slightly faster than the explicit original,

   ((10 st ]) o (('3 7 ' , ] , ' 10000'"_))each @: ;:) 'jose1 jose15'
┌──────────────────┬─────────────────┐
│┌──────┬─────────┐│┌──────┬────────┐│
││133440│0.0658859│││263808│0.046892││
│└──────┴─────────┘│└──────┴────────┘│
└──────────────────┴─────────────────┘

I might be wrong but as far as I can see nothing has changed except that
these timings correspond to a Surface Pro and the previous timings to a HP
laptop.
Go figure!

  jose15
}.@:(] |.~ <:@:(0 { [))^:((] - 1 { [)`(i.@]))

On Fri, May 10, 2013 at 2:49 AM, Skip Cave <[email protected]> wrote:

> Jose,
>
> That was a great description, showing the steps transforming my explicit
> Josephus verb into a full tacit version.Thanks very much!
>
> I learned several tricks from your explanation, including the 13 : tacit
> conversion, though it apparently doesn't always work. How you used infinity
> to detect a cap error is still over my head, as is the use of the power
> verb, but I will keep studying it.
>
> This would make a great wiki article entitled "Converting Explicit to
> Tacit"
>
> Skip
>
> On Thu, May 9, 2013 at 5:25 PM, Jose Mario Quintana <
> [email protected]> wrote:
>
> > Skip, I finally was able to take a look at your version.  The following
> > should be a series of equivalent definitions of your version. I do not
> code
> > explicitly thus the control words are alien to me but they probably are
> > correct:
> >
> >    jose1=: 4 : 0
> >  k =. y - 1{x            NB. k is the number of "kills"
> >  L =. i. y               NB. L is the position list
> >  whilst. k =. k-1 do.
> >      L =. (<:0{x) |. L   NB. Rotate by the skip number
> >      L =. }. L           NB. Remove the dead index.
> >  end.
> > )
> >
> > Substituting L in the first line of the whilst block into the second
> line,
> >
> >    jose10=: 4 : 0
> >   k =. y - 1{x           NB. k is the number of "kills"
> >   L =. i. y              NB. L is the position list
> >   whilst. k =. k-1 do.
> >     L =. }. (<:0{x) |. L NB. Removing the dead index after rotating by
> the
> > skip number
> >   end.
> > )
> >
> > Replacing the whilst by a for form,
> >
> >    jose11=: 4 : 0
> >   k =. y - 1{x           NB. k is the number of "kills"
> >   L =. i. y              NB. L is the position list
> >   for. i.k do.
> >     L =. }. (<:0{x) |. L NB. Removing the dead index after rotating by
> the
> > skip number
> >   end.
> > )
> >
> > Eliminating L by reusing y,
> >
> >    jose12=: 4 : 0
> >   k =. y - 1{x           NB. k is the number of "kills"
> >   y =. i. y              NB. L is the position list
> >   for. i.k do.
> >     y =. }. (<:0{x) |. y NB. Removing the dead index after rotating by
> the
> > skip number
> >   end.
> > )
> >
> > Finding a tacit form for the for block...
> >
> >    '}. (<:0{x) |. y' (13 :)
> > [: }. ] |.~ [: <: 0 { [
> >
> > Replacing Caps by Ats because Caps are overused! ;)
> >
> >    }.@:(] |.~ <:@:(0 { [))
> > }.@:(] |.~ <:@:(0 { [))
> >
> > Replacing the for form by a power form,
> >
> >    jose13=: 4 : 0
> >   k =. y - 1{x
> >   y =. i. y
> >   x (}.@:(] |.~ <:@:(0 { [))) ^: k y
> > )
> >
> > Making a one-liner by substituting k and y in the first and second lines
> > into the code of the last line,
> >
> >    jose14=: 'x (}.@:(] |.~ <:@:(0 { [)))^:(y - 1{x) i. y' (4 :)
> >
> > Trying to find a tacit expression,
> >
> >    'x (}.@:(] |.~ <:@:(0 { [)))^:(y - 1{x) i. y' (13 :)
> > 4 : 'x (}.@:(] |.~ <:@:(0 { [)))^:(y - 1{x) i. y'
> >
> > No, J is not smart enough; not yet anyway.  Replacing (y - 1{x) by __ to
> > find the form,
> >
> >    'x (}.@:(] |.~ <:@:(0 { [)))^:__ i. y' (13 :)
> > [ }.@:(] |.~ <:@:(0 { [))^:__ [: i. ]
> >
> > Replacing the offending Cap,
> >
> >    [ (}.@:(] |.~ <:@:(0 { [))^:__) i.@]
> > [ }.@:(] |.~ <:@:(0 { [))^:__ i.@]
> >
> > Consulting the Dictionary for power... Yes, the gerund form fits the
> bill!
> >
> >    jose15=. }.@:(] |.~ <:@:(0 { [))^:((] - 1 { [)`(i.@]))
> >
> >    3 7 (jose1 ; jose15) 10000
> > ┌────────────────────────────────┬────────────────────────────────┐
> > │8922 111 930 2691 3850 6154 6624│8922 111 930 2691 3850 6154 6624│
> > └────────────────────────────────┴────────────────────────────────┘
> >
> > They compare as follows,
> >
> >    st=. 7!:2@:] ; 6!:2
> >
> >    10 st '3 7 jose1  10000'
> > ┌──────┬────────┐
> > │133440│0.100217│
> > └──────┴────────┘
> >    10 st '3 7 jose15 10000'
> > ┌──────┬────────┐
> > │263808│0.184226│
> > └──────┴────────┘
> >
> > The explicit version is leaner and faster but my attitude is to wait for
> > the implementation to catch up (I would not bet on it though).  Wait!
> > Apparently the issue is more complicated than just explicit versus tacit,
> >
> >    ((<10) (((,@<@]) , st) &> ) (('3 7 ' , ] , ' 10000'"_)each @: ;:))
> > 'jose1 jose10 jose11 jose12 jose13 jose14 jose15'
> > ┌────────────────┬──────┬────────┐
> > │3 7 jose1 10000 │133440│0.100398│
> > ├────────────────┼──────┼────────┤
> > │3 7 jose10 10000│199104│0.183993│
> > ├────────────────┼──────┼────────┤
> > │3 7 jose11 10000│265152│0.174459│
> > ├────────────────┼──────┼────────┤
> > │3 7 jose12 10000│265152│0.173494│
> > ├────────────────┼──────┼────────┤
> > │3 7 jose13 10000│265728│0.181894│
> > ├────────────────┼──────┼────────┤
> > │3 7 jose14 10000│265920│0.180529│
> > ├────────────────┼──────┼────────┤
> > │3 7 jose15 10000│263808│0.180721│
> > └────────────────┴──────┴────────┘
> >
> > This is puzzling to me; then again, I do not know much (to say the least)
> > about the performance of explicit code.
> >
> >
> > --
> Skip Cave
> Cave Consulting LLC
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to