Think symbolicallyLesson 06 of 48 · 7 min
Choose when to approximate
Evaluate an exact expression numerically at a chosen precision.
Maths refresher: Exact values and decimal approximations
Some numbers have no finite decimal representation. A symbolic definition can remain exact while any finite decimal is an approximation.
Rounding to three significant digits gives 1.41. Squaring that rounded value does not give exactly 2.
Exact forms such as and pi preserve a mathematical definition. Numerical evaluation turns them into approximations with a requested number of significant digits. Use evalf or N when a decimal answer serves the question.
Precision means how many digits the arithmetic carries, not how much real-world evidence supports an input. A high-precision result from a low-precision measurement is still limited by that measurement. Avoid confusing the number of printed decimal places with significant digits.
The example retains an exact expression and evaluates it twice. Direct evalf with subs can also evaluate a formula using high-precision substitution more reliably than doing an early low-precision calculation. Later numerical lessons examine cancellation and input precision in more detail.
Does requesting 40 digits of an exact require replacing it with a Python float first?
Write a prediction (optional)
Exact expression and numerical evaluation
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
Substitution before numerical evaluation: sqrt(2) + pi 12 significant digits: 4.55580621596 40 significant digits: 4.555806215962888287264332107489200962767 Exact root check: 0
Read the starter result
Substitution before numerical evaluation retains . The exact root check is zero before numerical rounding. The two decimal displays approximate the same exact quantity.
Edit and compare
Replace sp.pi on the expression line with the Python number 3.141592653589793. Select Run Python. Compare the original and edited 40 significant digits results. Why do digits printed past the input precision fail to recover the exact sum?
Scope. Numerical precision controls arithmetic representation, not measurement error or model validity.
Try a fresh case
A sensor supplies about four reliable digits. What does printing 50 digits establish?
Need a hint?
Hint 1
Ask where the input came from.
Hint 2
Printing cannot create new observations.