from sage.all import * from sage.interfaces.maxima_lib import maxima_lib from sage.symbolic.expression import Expression def set_simplification_domain(d): """ Set Maxima's simplification domain. INPUT: - d -- The domain, either 'real' or 'complex'. """ cmd = 'domain: %s;' % d result = maxima_lib._eval_line(cmd) return result def safe_simplify(expr): """ What should be a totally safe simplification operation that works a little better than the plain simplify(). Uses a top-level function because we can't monkey-patch Cython classes. """ expr = expr.simplify_factorial() expr = expr.simplify_log() return expr def medium_simplify(expr): """ A reasonably-safe set of simplifications, much better than simplify() and safer than simplify_full() Uses a top-level function because we can't monkey-patch Cython classes. """ expr = expr.simplify_factorial() expr = expr.simplify_trig() expr = expr.simplify_rational() expr = expr.simplify_log() return expr