Skip to content

Esta página también está en español.

Léela en español

このページは日本語でも読めます。

日本語で読む

本页也有简体中文版本。

阅读简体中文版本

piecewise function

Cases written value if condition, with an optional otherwise case.

How to write it

piecewise(case, ...)

The first case whose condition holds; end with value otherwise.

case
A value and the condition it holds under, written value if condition. Takes a value with its condition.

Examples

  • subs⁡({xif x>0−xotherwise,x→−3)=3\displaystyle \operatorname{subs}\left(\begin{cases} x & \text{if } x > 0 \\ -x & \text{otherwise} \end{cases}, x \to -3\right) = 3
    subs(piecewise(x if x > 0, -x otherwise), x -> -3)

    In the solver, subs(piecewise(x if x > 0, -x otherwise), x -> -3) gives 3.

    Open in the solver

Functions its examples use

  • subs

    Substitute a rule, or a list of rules, in an expression.

  • pre_decrement

    Subtract 1 from a variable in place and return the new value.

  • indicator

    A condition as a number: 1 when it is true and 0 when it is false.

  • pre_increment

    Add 1 to a variable in place and return the new value.

  • increment

    Add 1 to a variable in place and return its old value.

  • release_hold

    Evaluate an expression that was held.

  • ifelse

    A value chosen by a test.