Skip to content
A

Getting started with SymEval

Loading the Python runtime…

SymEval allows you to define SymPy equations, then substitute Pint quantities (value + unit), and then shows you symbolically (LaTeX) how to arrive at the result.

Below some examples that start with the basics and progressively show more powerful SymEval funcionality and usecases.

Define the equation for calculating the axial stress using SymPy:

Then define the values and units of the force acting on the structural member and its cross-sectional area:

Then substitute the inputs into the SymPy equation:

For convenience, it’s also possible to call sym_evalf as a method on a sympy.Equality. Moreover, there are a few keyword arguments (kwargs) to help you nicely format the LaTeX:

  • n_display specifies the significant figures shown in the LaTeX (defaults to 4).
  • mode="verbose" adds an extra line showing all values converted to SI base units.

mode="one_line" collapses the equation, substituted quantities and result onto a single line:

Now suppose you have done a structural analysis, which gave you the axial forces acting on the members (building columns and beams), and now you want to calculate what the resulting axial stresses on these members are. So, let’s:

  1. create a polars.DataFrame with the forces and cross-sectional areas of these members;
  2. calculate the axial stresses using quantity_evalf() on the DataFrame;
  3. symbolicly evaluate the axial stress in the member which we select from a marimo.ui.table widget.

as per CSA S16-17.

This is the example calculation that Connor Ferster, the author of handcalcs (huge inspiration for SymEval), shows in this “Engineering Calculations: Handcalcs-on-Jupyter vs. Excel” YouTube tutorial.

This example shows how you can define an entire table of inputs using marimo ui elements and then chain the result from one equation into the next.

When solving the ideal gas law

you need to always know three out of four variables (R=8.3145JK⋅molR = 8.3145 \frac{\mathrm{J}}{\mathrm{K} \cdot \mathrm{mol}} is the molar gas constant):

NameSymbolSI-unit
PressurePPPaPa
VolumeVVm3m^3
TemperatureTTKK
Number of gas particlesnnmolmol

Now, given that SymEval is built on top of SymPy, SymEval will first symbolically rearrange the ideal gas law to isolate our unknown variable on the lefthand side with sympy.solve. After which the resulting expression feeds straight into sym_evalf.

The marimo ui elements combined with the piston widget are meant to give an explorable explanation of and some intuition for the ideal gas law.