[Jprogramming] math requests
Dan Bron
j at bron.us
Mon Feb 3 16:30:01 UTC 2014
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 <rauldmiller at gmail.com>
Date: Mon, 3 Feb 2014 10:49:20 -0500
To: Programming forum <programming at 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 at 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 <rauldmiller at gmail.com>
> Date: Mon, 3 Feb 2014 09:44:15 -0500
> To: Programming forum <programming at 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 <godspiral2000 at 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
More information about the Programming
mailing list