Sub topic 10
Conditional and Piecewise Definitions
This chapter assumes you can substitute values into a defined operation, evaluate nested expressions from the inside out, and solve one-variable linear equations. It also assumes you are comfortable with even and odd integers and with inequalities such as x < 3 and x ≥ 3.
What a conditional definition is
So far, each made-up operation has been a single formula, such as a★b = 2a + b². A conditional definition gives two or more formulas. Each formula comes with a condition that says when it applies. Textbooks call this a piecewise definition, because the rule is built from pieces.
GRE questions usually write it in one of these forms:
- f(x) = x/2 if x is even, and f(x) = 3x + 1 if x is odd.
- g(x) = 2x + 1 for x < 3, and g(x) = x² − 4 for x ≥ 3.
- a◆b = a² if a > b, and 3b otherwise.
The definition is still a function. Each valid input produces exactly one output. The only new step is deciding which piece applies before you compute anything.
The core procedure: decide the case, then compute
- Read the conditions and confirm they cover every input without overlapping. "Otherwise" or "if x is odd" after "if x is even" counts as covering the rest.
- Substitute the input into the condition only, and decide which one is true.
- Apply the formula that belongs to that condition. Ignore the other formulas.
- If the expression is nested, repeat steps 2 and 3 at each layer.
Here is the parity example from the plan. The function halves even inputs and sends odd inputs to 3x + 1.
def f(x):
# f(x) = x/2 if x is even, 3x + 1 if x is odd
return x // 2 if x % 2 == 0 else 3 * x + 1
print(f(3)) # odd: 3*3 + 1 = 10
print(f(f(3))) # f(10): even, so 5The input 3 is odd, so the output is 10. For the outer layer, the input is now 10, which is even. The rule changed between layers, and that is typical of GRE questions. You cannot decide the case once and reuse it.
Boundaries: where the condition changes
When the condition is an inequality, the most common errors happen at the boundary value. Pay attention to whether the inequality is strict (<, >) or includes equality (≤, ≥).
Take g(x) = 2x + 1 for x < 3, and g(x) = x² − 4 for x ≥ 3. At x = 3 the condition x < 3 is false, so you use the second formula. The first formula would give 7, but the correct value is 5.
def g(x):
# g(x) = 2x + 1 if x < 3, otherwise x**2 - 4
return 2 * x + 1 if x < 3 else x ** 2 - 4
print(g(2)) # 2*2 + 1 = 5
print(g(3)) # boundary: x < 3 is false, so 9 - 4 = 5
print(g(4)) # 16 - 4 = 12
print(g(-2)) # 2*(-2) + 1 = -3
print(g(2.5)) # 2*2.5 + 1 = 6.0The two pieces do not have to agree at the boundary. Here the first piece would give 7 at x = 3 and the second gives 5, so the function jumps there. Nothing in the definition forces the pieces to match, and GRE writers sometimes choose a jump on purpose to catch learners who use the wrong piece.
Negative and fractional inputs in conditions
The conditions interact with signs and fractions in a few ways.
- Negative numbers can be even or odd. −4 is even and −3 is odd. Zero is even.
- "Even" and "odd" only apply to integers. If a definition says "x/2 if x is even, 3x + 1 if x is odd", the input 1.5 is outside the domain. On the GRE, such a definition will be paired with integer inputs.
- Comparisons with negatives need care. −5 < 3 is true, but −5 > −2 is false.
- Substitute negatives in parentheses before squaring: (−3)² = 9, not −9.
Checking g(−2) above shows the pattern. The condition −2 < 3 holds, so use 2x + 1 with x = −2 in parentheses: 2(−2) + 1 = −3.
Conditional rules inside made-up symbols
The same idea applies to two-input operations. Define a◆b = a² if a > b, and a◆b = 3b otherwise. The condition now compares the two inputs, and that comparison depends on argument order.
def diamond(a, b):
# a diamond b = a**2 if a > b, otherwise 3*b
return a ** 2 if a > b else 3 * b
print(diamond(3, 5)) # 3 > 5 is false, so 3*5 = 15
print(diamond(5, 3)) # 5 > 3 is true, so 5**2 = 25
print(diamond(4, 4)) # 4 > 4 is false, so 3*4 = 12Three results are worth noticing:
- 3◆5 and 5◆3 differ, so this operation is not commutative.
- The tie case 4◆4 falls into "otherwise", because the condition is a strict inequality.
- In each evaluation, only one formula is ever used.
For a nested expression such as (3◆5)◆2, evaluate the inner operation first. 3◆5 = 15. Then 15◆2 compares 15 > 2, which is true, so the result is 15² = 225.
Nesting with conditions
In a nested or composed expression, the case can change at every layer. Take h(x) = 2x + 1 for x < 3, and h(x) = x² − 4 for x ≥ 3 (the same function as g above). Evaluate h(h(2)) and h(h(4)).
def h(x):
return 2 * x + 1 if x < 3 else x ** 2 - 4
print(h(h(2))) # h(2) = 5; 5 >= 3, so h(5) = 25 - 4 = 21
print(h(h(4))) # h(4) = 12; 12 >= 3, so h(12) = 144 - 4 = 140
print(h(h(-2))) # h(-2) = -3; -3 < 3, so h(-3) = -5Writing each intermediate value on scratch paper is worth the few seconds. Each time you finish one layer, write the number and then state which condition it meets.
You can extend the earlier parity function the same way. Repeated application of f from 3 goes 3 → 10 → 5 → 16. The chain alternates between the two pieces, and you must check parity at every step.
def f(x):
return x // 2 if x % 2 == 0 else 3 * x + 1
x = 3
chain = [x]
for _ in range(3):
x = f(x)
chain.append(x)
print(chain) # [3, 10, 5, 16]Solving for an unknown input
When the output is given and the input is unknown, you do not know which case applies. The standard method is to solve each piece separately, then check each answer against that piece's own condition. A solution only counts if it satisfies the condition of the formula that produced it.
Suppose f(x) = x/2 if x is even, and f(x) = 3x + 1 if x is odd. Find all x with f(x) = 10.
- Even case: x/2 = 10 gives x = 20. It is even, so it is valid.
- Odd case: 3x + 1 = 10 gives x = 3. It is odd, so it is valid.
Both pieces produce a valid answer, so f(x) = 10 has two solutions: 3 and 20.
Now find all x with f(x) = 7.
- Even case: x/2 = 7 gives x = 14. It is even, so it is valid.
- Odd case: 3x + 1 = 7 gives x = 2. It is not odd, so it is rejected.
Only 14 works. The rejected value is a trap answer: f(2) = 1, not 7.
def f(x):
return x // 2 if x % 2 == 0 else 3 * x + 1
print([x for x in range(-50, 51) if f(x) == 10]) # [3, 20]
print([x for x in range(-50, 51) if f(x) == 7]) # [14]The brute-force search is a good way to check your hand work. On the real exam you do the same check mentally by testing the rejected candidate in the original definition.
For inequality conditions, the check works the same way. Suppose g(x) = 2x + 1 for x < 3, and g(x) = x² − 4 for x ≥ 3, and g(x) = 12. The first piece gives 2x + 1 = 12, so x = 5.5, which fails x < 3. The second gives x² = 16, so x = 4 or x = −4. Of these, 4 satisfies x ≥ 3 and −4 does not. The only solution is x = 4.
Common errors
| Error | Example | Correction |
|---|---|---|
| Using the wrong piece at a boundary | Using 2x + 1 at x = 3 when the condition is x < 3 | Test the inequality with the exact value |
| Deciding the case once for a nested expression | Treating f(f(3)) as two odd steps | Re-check the condition at every layer |
| Accepting a solution that fails its own condition | Taking x = 2 from 3x + 1 = 7 | Substitute back and check parity or inequality |
| Dropping solutions from the other piece | Stopping after the even case | Solve every piece, then filter |
| Treating a tie as "greater" | Using a² for 4◆4 when the condition is a > b | A strict inequality is false when the values are equal |
| Losing the sign when squaring | Writing −3² as −9 | Substitute negatives in parentheses |
A checking routine for conditional definitions
- Write the conditions next to their formulas so you can see all pieces at once.
- Evaluate the condition first. Write "true" or "false" next to it.
- Compute with the chosen formula only.
- For unknowns, solve every piece, then substitute each candidate into its own condition.
- As a final sanity check, plug your answer into the original definition and confirm you get the target value.
Exercise
Define k(x) = 3x − 2 if x ≤ 4, and k(x) = x² − 10 if x > 4. Find k(k(4)) and all x such that k(x) = 26.
Show answer
First, k(4): 4 ≤ 4 is true, so k(4) = 3(4) − 2 = 10. Then k(10): 10 > 4, so k(10) = 100 − 10 = 90. So k(k(4)) = 90. For k(x) = 26, solve each piece. Piece 1: 3x − 2 = 26 gives x = 28/3, which is about 9.33. It fails x ≤ 4, so reject it. Piece 2: x² − 10 = 26 gives x² = 36, so x = 6 or x = −6. The value 6 satisfies x > 4. The value −6 does not, so reject it. The only solution is x = 6.
Exercise
Define a◆b = a² if a > b, and a◆b = 3b otherwise. Evaluate (2◆5)◆4, and then decide whether the operation is commutative using the inputs 2 and 5.
Show answer
Inner operation: 2 > 5 is false, so 2◆5 = 3(5) = 15. Outer operation: 15◆4 compares 15 > 4, which is true, so the result is 15² = 225. For commutativity, 2◆5 = 15 but 5◆2 has 5 > 2 true, so 5◆2 = 25. Since 15 ≠ 25, the operation is not commutative.