Sub topic 10
Conditional and Piecewise Definitions
Assume you know order of operations, integer and fractional arithmetic, exponents, and basic algebra. This chapter focuses on definitions that use different rules for different inputs.
A conditional definition assigns an output by first checking a condition. A piecewise function is a function written with several rules, where each rule applies only on a specified part of the input set.
Choose the Rule Before Calculating
Consider the function
f(x)=
\begin{cases}
x+4 & \text{if } x<2\\
x^2-1 & \text{if } x\ge 2
\end{cases}The condition determines which formula you use.
- If \(x=0\), then \(0<2\), so use \(x+4\). Thus, \(f(0)=4\).
- If \(x=3\), then \(3\ge2\), so use \(x^2-1\). Thus, \(f(3)=8\).
- Do not calculate both formulas and choose the more convenient result. Only one rule applies.
The boundary condition matters. The first rule excludes \(x=2\), while the second rule includes it.
| Input | Condition that applies | Calculation | Output |
|---|---|---|---|
| \(0\) | \(x<2\) | \(0+4\) | 4 |
| \(2\) | \(x\ge2\) | \(2^2-1\) | 3 |
| \(3\) | \(x\ge2\) | \(3^2-1\) | 8 |
A Reliable Evaluation Routine
For any conditional definition:
- Identify the input.
- Test the input against each condition.
- Select exactly one rule.
- Substitute the input into that rule.
- Apply order of operations.
- Check that the selected condition was actually true.
This routine prevents a common mistake: substituting into a formula before deciding whether that formula applies.
The following function uses parity, which means whether an integer is even or odd:
f(x)=
\begin{cases}
x/2 & \text{if }x\text{ is even}\\
3x+1 & \text{if }x\text{ is odd}
\end{cases}For \(f(3)\), 3 is odd, so use \(3x+1\):
f(3)=3(3)+1=10.For \(f(10)\), 10 is even, so use \(x/2\):
f(10)=10/2=5.def f(x):
# Apply one rule based on whether x is even or odd.
return x // 2 if x % 2 == 0 else 3 * x + 1
print(f(3)) # 10
print(f(f(3))) # 5Nested Conditional Operations
In \(f(f(3))\), evaluate the inner function first.
- The inner input is 3. Since 3 is odd, \(f(3)=10\).
- The outer input is now 10. Since 10 is even, \(f(10)=5\).
- Therefore, \(f(f(3))=5\).
The rule may change between steps. Never assume that the rule used for the original input also applies to the new output.
A piecewise function can also be nested inside a made-up operation. Suppose
a\star b=2a+b^2and \(f\) is the conditional function above. To find \(f(2\star3)\):
2\star3=2(2)+3^2=13.Since 13 is odd, use the odd rule:
f(13)=3(13)+1=40.The order is therefore:
- Evaluate the operation.
- Test the resulting value.
- Apply the matching conditional rule.
Common Errors and GRE Checks
Watch for these errors:
- Using the standard meaning of a symbol: A problem-defined operation replaces the usual meaning of that symbol.
- Ignoring the condition: A formula is valid only where its condition says it is valid.
- Dropping parentheses: In \(3x+1\), substitute the entire value for \(x\), especially when it is negative.
- Using the original rule in a nested expression: Recheck the new output.
- Confusing integer division with ordinary division: In a mathematical definition, \(x/2\) may produce a fraction unless the problem states otherwise.
For a GRE question, write the condition beside the input before doing arithmetic. Then use a quick reverse check: verify that the input satisfies the selected condition and that no other condition should have been used.
Exercise
Define f(x) = x - 2 if x ≥ 5, and f(x) = 2x + 1 if x < 5. Find f(f(4)).
Show answer
Since 4 < 5, f(4) = 2(4) + 1 = 9. Since 9 ≥ 5, f(9) = 9 - 2 = 7. Therefore, f(f(4)) = 7.