Function Repository Resource:

BooleInverse

Source Notebook

Inverse of the Boole function

Contributed by: Daniel Sanchez (Wolfram Research)

ResourceFunction["BooleInverse"][expr]

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

Details and Options

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

Examples

Basic Examples (2) 

Apply BooleInverse to a 0 and a 1:

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

Convert a list of 1s and 0s to truth values:

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

Applications (1) 

BooleInverse is useful when testing a condition based on bit values:

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

Properties and Relations (3) 

BooleInverse[expr] is effectively equivalent to Switch[expr,1,True,0,False]:

In[4]:=
{ResourceFunction["BooleInverse"][#], Switch[#, 1, True, 0, False]} & /@ {1, 0, 1, 1, 0}
Out[4]=

BooleInverse is the inverse function of Boole:

In[5]:=
ResourceFunction["BooleInverse"][Boole[{True, False}]]
Out[5]=

BooleInverse deals with Rule in the same way that Boole does:

In[6]:=
Boole[a -> True]
Out[6]=
In[7]:=
ResourceFunction["BooleInverse"][a -> 0]
Out[7]=

Possible Issues (2) 

Only one argument is expected:

In[8]:=
ResourceFunction["BooleInverse"][]
Out[8]=
In[9]:=
ResourceFunction["BooleInverse"][3, 3]
Out[9]=

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

In[10]:=
ResourceFunction["BooleInverse"][3]
Out[10]=

Publisher

Daniel Sanchez

Version History

  • 1.0.0 – 12 August 2020

Related Resources

License Information