Mathematics

Piecewise Function: Formula, Rules & Examples

A piecewise function is a function defined by two or more formulas, with each formula applying to a specified part of the domain.

For example:

f(x) = x + 2, if x < 0

f(x) = x², if 0 ≤ x ≤ 3

f(x) = 5, if x > 3

To evaluate the function, first identify which condition contains the input. Then use only the formula assigned to that condition.

For this example:

f(-4) = -4 + 2 = -2

f(2) = 2² = 4

f(5) = 5

A piecewise function therefore remains one function even though different input ranges use different rules.

What Is a Piecewise Function?

A piecewise function assigns different formulas to different portions of its domain.

A simple example is:

f(x) = 2x + 1, if x < 2

f(x) = x², if x ≥ 2

For an input below 2, use:

2x + 1

For an input equal to or greater than 2, use:

The condition beside each formula tells you exactly when that formula is valid.

This extends ordinary function notation. The meaning of f(x) remains the output produced by input x; the only difference is that the rule used to calculate that output depends on where x lies.

Piecewise Function Formula

A general piecewise function can be represented as:

f(x) = rule 1, if condition 1

f(x) = rule 2, if condition 2

f(x) = rule 3, if condition 3

For example:

f(x) = -x, if x < 0

f(x) = x, if x ≥ 0

The first rule applies to negative inputs. The second applies to zero and positive inputs.

The formulas and conditions together define the function. Neither part can be ignored.

How to Evaluate a Piecewise Function

Suppose:

f(x) = 3x – 1, if x < 1

f(x) = x + 4, if x ≥ 1

Find f(-2).

Since:

-2 < 1

use the first rule:

f(-2) = 3(-2) – 1

f(-2) = -6 – 1

f(-2) = -7

Now find f(3).

Since:

3 ≥ 1

use the second rule:

f(3) = 3 + 4

f(3) = 7

The condition is checked before substitution.

Example 1: Evaluating Three Pieces

Consider:

f(x) = x + 5, if x < 0

f(x) = x², if 0 ≤ x < 4

f(x) = 2x – 1, if x ≥ 4

Find f(-3), f(2), and f(6).

Find f(-3)

Because:

-3 < 0

use x + 5:

f(-3) = -3 + 5

f(-3) = 2

Find f(2)

Because:

0 ≤ 2 < 4

use x²:

f(2) = 2²

f(2) = 4

Find f(6)

Because:

6 ≥ 4

use 2x – 1:

f(6) = 2(6) – 1

f(6) = 11

Each input uses exactly one applicable branch.

Why the Conditions Matter

Consider:

f(x) = x + 1, if x < 5

f(x) = 2x, if x ≥ 5

If x = 4, the first rule applies:

f(4) = 5

You must not calculate both:

4 + 1

and:

2(4)

The second formula is not active at x = 4.

Likewise, at x = 5:

5 ≥ 5

so use the second rule:

f(5) = 2(5) = 10

The equality symbol in ≥ determines which branch owns the boundary value.

Piecewise Function Boundaries

Boundary values are the x-values where one rule stops and another begins.

Consider:

f(x) = x², if x < 3

f(x) = x + 4, if x ≥ 3

The boundary is:

x = 3

The first branch excludes 3 because it uses <.

The second branch includes 3 because it uses ≥.

Therefore:

f(3) = 3 + 4 = 7

not:

3² = 9

Carefully reading the boundary symbols is essential.

Strict and Inclusive Boundaries

A strict condition uses:

<

or:

>

and excludes the boundary.

An inclusive condition uses:

or:

and includes the boundary.

For example:

x < 2

excludes 2.

x ≥ 2

includes 2.

These are ordinary inequality conditions used to determine which branch applies.

Avoiding Overlapping Conditions

A properly specified piecewise function should normally assign one output to each permitted input.

Consider:

f(x) = x + 1, if x ≤ 3

f(x) = 2x, if x ≥ 3

At:

x = 3

both conditions are true.

The first rule gives:

f(3) = 4

while the second gives:

f(3) = 6

Because the same input would receive two different outputs, this definition does not describe a function unless the formulas happen to agree at the overlap or the conditions are revised.

A cleaner definition would use:

x < 3

for one branch and:

x ≥ 3

for the other.

Avoiding Gaps in the Domain

Conditions can also leave inputs uncovered.

For example:

f(x) = x + 1, if x < 2

f(x) = x², if x > 2

No rule applies at:

x = 2

Therefore f(2) is undefined.

That may be intentional. If not, one of the branches should include equality.

Understanding whether inputs are included or excluded connects directly with domain and range.

Graphing a Piecewise Function

A piecewise graph is drawn one branch at a time.

Suppose:

f(x) = x + 2, if x < 1

f(x) = 4, if x ≥ 1

For the first piece, graph:

y = x + 2

only where:

x < 1

At x = 1, that branch would produce:

1 + 2 = 3

but x = 1 is excluded, so place an open circle at:

(1, 3)

For the second branch, graph:

y = 4

for:

x ≥ 1

Because x = 1 is included, place a closed circle at:

(1, 4)

The complete graph consists of both pieces.

Open and Closed Circles

Endpoint circles indicate whether a boundary point belongs to a graph.

Use an open circle for:

<

or:

>

Use a closed circle for:

or:

For example:

x < 4

uses an open point at x = 4.

x ≥ 4

uses a closed point at x = 4.

This graphical convention carries the same information as brackets and parentheses in inequalities.

Example 2: Evaluate a Boundary Value

Suppose:

g(x) = x² – 1, if x ≤ 2

g(x) = 3x + 1, if x > 2

Find g(2).

The condition:

x ≤ 2

includes 2.

Therefore:

g(2) = 2² – 1

g(2) = 4 – 1

g(2) = 3

The second branch is not used because:

2 > 2

is false.

Example 3: Evaluate a Negative Input

Suppose:

h(x) = 4 – x, if x < -1

h(x) = x² + 2, if x ≥ -1

Find h(-5).

Because:

-5 < -1

use:

4 – x

So:

h(-5) = 4 – (-5)

h(-5) = 9

Parentheses are especially useful when substituting negative inputs.

Constant Pieces

A branch can be a constant.

For example:

f(x) = -2, if x < 0

f(x) = x + 1, if 0 ≤ x ≤ 5

f(x) = 6, if x > 5

For every negative input:

f(x) = -2

regardless of the exact value of x.

Constant pieces appear frequently in threshold-based rules and step-like models.

Piecewise Linear Functions

A piecewise function may use a different linear formula on each interval.

For example:

f(x) = 2x + 1, if x < 0

f(x) = -x + 4, if 0 ≤ x < 3

f(x) = 7, if x ≥ 3

Each branch is linear or constant, even though the full graph is not represented by one single linear equation.

Piecewise notation allows several simple rules to form one overall function.

Piecewise Polynomial Functions

The branches can also contain polynomial expressions.

For example:

f(x) = x² + 1, if x < 0

f(x) = x³ – x, if x ≥ 0

The first branch is quadratic and the second is cubic.

This does not turn the entire task into solving a polynomial equation. In a piecewise-function problem, the central question is which branch applies and what output that branch produces.

Piecewise Functions With Logarithmic Branches

A branch can contain a logarithm as long as the logarithm is defined throughout the portion of the domain where that branch is used.

For example:

f(x) = 0, if x ≤ 0

f(x) = ln(x), if x > 0

The condition x > 0 matches the real-number domain required by ln(x).

If a problem asks you to solve an equation involving the logarithmic branch itself, the methods for a logarithmic equation become relevant. The piecewise function determines when the branch applies; logarithmic algebra determines how an equation within that branch is solved.

Absolute Value as a Piecewise Function

The absolute value function can be expressed piecewise as:

|x| = -x, if x < 0

|x| = x, if x ≥ 0

For negative x, multiplying by -1 makes the output positive.

For example:

|-5| = -(-5) = 5

For nonnegative x:

|4| = 4

This representation shows how one familiar function can use different algebraic rules on different parts of its domain.

Solving an absolute value equation is a separate task; the piecewise form simply explains how the underlying absolute-value function behaves.

Step Functions

A step function is a type of piecewise function whose output remains constant over intervals and changes abruptly at specified boundaries.

For example:

f(x) = 1, if 0 ≤ x < 10

f(x) = 2, if 10 ≤ x < 20

f(x) = 3, if x ≥ 20

The graph consists of horizontal segments.

Step functions are useful for models where a quantity changes in discrete levels rather than continuously.

Real-World Piecewise Function Example

Suppose a parking charge is defined as:

C(h) = 5, if 0 < h ≤ 1

C(h) = 5 + 3(h – 1), if 1 < h ≤ 5

where h is the number of hours parked.

For 1 hour:

C(1) = 5

For 3 hours, use the second branch:

C(3) = 5 + 3(3 – 1)

C(3) = 5 + 6

C(3) = 11

The conditions determine which pricing rule applies.

Real fee schedules may use rounded time blocks or additional thresholds, but the mathematical structure is naturally piecewise.

Finding the Domain of a Piecewise Function

The domain is the collection of inputs covered by all branches, subject to any restrictions inside the formulas themselves.

For example:

f(x) = x², if x < 1

f(x) = x + 3, if x ≥ 1

Together the conditions cover every real x.

Therefore the domain is all real numbers:

(-∞, ∞)

Now consider:

f(x) = x + 1, if x < 0

f(x) = x², if x > 2

The inputs from 0 through 2 are not covered.

So the domain contains two separate regions rather than all real numbers.

A full domain-and-range analysis belongs to the dedicated domain and range topic, but checking branch coverage is essential when interpreting any piecewise definition.

Finding a Missing Piecewise Constant

Sometimes an unknown constant must be determined from a condition at a boundary.

Suppose:

f(x) = x + 2, if x < 3

f(x) = kx – 1, if x ≥ 3

and you are told that both formulas should produce the same value at the boundary.

The first rule approaches:

3 + 2 = 5

Set the second rule equal to 5 at x = 3:

3k – 1 = 5

Add 1:

3k = 6

Divide by 3:

k = 2

The calculation becomes a simple linear equation after the boundary condition is established.

Piecewise Function From a Table

A table may reveal that different formulas apply over different ranges.

Suppose:

xf(x)
-3-6
-2-4
-1-2
01
12
23

For negative x, the pattern is:

f(x) = 2x

For x ≥ 0, the pattern is:

f(x) = x + 1

A possible piecewise rule is therefore:

f(x) = 2x, if x < 0

f(x) = x + 1, if x ≥ 0

The boundary assignment must be consistent with the table.

Piecewise Function From a Graph

To write a piecewise function from a graph, identify each distinct graph segment and determine its equation.

Then determine the x-values over which each segment applies.

Finally, use open and closed endpoints to decide whether each boundary requires <, >, ≤, or ≥.

For example, a line segment ending with an open circle at x = 2 uses a condition that excludes 2. A second segment beginning with a closed circle at x = 2 includes that boundary.

The graph and algebraic conditions must communicate the same domain structure.

Piecewise Functions and Partial Fractions

A partial fractions decomposition and a piecewise function may both display several formulas, but they represent fundamentally different structures.

In partial fractions:

A/(x – a) + B/(x – b)

the terms are added together and apply simultaneously.

In a piecewise function, only the branch whose condition contains the current input is used.

This distinction prevents a common conceptual mistake: multiple written expressions do not necessarily mean multiple branches of a function.

Piecewise Functions and Polynomial Long Division

Polynomial long division rewrites one polynomial or rational expression through division. It does not divide a domain into cases.

A piecewise function instead divides the input domain into regions and assigns a rule to each region.

A polynomial quotient could appear as one branch of a piecewise definition, but the two techniques solve different problems.

Piecewise Function vs Composite Function

A composite function applies one function to the output of another:

f(g(x))

A piecewise function selects a rule according to the input’s condition.

These ideas can occur together, but they are not interchangeable.

For a piecewise function, the first question is:

Which condition contains this input?

For a composite function, the first question is usually:

Which function is applied first?

Common Piecewise Function Mistakes

Using the Wrong Branch

Always check the condition before substituting the input.

Ignoring Equality at a Boundary

For:

x ≥ 4

the value x = 4 belongs to that branch.

For:

x > 4

it does not.

Evaluating Every Formula

A piecewise function does not require calculating all branches for each input. Use only the applicable one.

Creating Overlapping Conditions

If two branches both include the same input and give different outputs, the definition does not assign a unique output at that point.

Leaving an Unintended Gap

Conditions such as:

x < 2

and:

x > 2

leave x = 2 undefined.

Using the Wrong Endpoint Symbol on a Graph

Strict inequalities use open circles. Inclusive inequalities use closed circles.

Forgetting Formula-Specific Restrictions

A branch may impose additional restrictions. A logarithmic branch requires a positive logarithm argument, while a rational branch cannot use an input that makes its denominator zero.

Worked Piecewise Function Example

Consider:

f(x) = 2x + 3, if x < -1

f(x) = x², if -1 ≤ x ≤ 2

f(x) = 7 – x, if x > 2

Find:

f(-4)

f(-1)

f(2)

f(5)

Find f(-4)

Since:

-4 < -1

use:

2x + 3

Therefore:

f(-4) = 2(-4) + 3

f(-4) = -8 + 3

f(-4) = -5

Find f(-1)

The middle condition includes -1:

-1 ≤ -1 ≤ 2

so:

f(-1) = (-1)²

f(-1) = 1

Find f(2)

The middle branch also includes 2:

f(2) = 2²

f(2) = 4

Find f(5)

Because:

5 > 2

use:

7 – x

Therefore:

f(5) = 7 – 5

f(5) = 2

The answers are:

f(-4) = -5

f(-1) = 1

f(2) = 4

f(5) = 2

Frequently Asked Questions

What is a piecewise function?

A piecewise function is a function defined by different formulas on different parts of its domain.

How do you evaluate a piecewise function?

Identify which condition contains the given input, substitute the input into that branch only, and simplify.

Can a piecewise function have more than two rules?

Yes. It can contain two, three, or many branches as long as the conditions clearly specify where each formula applies.

What happens at a piecewise function boundary?

Check whether the condition uses <, >, ≤, or ≥. Equality symbols determine which branch includes the boundary value.

What does an open circle mean on a piecewise graph?

An open circle means that endpoint is excluded from that graph piece.

What does a closed circle mean?

A closed circle means the endpoint belongs to that piece of the function.

Can a piecewise function have a gap?

Yes. If no branch applies to a particular input or interval, the function is undefined there.

Can piecewise conditions overlap?

They can overlap only if the definition still assigns a unique output. If overlapping branches produce different values for the same input, the relation is not a function at that input.

Is absolute value a piecewise function?

Yes. It can be written:

|x| = -x, if x < 0

|x| = x, if x ≥ 0

Can a piecewise function use quadratic or logarithmic formulas?

Yes. Each branch can use an appropriate formula—linear, quadratic, polynomial, logarithmic, constant, or another valid function rule—provided its domain conditions are correctly specified.

How do you graph a piecewise function?

Graph each formula only over the interval assigned to it. Use open circles for excluded boundaries and closed circles for included boundaries.

Is a piecewise function one function or several functions?

It is one function. The different formulas are branches of that function, each assigned to specified inputs.

Mehran Khan

Mehran Khan is the primary author at The Logic Library and CEO & Founder of One Digit Media. With 10+ years of experience in software engineering, SEO, and digital publishing, he uses a research-led approach to Logics, Maths, Tech, Formulas, Science, and AI.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button