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

Reply via email to