]> gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/symbolic.py
Clean up some imports and fix another test failure.
[sage.d.git] / mjo / symbolic.py
1 from sage.all import *
2 from sage.interfaces.maxima_lib import maxima_lib
3 from sage.symbolic.expression import Expression
4
5
6 def set_simplification_domain(d):
7 """
8 Set Maxima's simplification domain.
9
10 INPUT:
11
12 - ``d`` -- The domain, either 'real' or 'complex'.
13
14 TESTS:
15
16 With the default 'complex' domain, we don't simplify this::
17
18 sage: sqrt(x^2).simplify()
19 sqrt(x^2)
20
21 But in the 'real' domain, we do::
22
23 sage: set_simplification_domain('real')
24 'real'
25 sage: sqrt(x^2).simplify()
26 abs(x)
27 sage: set_simplification_domain('complex')
28 'complex'
29
30 """
31 cmd = 'domain: %s;' % d
32 result = maxima_lib._eval_line(cmd)
33 return result
34
35
36 def safe_simplify(expr):
37 """
38 What should be a totally safe simplification operation that works
39 a little better than the plain simplify().
40
41 Uses a top-level function because we can't monkey-patch Cython
42 classes.
43 """
44 expr = expr.simplify_factorial()
45 expr = expr.simplify_log()
46 return expr