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

Reply via email to