>  Why would I want to avoid using #: ?

I dunno.  Same reason the b. functions were introduced even though we
already had *. and +. and < etc? 

> If it's for performance reasons, I might be tempted to take the
> performance critical code and translate and compile it in some other
> language, then use the cd mechanism to bring it in to work with the
> rest of my code.

I agree this is a valid approach, but given the development overhead as
well as resultant complexity (another dependency, another moving part), I
would reserve it for the most extreme cases.  Antyhing short of that, I'd
seek out the most efficient way to express it in J.  After all, that's why
I'm using J.  If I end up writing a good body of code in another language
for a particular project, I'd have to reconsider the value of J for that
project.

So, the question still stands: are there "reduction" or "moving window" or
"running" analogs to the bitwise functions provided by b. ?  Given the
direction this thread has taken, I'm guessing not, but I'd be happy to be
proven wrong.

-Dan


----- Original Message ---------------

Subject: Re: [Jprogramming] math requests
   From: Raul Miller <rauldmil...@gmail.com>
   Date: Mon, 3 Feb 2014 11:36:58 -0500
     To: Programming forum <programm...@jsoftware.com>

Why would I want to avoid using #: ?

If it's for performance reasons, I might be tempted to take the
performance critical code and translate and compile it in some other
language, then use the cd mechanism to bring it in to work with the
rest of my code.

But here's another way of defining leftmostBit:

leftmostBit=: 2 ^ 2 <.@^. ]

    (2 ^ 2 <.@^. ]) 2222222222222222222222222222222222222222x
1361129467683753853853498429727072845824

(that's 2^130x)

Thanks,

-- 
Raul

On Mon, Feb 3, 2014 at 11:30 AM, Dan Bron <j...@bron.us> wrote:
> That's a useful edge-case to be aware of, thank you.  Any comments on how
> to express </\ (or *./\ or some boolean function/\ ) without actually
> having to use #: ?
>
> -Dan
>
> ----- Original Message ---------------
>
> Subject: Re: [Jprogramming] math requests
>    From: Raul Miller <rauldmil...@gmail.com>
>    Date: Mon, 3 Feb 2014 10:49:20 -0500
>      To: Programming forum <programm...@jsoftware.com>
>
> First, let's acknowledge that 17 b. seems to work just fine as bitwise and:
>
>    17 b./~i.4x
> 0 0 0 0
> 0 1 0 1
> 0 0 2 2
> 0 1 2 3
>
> However:
>    17 b./~ 2222222222222222222222222222222222222222x
>
> it seems that 17 b. runs into problems with large integers.
>
> Thanks,
>
> --
> Raul
>
>
> On Mon, Feb 3, 2014 at 10:25 AM, Dan Bron <j...@bron.us> wrote:
>> We can express bitwise < (y and not x) as 20 b. . Is there a way to express
>> bitwise </\ using b. ? Or, in general, without actually having to explode
>> an integer into its component bits, and then reassemble them?
>>
>> -Dan
>>
>> ----- Original Message ---------------
>>
>> Subject: Re: [Jprogramming] math requests
>>    From: Raul Miller <rauldmil...@gmail.com>
>>    Date: Mon, 3 Feb 2014 09:44:15 -0500
>>      To: Programming forum <programm...@jsoftware.com>
>>
>> I am going over the messages in this thread slowly, because this
>> subject requires some thought. But that also means that some of my
>> responses in this thread will appear slowly.
>>
>> Anyways:
>>
>> On Thu, Jan 30, 2014 at 1:02 PM, Pascal Jasmin <godspiral2...@yahoo.ca>
>> wrote:
>>> http://repl.it/languages/Python is a useful resource for figuring out 
>>> python code.  But here is the only part I had trouble understanding:
>>>
>>> leftmostbit =: 2&#.@:({. , 0 $~ 2 -~ #)@:(2&#. inv) NB. for some reason 
>>> divides msb by 2.
>>
>> Here was the version I came up with:
>>
>>    leftmostBit=: </\&.#:
>>
>> If I compare this to the python code:
>>
>>     def leftmost_bit( x ):
>>       assert x > 0
>>       result = 1
>>       while result <= x: result = 2 * result
>>       return result // 2
>>
>> The python variable 'result' is indeed divided by 2 (// in python is
>> like <.@% in J), but notice that there's an extra 2 * result in the
>> loop when result is equal to x.
>>
>> Example use:
>>    leftmostBit"0 i.10
>> 0 1 2 2 4 4 4 4 8 8
>>
>> And here's the comparable python (leaving out 0 because of the assert):
>>    [leftmost_bit(x) for x in range(1,10)]
>> [1, 2, 2, 4, 4, 4, 4, 8, 8]
>>
>> Anyways, python is a bit quirky (but maybe that is a characteristic of
>> any computer system), but inspecting the data can work there just as
>> it can work in J.
>>
>> Thanks,
>>
>> --
>> Raul
>> ----------------------------------------------------------------------
>> 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