Experimenting with Equations¶

SymPy is a Python library for symbolic mathematics.

In Jupyter Notebook, we can initialize SymPy as follows.

In [1]:
from sympy import init_session
init_session()
IPython console for SymPy 1.12 (Python 3.11.5-64-bit) (ground types: python)

These commands were executed:
>>> from sympy import *
>>> x, y, z, t = symbols('x y z t')
>>> k, m, n = symbols('k m n', integer=True)
>>> f, g, h = symbols('f g h', cls=Function)
>>> init_printing()

Documentation can be found at https://docs.sympy.org/1.12/

Balancing Equations¶

In grade 9 students might be able to understand the mechanics of balancing an equation to isolate a variable but struggle with arithmetic or organizing their solution across multiple lines.

In these cases we might encourage students to demonstrate their understanding of balancing an equation by using a computer algebra system.

We might provide a notebook with a series of expressions defined, like this...

In [2]:
left = 2 * x + 6
In [3]:
left
Out[3]:
$\displaystyle 2 x + 6$
In [4]:
right = 24
In [5]:
right
Out[5]:
$\displaystyle 24$

Try out ideas for simplifying¶

Now we might encourage students to experiment to solve: $$2x + 6 = 24$$

Perhaps adding $6$ to the left side might make the expression simpler?

In [6]:
left + 6
Out[6]:
$\displaystyle 2 x + 12$

The student should hopefully realize that $2x + 12$ is a more complex expression than $2x + 6$... especially as our goal was to isolate the term with $x$.

They might realize subtracting six was the better approach...

In [7]:
left - 6
Out[7]:
$\displaystyle 2 x$

Now that the left side is simpler, we remind students we need to keep the equation balanced, so they should apply the same operation to the right side expression.

In [8]:
right - 6
Out[8]:
$\displaystyle 18$

This is progress, so we'll "save" these operations.

In [9]:
left = left - 6
left
Out[9]:
$\displaystyle 2 x$
In [10]:
right = right - 6
right
Out[10]:
$\displaystyle 18$

Continuing to experiment...

In [11]:
left / 2
Out[11]:
$\displaystyle x$
In [12]:
right / 2
Out[12]:
$\displaystyle 9.0$

Save the operations...

In [13]:
left = left / 2
left
Out[13]:
$\displaystyle x$
In [14]:
right = right / 2
right
Out[14]:
$\displaystyle 9.0$

Check their solution¶

Optionally, we can have students check their process of simplification using the computer algebra system.

First, they restore each side to the original expression.

In [15]:
left = 2 * x + 6
left
Out[15]:
$\displaystyle 2 x + 6$
In [16]:
right = 24
right
Out[16]:
$\displaystyle 24$

Then they create the equation:

In [17]:
equation = Eq(left, right)
In [18]:
equation
Out[18]:
$\displaystyle 2 x + 6 = 24$

Finally, they check their work above using the CAS:

In [19]:
solve(equation, x)
Out[19]:
$\displaystyle \left[ 9\right]$

Multiple representations¶

We also might want to reinforce that expressions can be represented graphically, and that the solution to a single variable equation can be seen as the intersection of those graphs.

First we import the plotting library to create an inline graph:

In [20]:
%matplotlib inline

Then we plot both expressions on the same graph:

In [21]:
p = plot(left, right)
No description has been provided for this image

We observe that the intersection of the two graphs occurs when $x=9$.