MathGroup Archive 2013

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: BitAnd[True,False]

  • To: mathgroup at
  • Subject: [mg131746] Re: BitAnd[True,False]
  • From: Itai Seggev <itais at>
  • Date: Fri, 27 Sep 2013 02:29:12 -0400 (EDT)
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • References: <>

On Thu, Sep 26, 2013 at 03:44:04AM -0400, Alan G Isaac wrote:
> On 9/25/2013 4:24 AM, John Fultz wrote:
> > I'm not sure why you might have expected this to work. It
> > wouldn't occur to me at all that bitwise operations would
> > have anything to do with logical truth tables (unless
> > those tables were expressed in values of 0 and 1).
> Not expect, but rather hope.  And why?
> Because I would hope bitwise operations would treat
> True and False like 1 and 0. 

There is a function to do this; it is called Boole.

In[127]:= Boole[{True, False}]

Out[127]= {1, 0}

> (E.g., in Python, True
> and False behave this way, since bool is a subtype
> of int.)

That is common in many languages; it is not the case in Mathematica.  For
example, If[1, a,b,c] will return c (neither True nor False), not a, and I
think that is quite correct and useful.  I would quite suprised if some
function decided to treat True the same as 1 without conversion

> Let me put it this way:
> what else might one intend by BitAnd[True,False]?

I would expect it to return an integer, not True or False, given that it is
called BitAnd.

> To AND values in two binary (True,False) matrices,
> I think we must do something like:
> MapThread[And, {m1, m2}, 2]
> Being able to just BitAnd[m1,m2] would be nicer.

> But in any case, thank you for the helpful
> explanation of the behavior that puzzled me.
> Cheers,
> Alan Isaac
Itai Seggev
Mathematica Algorithms R&D

  • Prev by Date: Re: Cyclic generator of a cyclic expression
  • Next by Date: Re: FindFit for a differential equation model with multiple variables
  • Previous by thread: Re: BitAnd[True,False]
  • Next by thread: Cyclic generator of a cyclic expression