Term representation in SymbolicUtils/Symbolics -- rational polynomial form, and future changes

Hi all!

I wanted to post an update about the recent changes in SymbolicUtils that I’m looking forward to bug-fixing and making very good.

An explanation of this representation is written up here

In summary,

  • we have had special types to represent + and * (on Symbolic terms of type <: Number) using dictionaries, so that polynomials of terms are represented as a multi-dictionary datastructure which auto-simplifies and saves space and time.
  • Now we also have a new type called PolyForm which uses the storage from JuliaAlgebra’s MultivariatePolynomials ecosystem to represent terms. It wraps around polynomials but provides the generic interface of SU terms.
  • Now x / y is represented as Div(x,y) instead of x * y^(-1), and simplify_fractions represents terms as rational polynomials when possible, and simplifies them using multi-variate polynomial GCD, it also has some clever rules to avoid expansion of terms as much as possible while simplifying fractions correctly and fully.
  • Because of the above change, x/x is not simplified by default to 1 (previously it was * which ended up doing the simplifcation); however simplify_fractions will do it. The former had questionable correctness, now, having to explicitly call the simplify_fractions also means you’re indicating that it’s ok to simplify out factors from the denominator even though they can become zero for some values of the variables.

Note that this representation currently only exists in SymbolicUtils, but will be part of Symbolics in a day or two when we increase the upperbound on the dependency.

There has been a lot of chatter around correctness of Symbolics on Number-like terms (on Zulip, Here and Github). It is summed up nicely in https://github.com/JuliaSymbolics/SymbolicUtils.jl/issues/269 As a solution going forward, we may try to distinguish between \mathbb{R} (probably represented by a concrete type), and Base.Real to allow for more correct assumptions. Yet allowing the features to wrap symbolic expressions as a subtype of Real for purposes of tracing through generic numerical functions.

TermInterface.jl

There is also now a https://github.com/JuliaSymbolics/TermInterface.jl package which is an outcome of @0x0f0f0f 's GSoC project – read more about it here. This defines the traits istree and issym and actions they support which decouples term-manipulation from the type used to represent terms. This will allow Symbolics expressions to be used with Metatheory.jl! – The release of this feature is coming very soon!

Thank you!
Shashi

9 Likes