Logical and Piecewise Functions

Nested logical and piecewise functions can be expanded out much like nested arithmetic functions. You can do this using (RefLink[LogicalExpand, paclet:ref/LogicalExpand]) and (RefLink[PiecewiseExpand, paclet:ref/PiecewiseExpand]).

Expanding out logical and piecewise functions.

(RefLink[LogicalExpand, paclet:ref/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:

(a||b)&&c

(RefLink[LogicalExpand, paclet:ref/LogicalExpand]) expands this into an OR of ANDs:

LogicalExpand[%]

(RefLink[LogicalExpand, paclet:ref/LogicalExpand]) works on all logical functions, always converting them into a standard OR of ANDs form. Sometimes the results are inevitably quite large.

(RefLink[Xor, paclet:ref/Xor]) can be expressed as an OR of ANDs:

LogicalExpand[Xor[a,b,c]]

Any collection of nested conditionals can always in effect be flattened into a piecewise normal form consisting of a single (RefLink[Piecewise, paclet:ref/Piecewise]) object. You can do this in the Wolfram Language using (RefLink[PiecewiseExpand, paclet:ref/PiecewiseExpand]).

By default, the Wolfram Language leaves this expression unchanged:

If[x>0,If[x<1,a,b],c]

(RefLink[PiecewiseExpand, paclet:ref/PiecewiseExpand]) flattens it into a single (RefLink[Piecewise, paclet:ref/Piecewise]) object:

PiecewiseExpand[%]

Functions like (RefLink[Max, paclet:ref/Max]) and (RefLink[Abs, paclet:ref/Abs]), as well as (RefLink[Clip, paclet:ref/Clip]) and (RefLink[UnitStep, paclet:ref/UnitStep]), implicitly involve conditionals, and combinations of them can again be reduced to a single (RefLink[Piecewise, paclet:ref/Piecewise]) object using (RefLink[PiecewiseExpand, paclet:ref/PiecewiseExpand]).

This gives a result as a single (RefLink[Piecewise, paclet:ref/Piecewise]) object:

PiecewiseExpand[Max[Min[a,b],c]]

With x assumed real, this can also be written as a (RefLink[Piecewise, paclet:ref/Piecewise]) object:

PiecewiseExpand[Abs[x],x ∈ Reals]

Functions like (RefLink[Floor, paclet:ref/Floor]), (RefLink[Mod, paclet:ref/Mod]), and (RefLink[FractionalPart, paclet:ref/FractionalPart]) can also be expressed in terms of (RefLink[Piecewise, paclet:ref/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:

PiecewiseExpand[Floor[x^2],0<x<2]

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 (RefLink[Floor, paclet:ref/Floor]) at any stage in a computation. You can change this limit by resetting the value of (RefLink[$MaxPiecewiseCases, paclet:ref/$MaxPiecewiseCases]).