Skip to main content
edited title
Link
Ronald Monson
  • 6.1k
  • 29
  • 47

Use cases for PiecewiseExpand applied to If, Which or SwitchWhich?

added 22 characters in body
Source Link
Ronald Monson
  • 6.1k
  • 29
  • 47

As indicated by its name, PiecewiseExpand's most natural application is to Piecewise expressions but nonetheless, it is still documented as being applicable to (unevaluated) If, Which and Switch expressions. Has anyone ever had any experience of usefully applying PiecewiseExpand to these procedural-like conditionals?

Applications like

Clear@f; f[x_] := Which[ EvenQ@x, "even", LessThan[10]@x, "lessThan10", GreaterThan[20]@x, "greaterThan20"]; PiecewiseExpand[f[x], Assumptions -> x \[Element] Integers] 

enter image description here

don't expand as expected in more general programming contexts whereas PiecewiseExpand's simplifying engine seems more apt in mathematical settings wherein which case Piecewise then seems more natural.

 Clear@f; f[x_] := Piecewise[{ {"even", Mod[x, 2] == 0}, {"lessThan10", x < 10}, {"greaterThan20", x > 20}}]; PiecewiseExpand[f[x], Assumptions -> x \[Element] Integers] 

enter image description here

As indicated by its name, PiecewiseExpand's most natural application is to Piecewise expressions but nonetheless, it is still documented as being applicable to If, Which and Switch expressions. Has anyone ever had any experience of usefully applying PiecewiseExpand to these procedural-like conditionals?

Applications like

Clear@f; f[x_] := Which[ EvenQ@x, "even", LessThan[10]@x, "lessThan10", GreaterThan[20]@x, "greaterThan20"]; PiecewiseExpand[f[x], Assumptions -> x \[Element] Integers] 

enter image description here

don't expand as expected in more general programming contexts whereas PiecewiseExpand's simplifying engine seems more apt in mathematical settings where Piecewise then seems more natural.

 Clear@f; f[x_] := Piecewise[{ {"even", Mod[x, 2] == 0}, {"lessThan10", x < 10}, {"greaterThan20", x > 20}}]; PiecewiseExpand[f[x], Assumptions -> x \[Element] Integers] 

enter image description here

As indicated by its name, PiecewiseExpand's most natural application is to Piecewise expressions but nonetheless, it is still documented as being applicable to (unevaluated) If, Which and Switch expressions. Has anyone ever had any experience of usefully applying PiecewiseExpand to these procedural-like conditionals?

Applications like

Clear@f; f[x_] := Which[ EvenQ@x, "even", LessThan[10]@x, "lessThan10", GreaterThan[20]@x, "greaterThan20"]; PiecewiseExpand[f[x], Assumptions -> x \[Element] Integers] 

enter image description here

don't expand as expected in more general programming contexts whereas PiecewiseExpand's simplifying engine seems more apt in mathematical settings in which case Piecewise then seems more natural.

 Clear@f; f[x_] := Piecewise[{ {"even", Mod[x, 2] == 0}, {"lessThan10", x < 10}, {"greaterThan20", x > 20}}]; PiecewiseExpand[f[x], Assumptions -> x \[Element] Integers] 

enter image description here

Source Link
Ronald Monson
  • 6.1k
  • 29
  • 47

Use cases for PiecewiseExpand applied to If, Which or Switch?

As indicated by its name, PiecewiseExpand's most natural application is to Piecewise expressions but nonetheless, it is still documented as being applicable to If, Which and Switch expressions. Has anyone ever had any experience of usefully applying PiecewiseExpand to these procedural-like conditionals?

Applications like

Clear@f; f[x_] := Which[ EvenQ@x, "even", LessThan[10]@x, "lessThan10", GreaterThan[20]@x, "greaterThan20"]; PiecewiseExpand[f[x], Assumptions -> x \[Element] Integers] 

enter image description here

don't expand as expected in more general programming contexts whereas PiecewiseExpand's simplifying engine seems more apt in mathematical settings where Piecewise then seems more natural.

 Clear@f; f[x_] := Piecewise[{ {"even", Mod[x, 2] == 0}, {"lessThan10", x < 10}, {"greaterThan20", x > 20}}]; PiecewiseExpand[f[x], Assumptions -> x \[Element] Integers] 

enter image description here