Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: BitAnd[True,False]
Replies: 6   Last Post: Sep 27, 2013 2:37 AM

 Messages: [ Previous | Next ]
 Sseziwa Mukasa Posts: 108 Registered: 8/26/07
Re: BitAnd[True,False]
Posted: Sep 26, 2013 3:45 AM

On Sep 25, 2013, at 2:36 AM, Alan <alan.isaac@gmail.com> 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].

Regards,
Sseziwa

Date Subject Author
9/26/13 John Fultz
9/26/13 Alan
9/26/13 Sseziwa Mukasa
9/26/13 Ernst H.K. Stelzer
9/27/13 Itai Seggev