Determining if a symbolic expression is positive and real

I’m about to start rewriting a physics simulation from Wolfram Client Library for Python to Julia using Symbolics.jl. The simulation consists of collisions between circles and line segments.

At each time step, I find the roots of distance formulae to find the next collision that will take place, advance the simulation to that time, perform the collision, and repeat. I’m using closed forms to compute the roots, then using Wolfram to choose the smallest positive real root from among them. Because each time step is the root of an equation, and those roots determine the variables in the next equation, the expressions end up getting pretty huge pretty fast.

My question: is Symbolics.jl able to take a list of symbolic expressions with thousands of nested terms and determine which, if any, is the smallest positive real one? What’s the best way of going about this?

If this is a physics simulation, why would you want to do this symbolically? Wouldn’t it be fine (and much faster) to do it numerically?

1 Like

I did do it numerically in Python — works great! I’m just looking to recreate the same experiment symbolically for fun.

The simulation is looking for the periods of this simulation as the angle of these segments vary:

left_center

Segment angles on the axes vs period, simulated numerically:

That’s neat! You may be able to use HardSphereDynamics.jl pretty directly.

Whoa, there’s a package for everything! Will check it out, thanks.

1 Like