How to robustly simplify an object (including a number)
When writing a package, I met the following problem:
Say, I want the variable 'a' to be an expression, which is passed to the package by user. Then I want to call a.simplify() to simplify the expression.
However, as an input, a could naturally be the following cases:
# case 1 a = var('t') # case 2 a = 1 # case 3 a = 0.1
a.simplify() will work on 1, but not work on 2 or 3, which crashes the whole package.
I could do something as
try: b = a.simplify() except: b = a
But this really seems like a workaround instead of something formal. Is there a better way to handle this case? Thanks!