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.
At and , , whereas swapping the input roles gives .
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.
- Original
- Simultaneous swap
- New expression
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.
Your saved draft is open. To use the published code, select Restore example in Tools. Use Recover draft to bring back your code.
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.
Execution error
Technical error details
Your result
Python text output
Compare with the worked example
Executed from the published Python during the site build. Your own run appears above. Build environment ↗
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 . 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?
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?
Need a hint?
Hint 1
A swap must retain both original roles.
Hint 2
Use the simultaneous option.