Discord

INAIO Guide Stage 1 3Functions and Graphs

3.5 Piecewise and indicator functions

Choose the right rule on each interval and use zero-one indicators to express a condition.

One formula does not always describe a whole situation. A delivery price may change after a weight limit, and a classifier may switch its decision at a score threshold. A piecewise function records the rule for each range of inputs. An indicator function records whether one condition is true.

This is intermediate work built on functions and Module 2.4's inequality boundaries. OpenStax's piecewise-function examples explain how to read the intervals. Penn State's indicator-variable introduction shows why zero-one rules are useful in data work.

A basic idea: test the condition first

Consider

f(x)={x+1x<2,5x≥2.f(x)= \begin{cases} x+1 & x<2,\\ 5 & x\ge2. \end{cases}

To find f(1)f(1), use the first line and get 22. To find f(2)f(2), use the second line and get 55. The equality sign at the boundary decides which branch owns x=2x=2. On a graph, an open circle marks an excluded endpoint; a filled circle marks an included one.

A quick tour of rules

A piecewise rule must say where each formula applies. If two branches apply to the same input but give different values, it is not a well-defined function there. If no branch applies, the function is undefined at that input. Always test the boundaries explicitly.

The indicator of a condition AA is

1{A}={1if A is true,0if A is false.\mathbf{1}\{A\}= \begin{cases} 1 & \text{if }A\text{ is true},\\ 0 & \text{if }A\text{ is false}. \end{cases}

For a threshold cc, 1{x≥c}\mathbf{1}\{x\ge c\} is 00 below cc and 11 at or above it. A sum of indicators counts how many conditions hold: if three scores are 0.620.62, 0.700.70, and 0.810.81, then ∑i=131{si≥0.70}=2\sum_{i=1}^{3}\mathbf{1}\{s_i\ge0.70\}=2.

A step graph of the indicator of score at least 0.70. It is zero below 0.70, with an open circle at the boundary, and one from 0.70 onward, with a filled circle at the boundary.A step graph of the indicator of score at least 0.70. It is zero below 0.70, with an open circle at the boundary, and one from 0.70 onward, with a filled circle at the boundary.
The filled point shows that a score exactly equal to the threshold counts as true.

You can also use an indicator inside a larger formula. For example, 20+3(w−2)1{w>2}20+3(w-2)\mathbf{1}\{w>2\} adds an extra charge only when ww exceeds 22. Read the condition before calculating the product.

Application 1: a shipping rule

A parcel costs 2020 units to ship if it weighs at most 22 kg. Above 22 kg, the cost rises by 33 units per kilogram over 22 kg. What do parcels of 22 kg and 55 kg cost?

  1. Write both branches. C(w)=20C(w)=20 for 0<w≤20<w\le2, and C(w)=20+3(w−2)C(w)=20+3(w-2) for w>2w>2.
  2. Check the boundary. Since 22 belongs to the first branch, C(2)=20C(2)=20.
  3. Use the other branch. For w=5w=5, the extra weight is 5−2=35-2=3 kg, so C(5)=20+3(3)=29C(5)=20+3(3)=29.

The rule changes at 22 kg, but the price does not jump there: the second formula approaches 2020 as ww approaches 22 from above.

Application 2: counting flagged messages

A filter flags a message when its score is at least 0.700.70. Four messages have scores 0.690.69, 0.700.70, 0.720.72, and 0.310.31. How many are flagged, and what happens at the exact threshold?

  1. Write the decision. For score ss, let F(s)=1{s≥0.70}F(s)=\mathbf{1}\{s\ge0.70\}.
  2. Evaluate each score. The outputs are 0,1,1,00,1,1,0. The score 0.700.70 is included because the condition uses ≥\ge.
  3. Add the indicators. 0+1+1+0=20+1+1+0=2 messages are flagged.

The same indicator can be used for every message; summing its outputs turns individual yes-or-no decisions into a count.

Resources

SourceTitleWhy read it
OpenStaxDomain, range, and piecewise functionsLearn how to evaluate and graph different rules on different intervals.
Penn StateThe basics of indicator variablesSee how a yes-or-no condition can be encoded as 1 or 0.

Finished this module? Mark it done.

Comments

Stuck on something, spotted a mistake, or found a resource that helped you? Tell us below.

Loading comments