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.

2≈1.41421356\sqrt2\approx1.41421356
Worked example

Rounding 2\sqrt2 to three significant digits gives 1.41. Squaring that rounded value does not give exactly 2.

Maths prerequisite map ↗

Exact forms such as 2\sqrt2 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.

See the mathematics
1.401.411.421.43√2
1.401.411.421.43√2
1.41<2<1.421.41<\sqrt2<1.42
Starter reference. A zoomed number line separates the exact square root from rounded displays. More digits refine the numerical approximation, not the evidence behind an input.

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 2\sqrt2 require replacing it with a Python float first?

Write a prediction (optional)

Exact expression and numerical evaluation

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 ↗

Substitution before numerical evaluation
2+π\sqrt{2} + \pi
12 significant digits
4.555806215964.55580621596
40 significant digits
4.5558062159628882872643321074892009627674.555806215962888287264332107489200962767
Exact root check
00
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 2+π\sqrt 2+\pi. 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?

Return to the editor

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?

Choose an answer
Need a hint?
Hint 1

Ask where the input came from.

Hint 2

Printing cannot create new observations.

Your notesNotes save in this browser when storage is available.