A computer algebra system performs exact or symbolic mathematical manipulation and computation. Instead of rearranging equations by hand, you define symbols, provide equations, and ask the system to solve them. SymPy supplies this workflow as a Python module and aims to become a full-featured computer algebra system. section 1.6
A practical symbolic workflow is:
- Import SymPy and define symbolic quantities such as speeds, distances, and time. section 1.6
- Translate the situation into equations, preserving relationships such as total distance and relative speed. section 1.6
- Pass the equations and unknowns to solve, then inspect the numeric or symbolic result. section 1.6
Solving a two-train problem
Let Va be the Amsterdam train’s speed and Vp the Paris train’s speed. A 450-kilometre separation and a one-hour meeting time produce Va + Vp = 450; the faster train’s speed produces Vp = 2Va. SymPy returns Va = 150 and Vp = 300. Replacing the fixed values with symbols such as D, t, and Vpx yields reusable formulas rather than one numeric answer. section 1.6
Listing 1.1 Numeric solution in SymPy
from sympy import *
Va, Vp = symbols('Va Vp') #1
solution = solve([
Vp - Va * 2,
Va * 1 + Vp * 1 - 450
], (Va, Vp))
print(solution)
Run the compact SymPy listing to see symbolic variables, equation solving, and printed results in one executable example. section 1.6
