# Logical and Piecewise Functions

Nested logical and piecewise functions can be expanded out much like nested arithmetic functions. You can do this using LogicalExpand and PiecewiseExpand.

 LogicalExpand[expr] expand out logical functions in expr PiecewiseExpand[expr] expand out piecewise functions in expr PiecewiseExpand[expr,assum] expand out with the specified assumptions

Expanding out logical and piecewise functions.

LogicalExpand puts logical expressions into a standard disjunctive normal form (DNF), consisting of an OR of ANDs.

By default, the Wolfram Language leaves this expression unchanged.
 In[1]:=
 Out[1]=
LogicalExpand expands this into an OR of ANDs.
 In[2]:=
 Out[2]=

LogicalExpand works on all logical functions, always converting them into a standard OR of ANDs form. Sometimes the results are inevitably quite large.

Xor can be expressed as an OR of ANDs.
 In[3]:=
 Out[3]=

Any collection of nested conditionals can always in effect be flattened into a piecewise normal form consisting of a single Piecewise object. You can do this in the Wolfram Language using PiecewiseExpand.

By default, the Wolfram Language leaves this expression unchanged.
 In[4]:=
 Out[4]=
PiecewiseExpand flattens it into a single Piecewise object.
 In[5]:=
 Out[5]=

Functions like Max and Abs, as well as Clip and UnitStep, implicitly involve conditionals, and combinations of them can again be reduced to a single Piecewise object using PiecewiseExpand.

This gives a result as a single Piecewise object.
 In[6]:=
 Out[6]=
With x assumed real, this can also be written as a Piecewise object.
 In[7]:=
 Out[7]=

Functions like Floor, Mod, and FractionalPart can also be expressed in terms of Piecewise objects, though in principle they can involve an infinite number of cases.

Without a bound on x, this would yield an infinite number of cases.
 In[8]:=
 Out[8]=

The Wolfram Language by default limits the number of cases that the Wolfram Language will explicitly generate in the expansion of any single piecewise function such as Floor at any stage in a computation. You can change this limit by resetting the value of \$MaxPiecewiseCases.