That is what we have been trying to explain. ;)

That said it is also worth noting that Jose included some deliberate
(though inconsequential) other inefficiencies in his implementation.
Can you spot them?

Thanks,

-- 
Raul


On Mon, Nov 18, 2013 at 12:22 AM, Pascal Jasmin <godspiral2...@yahoo.ca> wrote:
> I think there is a "bug" or needless slowdown in the implicit code 
> interpreter.
>
> before it disapears from my edit bufffers, a slight variation on your code
> a2 =. ( 1e3 $ 2) , 2 1 3 2 4 5 2, 1e1 $ 2
> a =. ( 1e3 $ 2) , 2 1 3 2 4 5 2, 1e5 $ 2
>    ((( $:@:}.)^:(6>:{.))^:_) @: dh :: (_"_)  a2
> 8 5 2 2 2 2 2 2 2 2 2 2 2
>
> while the code does indeed exit after the first match, ^:0 is extremely slow 
> at returning 'y', or dh is extremely slow at amending the head of a long list.
>
> for this version, I don't understand why it does not also break out:
>
>   pD =: 1!:2&2
>
>
>    ({.`}.@.(6>:{.)^:_@:pD@:+:)1 2 1 4 5 2
> 2 4 2 8 10 4
> 8
>
>
>
> ________________________________
> From: Jose Mario Quintana <jose.mario.quint...@gmail.com>
> To: Programming forum <programm...@jsoftware.com>
> Sent: Sunday, November 17, 2013 11:32:06 PM
> Subject: Re: [Jprogramming] repeatuntil and repeat while tacit definitions    
> possible?
>
>
> We can check it out,
>
>     dh=. ([ smoutput)@:(+:@:(0&({::)) 0} ])
>
>     ({.@:((dh @: }.^:(6>:{.)^:_)) @: dh) :: ('None found'"_) 2 1 3 2 4 5 2
> 4 1 3 2 4 5 2
> 2 3 2 4 5 2
> 6 2 4 5 2
> 4 4 5 2
> 8 5 2
> 8
>
> So, v (+: in this case) is evaluated only until the condition is met.  What
> happens is that if the verb v is not really expensive to evaluate or if the
> condition is met near the end, the extra complication is not worth it.
>
> It is too late in the evening now but tomorrow I will elaborate on a direct
> support via a couple of new alternative primitives, stay tuned... ;)
>
>
> On Sun, Nov 17, 2013 at 8:48 PM, Pascal Jasmin <godspiral2...@yahoo.ca>wrote:
>
>> Thank you so much.  A lot of the motivation for the question was hoping to
>> have my thinking expanded.
>>
>> For those following along, the use of 0&{:: is interesting as an
>> alternative to {. because it will generate an error when the list runs out.
>>
>> Your second version advertised as lazy, though, seems to evaluate the
>> whole list (assumption from timings)
>>
>> a =. ( 1e3 $ 2) , 2 1 3 2 4 5 2, 1e5 $ 2
>>
>> a2 =. ( 1e3 $ 2) , 2 1 3 2 4 5 2, 1e1 $ 2
>>
>>
>>    ts '({.@:((dh @: }.^:(6>:{.)^:_)) @: dh) :: (_"_)  a'
>> 0.654649/sec 14.6902MB
>>    ts '({.@:((dh @: }.^:(6>:{.)^:_)) @: dh) :: (_"_)  a2'
>> 275.307/sec 0.149376MB
>>    ts '{.@(}.^:(6>:{.)^:_@: +:)  a2'
>> 637.106/sec 0.137088MB
>>    ts '{.@(}.^:(6>:{.)^:_@: +:)  a'
>> 1.14031/sec 13.6375MB
>>
>>
>> > I have thought that a direct tacit support for this kind of situations
>> would be welcome; I will
>> elaborate more on this subject soon.
>>
>> Would your thoughts be towards a break. function in tacit code?  From your
>> above code, it would seem that generating an error would let us break out.
>>
>>
>> ________________________________
>> From: Jose Mario Quintana <jose.mario.quint...@gmail.com>
>> To: Programming forum <programm...@jsoftware.com>
>> Sent: Sunday, November 17, 2013 7:22:43 PM
>> Subject: Re: [Jprogramming] repeatuntil and repeat while tacit
>> definitions    possible?
>>
>>
>> Pascal Jasmin writes:
>>
>>   But I'd like to see the first before I ask for another, and the approach
>> of
>>   finding them all and then returning the first is not practical.
>>
>> Arie Groeneveld writes:
>>
>>       {.@(}.^:(6>:{.)^:_@: +:) 2 1 3 2 4 5 2
>>
>> 8
>>
>>
>> Presumably "is not practical" because the verb v in the actual application
>> is expensive to compute (+: in the toy example).  However, +: is computed
>> for each of the items of the argument.  If that were the case then the
>> following lazy variation could help,
>>
>>
>>    dh=. +:@:(0&({::)) 0} ]
>>    ({.@:((dh @: }.^:(6>:{.)^:_)) @: dh) :: ('None found'"_) 2 1 3 2 4 5 2
>> 8
>>    ({.@:((dh @: }.^:(6>:{.)^:_)) @: dh) :: ('None found'"_) 2 1 3 2
>> None found
>>
>> Extra code might also be necessary to avoid a potential premature
>> convergence.  Furthermore, for many years I have thought that a direct
>> tacit support for this kind of situations would be welcome; I will
>> elaborate more on this subject soon.
>>
>>
>> On Sun, Nov 17, 2013 at 4:24 AM, Aai <agroeneveld...@gmail.com> wrote:
>>
>> >    $:@}.`{.@.(6<{.) +: 2 1 3 2 4 5 2
>> > 8
>> >
>> > much slower
>> >
>> >    {.@(}.^:(6>:{.)^:_@: +:) 2 1 3 2 4 5 2
>> > 8
>> >
>> > But I prefer Raul's solution.
>> >
>> >
>> >
>> >
>> > On 17-11-13 03:38, Pascal Jasmin wrote:
>> >
>> >> I spent some time describing the application.  You can also think of the
>> >> application as search every web page on every ipv4 until the first
>> >> interesting thing is found.  Maybe I care about a 2nd interesting thing,
>> >> maybe I don't.  But I'd like to see the first before I ask for another,
>> and
>> >> the approach of finding them all and then returning the first is not
>> >> practical.
>> >>
>> >> The explicit version I provided is not unworkable.  I was hoping that
>> >> there is a version with {. and $:@:}.
>> >>
>> >>
>> >> ----- Original Message -----
>> >> From: Raul Miller <rauldmil...@gmail.com>
>> >> To: Programming forum <programm...@jsoftware.com>
>> >> Cc:
>> >> Sent: Saturday, November 16, 2013 8:56:03 PM
>> >> Subject: Re: [Jprogramming] repeatuntil and repeat while tacit
>> >> definitions      possible?
>> >>
>> >>     ({~ 1 i.~ 6 < ]) +: 2 1 3 2 4 5 2
>> >> 8
>> >>     ({.~ 1 i.~ 6 < ]) +: 2 1 3 2 4 5 2
>> >> 4 2 6 4
>> >>
>> >> Now you might argue that this is not the same thing. But it is the same
>> >> result.
>> >>
>> >> It's just faster to compute this way. And, ok, I understand that speed
>> >> is not necessarily desirable. But I think in this case you might want
>> >> to just use a different language.
>> >>
>> >>
>> > --
>> > Met vriendelijke groet,
>> > @@i = Arie Groeneveld
>> >
>> >
>> > ----------------------------------------------------------------------
>> > 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to