ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 19 Dec 2011 09:14:40 +0100How to robustly simplify an object (including a number)https://ask.sagemath.org/question/8576/how-to-robustly-simplify-an-object-including-a-number/Hi,
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!
tririverMon, 19 Dec 2011 09:14:40 +0100https://ask.sagemath.org/question/8576/