On pp. 152-3 of Hydon's Symmetry Methods for Differential Equations (2000 ed.), he lists some computer packages for symmetry-finding. This related Mathematica StackExchange question mentions the SYM Mathematica package and Maple's DEtools/symgen. Does SAGE have anything similar for doing symmetry-finding?

This question also posted on ask.sagemath.org

  • 2
    $\begingroup$ 1) If you want to check whether your system has particular symmetry, it's quite easy to do with SymPy. It can be done with few lines of Python code, but you have to know what symmetry you want to check. SymPy is a Python package which is readily available as a part of Sage Math Cloud. 2) Also SAGE has interface to Singular. One of tutorials covers how to find invariants and equivariants for group actions, which might be used for finding symmetries. I haven't succeeded with this method though. $\endgroup$
    – Evgeny
    Mar 6, 2017 at 20:20
  • $\begingroup$ @Evgeny Thank you. Perhaps you could expand your comment into an answer and include an example of how symmetry-finding with SymPy "can be done with few lines of Python code". $\endgroup$
    – Geremia
    Mar 6, 2017 at 21:29
  • $\begingroup$ Will do in the morning :) I've been doing a gist for this before I saw your comment and I want to add some example with discrete symmetry to make it look more interesting. $\endgroup$
    – Evgeny
    Mar 6, 2017 at 21:48
  • $\begingroup$ Hopefully I can rewrite this as a StackExchange answer, but for now I have just this gist: gist.github.com/Evgenij-Gr/fd4daf9ff69a681809ac6d3106ed8f2c . $\endgroup$
    – Evgeny
    Mar 6, 2017 at 22:04
  • $\begingroup$ Try the Mathematica package from Cantwell's book. $\endgroup$
    – mavzolej
    Mar 15, 2017 at 5:36

1 Answer 1


When all you really need is to check whether some transformation is a symmetry of system or not, the following Python code can be a simple substitution for specific CAS or packages dealing with symmetry groups.

Let's consider the following vector field in $\mathbb{R}^3$:

$$\left \lbrace \begin{array}{ccc} \dot{x} & = & y, \\ \dot{y} & = & -x, \\ \dot{z} & = & -z \end{array} \right .$$

It's quite obvious that $(x, y, z) \mapsto (x \cos \varphi - y \sin \varphi, x \sin \varphi + y \cos \varphi, z)$ is a symmetry of this system for any real $\varphi$ in a sense that it maps a solution into solution. Recall that $g \in O(3)$ is a symmetry of a vector field $\dot{\mathbf{x}} = v (\mathbf{x})$ iff

$$g \cdot v(\mathbf{x}) \equiv v(g \cdot \mathbf{x}).$$

This is an "equivarince condition". That's exactly what we can check using CAS like SymPy. Let's illustrate this:

import sympy as sp


x, y, z, fi = sp.symbols('x y z varphi')

R_fi = sp.Matrix([[sp.cos(fi), -sp.sin(fi), 0],[sp.sin(fi), sp.cos(fi), 0],[0,0,1]])

u, v, w = sp.symbols('u, v, w')
vector_field = sp.Matrix([[v], [-u], [-w]])
X = sp.Matrix([[x], [y], [z]])
gX = R_fi * X

The method is very crude and ineffective, but might work for small groups: just check if equivariance condition holds for all elements of group $G$:

R_fi * vector_field.subs([(u, x), (v, y), (w, z)]) - vector_field.subs([(u, gX[0]), (v, gX[1]), (w, gX[2])])

The output would be

$\left \lbrack \begin{array}{c} 0\\ 0\\ 0 \end{array} \right \rbrack$

which means that equivariance condition holds symbolically no matter what value $\varphi$ takes (as it is expected here). Note that using Lie algebras for continuous symmetry groups is a true approach, and as far as I understand the invariance condition can be rewritten in terms of Lie algebra. But here the symmetry group is quite simple and we just check the action of elements of group.

The other example I have has discrete symmetry group. Let's also consider this system:

$$\left \lbrace \begin{array}{ccc} \dot{x} & = & Ax -6Bx^2 y^2 + By^4 + Bx^4, \\ \dot{y} & = & Ay + 4Bx^3y - 4 Bxy^3, \\ \dot{z} & = & -z \end{array} \right .$$

I've constructed this example having discrete $\mathbb{Z}_3$-symmetry in mind, i.e. $(x, y, z) \mapsto (x \cos \varphi - y \sin \varphi, x \sin \varphi + y \cos \varphi, z)$ is a symmetry of this system when $\varphi = \frac{2 \pi}{3}$. Let's check it:

R_fi = R_fi.subs([(fi, 2*sp.pi/3)])
A, B = sp.symbols('A B')
vector_field = sp.Matrix([[A*u-6*B*u**2*v**2+B*u**4+B*v**4], [A*v + 4*B*u**3*v-4*B*u*v**3], [-w]])
X = sp.Matrix([[x], [y], [z]])
gX = R_fi * X
res = R_fi * vector_field.subs([(u, x), (v, y), (w, z)]) - vector_field.subs([(u, gX[0]), (v, gX[1]), (w, gX[2])])

When we check equivariance condition, the result looks a bit ugly at first

$\left[\begin{matrix}- \frac{A x}{2} - A \left(- \frac{x}{2} - \frac{\sqrt{3} y}{2}\right) - \frac{B x^{4}}{2} + 3 B x^{2} y^{2} - \frac{B y^{4}}{2} - B \left(- \frac{x}{2} - \frac{\sqrt{3} y}{2}\right)^{4} + 6 B \left(- \frac{x}{2} - \frac{\sqrt{3} y}{2}\right)^{2} \left(\frac{\sqrt{3} x}{2} - \frac{y}{2}\right)^{2} - B \left(\frac{\sqrt{3} x}{2} - \frac{y}{2}\right)^{4} - \frac{\sqrt{3}}{2} \left(A y + 4 B x^{3} y - 4 B x y^{3}\right),\\- \frac{A y}{2} - A \left(\frac{\sqrt{3} x}{2} - \frac{y}{2}\right) - 2 B x^{3} y + 2 B x y^{3} - 4 B \left(- \frac{x}{2} - \frac{\sqrt{3} y}{2}\right)^{3} \left(\frac{\sqrt{3} x}{2} - \frac{y}{2}\right) + 4 B \left(- \frac{x}{2} - \frac{\sqrt{3} y}{2}\right) \left(\frac{\sqrt{3} x}{2} - \frac{y}{2}\right)^{3} + \frac{\sqrt{3}}{2} \left(A x + B x^{4} - 6 B x^{2} y^{2} + B y^{4}\right),\\0\end{matrix}\right]$

but after performing simple brackets expansion and basic simplification we get the following:


$\left \lbrack \begin{array}{c} 0\\ 0\\ 0 \end{array} \right \rbrack$

which again shows that the transformation is a symmetry of the system.

  • 1
    $\begingroup$ By the way, SymPy also has this functionality which looks pretty similar to some featuras of DEtools/symgen . $\endgroup$
    – Evgeny
    Mar 7, 2017 at 6:25
  • $\begingroup$ I see there are more than one reference to Lie group methods and related functions on the SymPy page you link, e.g., the § "Lie heuristics", which mentions several functions. thank you $\endgroup$
    – Geremia
    Mar 8, 2017 at 2:31
  • $\begingroup$ Well, having functionality similar to the one that is present in most used CAS seems to be in spirit of creating viable open-source Python alternative :) However, this functionality seems to be restricted to equations of particular kind and as I see it's not directly applicable to systems of ODEs. Do you have any other questions? $\endgroup$
    – Evgeny
    Mar 8, 2017 at 12:34
  • $\begingroup$ I'm really liking SymPy better than Sage (Sympy isn't bloated, and it seems to offer more tools for solving DEs!). Thank you for the answer! $\endgroup$
    – Geremia
    Jun 8, 2017 at 20:38
  • $\begingroup$ @Geremia I'm glad that my little trick that helped me once is also useful for others :) I wish Singular or Sage were more understandable: it looks like that Singular at least can solve pretty tough problems and maybe more suitable for using methods from, for example, here, but no, still beyound my reach :( $\endgroup$
    – Evgeny
    Jun 8, 2017 at 20:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .