Think symbolicallyLesson 01 of 48 · 6 min

Your first symbolic expression

Construct an expression and recognise its mathematical meaning.

Maths refresher: Squares and brackets

Squaring a sum multiplies the whole sum by itself. The middle terms do not disappear.

(x+1)2=(x+1)(x+1)=x2+2x+1(x+1)^2=(x+1)(x+1)=x^2+2x+1
Worked example

At x=2x=2, both forms give 9. Squaring each term separately would give 5 and changes the expression.

Maths prerequisite map ↗

A symbolic expression represents a calculation without requiring a numerical value for every quantity. SymPy keeps the symbol xx inside the result, so you can transform the expression before choosing a value for xx.

See the expansion
x²xx1x1x1
(x+1)2=x2+x+x⏟2x+1(x+1)^2=x^2+\underbrace{x+x}_{2x}+1
Starter reference. A square with side x + 1 contains one x² square, two x rectangles and a unit square. This geometric interpretation uses x ≥ 0; the polynomial identity also holds beyond that geometric domain. Dimensions are schematic.

The mathematics (x+1)2(x+1)^2 squares the entire sum. In Python, write (x+1)**2: parentheses group the sum and ** means a power. Multiplication needs an explicit *. Importing sympy as sp gives a short, consistent prefix for SymPy’s functions.

Run the example and compare the original expression with its expanded form. Both describe the same polynomial. The results dictionary labels the expressions displayed by this lab; the final loop also prints them when you download and run the file locally.

Will (x+1)2(x+1)^2 and x2+1x^2+1 expand to the same polynomial?

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+1)2\left(x + 1\right)^{2}
Expanded
x2+2x+1x^{2} + 2 x + 1
Worked text output
Original: (x + 1)**2
Expanded: x**2 + 2*x + 1

Read the starter result

Read Original and Expanded. Both keep x as a symbol. In the diagram, the two side rectangles give the middle term 2x2x in the starter’s expanded form.

Edit and compare

In the editor, replace expression = (x+1)**2 with expression = (x+2)**2. Predict the middle and constant terms. Select Run Python and compare Expanded and the area diagram with your first result.

Return to the editor

Scope. Expansion changes form. It does not assign a value to x or solve an equation.

Try a fresh case

Which Python expression means the square of the sum of x and 3?

Choose an answer
Need a hint?
Hint 1

Decide what the exponent applies to.

Hint 2

Use ** after the complete bracketed sum.

Your notesNotes save in this browser when storage is available.