Think symbolicallyLesson 05 of 48 · 7 min

Substitute deliberately

Replace symbols explicitly and distinguish simultaneous substitution from sequential updates.

Maths refresher: Functions with several inputs

A formula can depend on more than one independent quantity. Replacing an input means evaluating or rewriting that particular role.

f(x,y)=x+2y,f(y,x)=y+2xf(x,y)=x+2y,\qquad f(y,x)=y+2x
Worked example

At x=1x=1 and y=3y=3, f(x,y)=7f(x,y)=7, whereas swapping the input roles gives f(y,x)=5f(y,x)=5.

Maths prerequisite map ↗

Substitution replaces an expression or symbol inside another expression. It creates a new object; the original expression is unchanged. Use the symbol objects you actually used when constructing the expression.

Swap both roles together
  1. Original
    x+2yx+2y
  2. Simultaneous swap
    x↦y,  y↦xx\mapsto y,\;y\mapsto x
  3. New expression
    y+2xy+2x
Starter reference. A simultaneous substitution uses the original roles for both replacements; it does not feed one replacement into the next.

Order matters when replacements depend on one another. Sequentially changing x to y and then y to x is not a reliable way to swap their original roles. simultaneous=True applies replacements together without using one replacement as input to another.

Inspect the original, ordinary sequential replacement and simultaneous swap below. This matters when renaming variables, changing coordinates or substituting several model inputs. Retain a copy of the symbolic formula before inserting particular numbers.

Will sequential replacements x→y and y→x necessarily swap the two original symbols?

Write a prediction (optional)

Exact symbolic investigation

Select Run Python with the code unchanged.

Tools
About Python

Python and the course packages can load while you read. Each run starts with fresh user variables; imported modules stay loaded. Stop replaces the worker. Runtime details ↗

Ctrl+Enter or ⌘+Enter runs Python.

Compare with the worked example

Executed from the published Python during the site build. Your own run appears above. Build environment ↗

Original
x+2yx + 2 y
Sequential
3x3 x
Simultaneous swap
2x+y2 x + y
Numerical inputs
77
Worked text output
Original: x + 2*y
Sequential: 3*x
Simultaneous swap: 2*x + y
Numerical inputs: 7

Read the starter result

For the starter, Original remains x+2yx+2y. Sequential uses one symbol, while Simultaneous swap preserves the two distinct roles.

Edit and compare

Replace expression = x+2*y with expression = x/y. Restrict your swap comparison to nonzero x and y. Select Run Python and compare Sequential with Simultaneous swap. Which one keeps the original roles distinct after the replacements?

Return to the editor

Scope. Substitution does not automatically preserve or document every domain restriction of a transformed formula.

Try a fresh case

Which operation safely swaps the original roles of a and b?

Choose an answer
Need a hint?
Hint 1

A swap must retain both original roles.

Hint 2

Use the simultaneous option.

Your notesNotes save in this browser when storage is available.