]>
gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/symbolic.py
3760596c66e3f8f53cded6dbb9b3f9f636324387
2 from sage
.interfaces
.maxima_lib
import maxima_lib
3 from sage
.symbolic
.expression
import Expression
6 def set_simplification_domain(d
):
8 Set Maxima's simplification domain.
12 - ``d`` -- The domain, either 'real' or 'complex'.
16 With the default 'complex' domain, we don't simplify this::
18 sage: (abs(x)^2).simplify()
21 But in the 'real' domain, we do::
23 sage: set_simplification_domain('real')
25 sage: (abs(x)^2).simplify()
27 sage: set_simplification_domain('complex')
31 cmd
= 'domain: %s;' % d
32 result
= maxima_lib
._eval
_line
(cmd
)
36 def safe_simplify(expr
):
38 What should be a totally safe simplification operation that works
39 a little better than the plain simplify().
41 Uses a top-level function because we can't monkey-patch Cython
44 expr
= expr
.simplify_factorial()
45 expr
= expr
.simplify_log()
49 def matrix_simplify_full(A
):
51 Simplify each entry of a symbolic matrix using the
52 Expression.simplify_full() method.
56 - ``A`` - The matrix whose entries we should simplify.
60 A copy of ``A`` with all of its entries simplified.
64 Symbolic matrices (examples stolen from Expression.simplify_full())
65 will have their entries simplified::
67 sage: a,n,k = SR.var('a,n,k')
68 sage: f1 = sin(x)^2 + cos(x)^2
69 sage: f2 = sin(x/(x^2 + x))
70 sage: f3 = binomial(n,k)*factorial(k)*factorial(n-k)
71 sage: f4 = x*sin(2)/(x^a)
72 sage: A = matrix(SR, [[f1,f2],[f3,f4]])
73 sage: matrix_simplify_full(A)
75 [ factorial(n) x^(-a + 1)*sin(2)]
77 But an exception will be raised if ``A`` is not symbolic::
79 sage: A = matrix(QQ, [[1,2],[3,4]])
80 sage: matrix_simplify_full(A)
81 Traceback (most recent call last):
83 ValueError: The base ring of `A` must be the Symbolic Ring.
86 if not A
.base_ring() == SR
:
87 raise ValueError('The base ring of `A` must be the Symbolic Ring.')
90 return M(map(lambda x
: x
.simplify_full(), A
))