pythonsympy

How do I display a full expression in sympy?


I am trying to use SymPy in a Jupyter notebook to document and perform a series of mathematical calculations in a reproducible way.

If I define the following:

from sympy import *

init_printing()
x, y, z = symbols("x y z")

x=y+z
x

then I can display the value of x (that is, y+z).

How do I display the full equation (x=y+z)?

Running Eq(x,y+z), even with evaluate=False) returns the expression with the value of x substituted (y+z=y+z).


Solution

  • Although you first declare x as a sympy.Symbol, once you perform the assignment x=y+z, x becomes an alias for y+z. Whenever you use x from that point after, x will be automatically translated by python as y+z.

    If you insist on this workflow, you could use Eq(S('x'),y+z) to display the equation.