PiecewiseExpand
Rewrite Abs, Sign, Min, Max, UnitStep, Clip, UnitBox, UnitTriangle and, over a bounded variable, Floor, Ceil, Round, IntegerPart, FractionalPart, Mod, Quotient and the waves inside into Piecewise, recursively. Provided by @enumeratio/analytic.
✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram Language
PiecewiseExpand!PiecewiseExpand(expr)rewrite using whatever is already assumed (e.g. inside an enclosing Assuming).PiecewiseExpand(expr, assumptions)assume (scoped, as in Assuming) for the rewrite, then forget it.Typed signatures
| Type | Package | Applies |
|---|---|---|
(expression, expression?) -> expression | analytic | always |
Details
- Abs, Sign and Argument expand only once their argument is known real — on a genuinely complex value they are not piecewise-comparable, so (matching Wolfram's own
PiecewiseExpand) an argument whose realness isn't established is left untouched rather than guessed at.RealNumbersas the assumption makes every variable real. - Min, Max, UnitStep, Clip, UnitBox and UnitTriangle need no assumption, as in Wolfram: they expand over any symbols. The branches, conditions and default follow Wolfram's: a condition between two unknowns is written
x - y >= 0, one against a constantx <= 2, and a zero-valued branch is the default. What the assumptions decide of a condition is not written (UnitBox(x)on0 < x < 2isx <= 1/2), a branch they rule out goes, and when the branches cover what is left the last one is the default. - Floor, Ceil, Round, IntegerPart, FractionalPart, Mod and Quotient, and SquareWave, TriangleWave and SawtoothWave, expand over an argument bounded on both sides by an assumption, one branch per stretch. The bound is read as an interval:
0 < x < 3, but alsox^2 < 3,0 < 2 x < 5, a constant such asPi, orx < 3 ywith0 < y < 1. The argument is a symbol, linear in one (Floor(2 x)), or over an interval where it is monotone a square or square root of one (Floor(x^2)is bounded bySqrt(2),Sqrt(3)). A modulus, or the multiple in a two-argument Floor, is a positive number, a constant, or a symbol:Mod(k, m)with0 <= k <= 3 mreads the bound as0 <= k/m <= 3and writes its conditions onk/m. The values are written as Wolfram'sTogetherwrites them, in its order. A span of 100 stretches or more is left alone, as Wolfram leaves it. - Rewrites recurse into subexpressions, so
PiecewiseExpand(Abs(x) + 1, …)rewrites theAbsinside the sum. A sum, product or power of Piecewise values, or a Max, Min, Clip or step over them, is one Piecewise: a branch for each combination, values that agree sharing their conditions, a zero value (else the last in Wolfram's order) the default. Conditions that are bounds on one unknown merge into intervals (x <= 0withx >= 0isx == 0, and two intervals that do not touch stay apart asx > 0 || x < 0). A relation is not entered (Wolfram turns a Piecewise inside one into conditions).
Examples
Basic #
The peak, where both branches give 1, goes to the branch left of it when it is right of 0
live ↗InOut
Scope #
Four arguments: a branch wins over the earlier ones strictly, over the later ones on a tie
live ↗InOut
A bound on each unknown by its square: the floor and the round together are one Piecewise
live ↗InOut
A max of absolute values is one Piecewise, each branch carrying the conditions of the pieces it came from
live ↗InOut
live ↗
InOut
Possible issues #
About
| Examples | 64 |
|---|---|
| Checked against | Wolfram Language 60 agree2 differ |
| Crosswalk | Wolfram Language |