Function Repository Resource:

InverseBoole

Source Notebook

Inverse of the Boole function

Contributed by: Daniel Sanchez (Wolfram Research)

ResourceFunction["InverseBoole"][expr]

yields True if expr is 1 and False if it is 0.

Details and Options

ResourceFunction["InverseBoole"][expr] remains unchanged if expr is neither 1 nor 0.
ResourceFunction["InverseBoole"][expr] is effectively equivalent to Switch[expr,1,True,0,False].
ResourceFunction["InverseBoole"] is Listable.

Examples

Basic Examples (2) 

In[1]:=
{ResourceFunction["InverseBoole"][0], ResourceFunction["InverseBoole"][1]}
Out[1]=

Convert a List of 1's and 0's to truth values:

In[2]:=
ResourceFunction["InverseBoole"][{1, 0, 1, 1, 0}]
Out[2]=

Applications (1) 

InverseBoole is particularly useful when testing a condition based on bit values:

In[3]:=
If[ResourceFunction["InverseBoole"]@
  BitGet[2^^1000000, 6], "one", "zero"]
Out[3]=

Properties and Relations (2) 

InverseBoole is the inverse function of Boole:

In[4]:=
ResourceFunction["InverseBoole"][Boole[{True, False}]]
Out[4]=

InverseBoole deals with Rule just like Boole:

In[5]:=
Boole[a -> True]
Out[5]=
In[6]:=
ResourceFunction["InverseBoole"][a -> 0]
Out[6]=

Possible Issues (3) 

Only one argument is expected:

In[7]:=
ResourceFunction["InverseBoole"][]
Out[7]=
In[8]:=
ResourceFunction["InverseBoole"][3, 3]
Out[8]=

If the sole argument provided is neither 1 nor 0, the expression is not evaluated:

In[9]:=
If[ResourceFunction[
  "InverseBoole"][\[Pi]], "if branch", "else branch"]
Out[9]=

If the argument is a numeric value, use Unitize together with InverseBoole:

In[10]:=
If[ResourceFunction["InverseBoole"][
  Unitize@\[Pi]], "if branch", "else branch"]
Out[10]=

Publisher

Daniel Sanchez

Version History

  • 1.0.0 – 24 August 2020

License Information