MathGroup Archive 2013

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

Search the Archive

Re: BitAnd[True,False]

  • To: mathgroup at
  • Subject: [mg131743] Re: BitAnd[True,False]
  • From: Sseziwa Mukasa <mukasa at>
  • Date: Thu, 26 Sep 2013 03:45:24 -0400 (EDT)
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • References: <>

On Sep 25, 2013, at 2:36 AM, Alan <alan.isaac at> wrote:

> I'd hoped BitAnd would work on Boolean Lists so I gave it a try.  If it had simply failed completely I'd be disappointed but would understand.  But oddly, it half succeeds.  Why? BitOr fails the same way, and BitNot always fails.
> I just want to understand these results.  I know there are ways to get the output I want.
> Thanks,
> Alan Isaac
> (using Mathematica 9)
> In[77]:= BooleanTable[{p,q,BitAnd[p,q]},{p,q}]//TableForm
> Out[77]//TableForm=
> True	True	True
> True	False	BitAnd[False,True]
> False	True	BitAnd[False,True]
> False	False	False

There's a lot going on here. 

To start with BooleanTable[expr,p,q] evaluates the truth value of expr, but {p,q,BitAnd[p,q]} is  not a Boolean function and has no truth value. But BooleanTable's implementation is strange,  it's actually written in Mathematica itself,  try

Trace[BooleanTable[{stuff}, stuff]]

for example.  The upshot of all this is rather than returning BooleanTable[expr,p,q] as most other functions that can't evaluate their arguments BooleanTable[{p,q},p,q] returns the expression with the variables replaced by True or False.  Similarly consider:

(Debug) In[21]:= BooleanTable[expr, p, q]
(Debug) Out[21]= {{expr, expr}, {expr, expr}}

So anyway that's a long winded way of saying BooleanTable's result is already a truth table but the values of the arguments to its first argument are implied and if you want to make a table with columns for the arguments you have to use a different method.

As for the behavior of BitAnd.  First of all it simplifies its arguments so BitAnd[x,x] evaluates to BitAnd[x]:

(Debug) In[52]:= tRACe[BitAnd[x,x]]
(Debug) Out[52]= {BitAnd[x,x],BitAnd[x],x}

Then BitAnd has the property OneIdentity so BitAnd[x] evaluates to x.  Thus BitAnd[True,True]->True.  This has the amusing side effect of meaning BitAnd sometimes will appear to evaluate for arguments of the wrong type, but BitAnd[True,False] is undefined since True and False are not integers which is what BitAnd expects for arguments.  The Orderless attribute results in BitAnd[True,False]->BitAnd[False,True].


  • Prev by Date: Re: Quantity
  • Next by Date: Aspect ratio of bounding box
  • Previous by thread: Re: BitAnd[True,False]
  • Next by thread: Re: BitAnd[True,False]