user3558515
user3558515

Reputation: 502

Symbolic simplification in pydrake

I'm working on a (system identification type) problem where I have a very complicated symbolic expression, which I know is linear in a certain set of parameters. I'd like to use DecomposeAffineExpressions on this expression, but Drake does not recognize the expression as linear due to un-cancelled terms in the denominator. I know the expression really is linear, because I can convert to sympy and do the simplification there (but I'd rather avoid this conversion if possible).

Is it possible to perform this sort of simplification in Drake (see minimal example below)? It seems there is some support for more complicated Trig-related simplifications, but it's not clear to me how this could apply to simply cancelling redundant terms in the denominator.

Minimal example:

What actually happens:

from pydrake.all import *

a = Variable('a')
b = Variable('b')

expr = (a*b)/b
print(expr)           # (a*b)/b
print(expr.Expand())  # (a*b)/b

What I'd like to do:

expr_simplified = expr.Simplify()  # (or something like this)
print(expr_simplified)             # a

Upvotes: 1

Views: 176

Answers (1)

Soonho Kong
Soonho Kong

Reputation: 365

We do not have this simplification in Drake for now. One of the reasons is that it is not sound. For example, when b = 0, (a * b) / b and a have different evaluation outputs.

Having said that, we understand that this feature can be useful (e.g. based on the assumption that b ≠ 0). I'll start implementing this in C++ and make it usable from the Python side. Please subscribe the issue, https://github.com/RobotLocomotion/drake/issues/8515 to get updates on this topic.

Upvotes: 2

Related Questions