Actually, having a changing item, for example a counter, might be sometimes
advantageous since a verb ( u^:v^:_)  can also terminate even if v is 1
(true) when u converges (that is, if the result of u matches its previous
result) which could have adverse unintended consequences (Henry, I know you
know).  The presence of a counter would prevent a premature convergence of
( u^:v^:_).  (In addition, as Bo suggested, a bounded while can be easily
implemented by modifying the controlling condition (v) accordingly.)

This is a direct transcription of Kip's exp verb following Henry's outline:

   Exp("0) 1 0j1p1
2.71828 _1

     ( Exp=. (clean o (S f)) o (update w (S f ~: OS f)) o ((0;1;0;1) ;~ ])
f. )
(* *!.1e_14@|)"0&.+.@:(2&({::))@:((<@:(2&({::) + 4&({::)) 2}
])@:((<@:(4&({::) * 0&({::) % 3&({::)) 4} ])@:((<@:(>:@:(3&({::))) 3}
])@:(<@:(2&({::)) 1} ])))^:(2&({::) ~: 1&({::))^:_)@:((0;1;0;1) ;~ ])

where,

   u w v
u^:v^:_

the corresponding condition to (s ~: os) is the verb,

   (S f ~: OS f)
2&({::) ~: 1&({::)

and the updating verb is,

   update
(<@:(2&({::) + 4&({::)) 2} ])@:((<@:(4&({::) * 0&({::) % 3&({::)) 4}
])@:((<@:(>:@:(3&({::))) 3} ])@:(<@:(2&({::)) 1} ])))

On the one hand, this particular tacit verb is at disadvantage vs its
explicit counterpart regarding speed for the same reason the explicit verb
would be at disadvantage to a FORTRAN or C counterpart: overhead (both
verbs are operating with tiny pieces, as oppose to large chunks, of data).
On the other hand, it illustrates the general method to iterate tacitly
(and, I hope, it provides an answer to Kip's question in particular) not to
mention that, in principle, any computable task can be reduced to that
form; namely, a verb with at most a single, possibly open ended,
iteration.

Moreover, one does not even have to take into account the underlying
meaning of the explicit verb to transcribe it and it is often an effortless
process.  Here is how I wrote the tacit verb:

   set'Y OS S K T'
0 1 2 3 4

   update=. [tv
  OS h( S f )
  K  h( >: o (K f) )
  T  h( T f * Y f % K f )
  S  h( S f + T f )
)

   ( Exp=. (clean o (S f)) o (update w (S f ~: OS f)) o ((0;1;0;1) ;~ ]) f.
)
(* *!.1e_14@|)"0&.+.@:(2&({::))@:((<@:(2&({::) + 4&({::)) 2}
])@:((<@:(4&({::) * 0&({::) % 3&({::)) 4} ])@:((<@:(>:@:(3&({::))) 3}
])@:(<@:(2&({::)) 1} ])))^:(2&({::) ~: 1&({::))^:_)@:((0;1;0;1) ;~ ])

See http://www.2bestsystems.com/j/J_Conference_2012.rtf for more insights.
Otherwise, here are some hints:

   o
@:

   N f
N&({::)

   N h u
<@:u N} ]

   [tv
  u0
  u1
  u2
  u3
)
u3@:(u2@:(u1@:u0))
I hope it helps.
PS. I just noticed  (I was writing this while watching the (American)
football games) Dan's message that follows a very similar approach but it
will not hurt to reiterate ;)


On Sun, Dec 22, 2013 at 11:18 AM, Henry Rich <[email protected]> wrote:

> I can't figure out a pleasing way to do this.  You need 4 things: k,s,y,t.
>  3 of these change.  So, you need to join them as a boxed list and then
> iterate, but you can't iterate until they stop changing, because the
> iteration number always changes.  t also changes.  Yuck.
>
> Henry Rich
>
>
>
> On 12/22/2013 3:27 AM, km wrote:
>
>> Thanks, Raul, for a cool solution.  I'm still interested in tacitly
>> terminating a series when its partial sums stop changing.  --Kip
>>
>> Sent from my iPad
>>
>>  On Dec 22, 2013, at 12:34 AM, Raul Miller <[email protected]> wrote:
>>>
>>>    ^ 2
>>> 7.38906
>>>    (%!i.40) p. 2
>>> 7.38906
>>>    (^ =  (%!i.40)&p.) 0j1p1
>>> 1
>>>
>>> I'd just use ^
>>>
>>> --
>>> Raul
>>>
>>>  On Sat, Dec 21, 2013 at 5:43 PM, km <[email protected]> wrote:
>>>> Verb  exp  below uses the series for monadic  ^  to calculate  ^ y .
>>>>  Can you remind me how to do  exp  tacitly?  You may omit the  "clean"
>>>>  part.  Verb  clean  replaces tiny real numbers by 0 .
>>>>
>>>>    clean =: (* *!.1e_14@|)"0&.+.
>>>>
>>>>    exp =: 3 : 0
>>>>   os =. 0
>>>>    s =. 1
>>>>    k =. 0
>>>>    t =. 1
>>>> while. s ~: os do.
>>>>   os =. s
>>>>    k =. >: k
>>>>    t =. t * y % k
>>>>    s =. s + t
>>>> end.
>>>> clean s
>>>> )
>>>>
>>>>    exp 1
>>>> 2.71828
>>>>
>>>>    ^1
>>>> 2.71828
>>>>
>>>>    exp 0j1p1
>>>> _1
>>>>
>>>>    ^ 0j1p1
>>>> _1j1.22465e_16
>>>>
>>>>    (^0j1p1) = exp 0j1p1
>>>> 1
>>>>
>>>>    VERSION  NB. iPad
>>>> 1.3 5
>>>>
>>>> --Kip Murray
>>>>
>>>> Sent from my iPad
>>>>
>>>> ----------------------------------------------------------------------
>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>>
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>>  ----------------------------------------------------------------------
> 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