]>
gitweb.michael.orlitzky.com - sage.d.git/blob - symbolic.py
ec3fc99e1e451b95b33eed22790b3dc089f617d1
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_subs_expr(m
, *equations
):
51 Symbolic matrices have a `subs()` method, but no `subs_expr()`.
52 This makes it diffucult to substitute in a list of solutions obtained
57 - ``m`` -- A symbolic matrix.
59 - ``equations`` - One or more symbolic equations, presumably for
64 The result of substituting each equation into `m`, one after another.
68 sage: w,x,y,z = SR.var('w,x,y,z')
69 sage: A = matrix(SR, [[w,x],[y,z]])
70 sage: matrix_subs_expr(A, w == 1, x == 2, y == 3, z == 4)
75 from sage
.symbolic
.expression
import is_SymbolicEquation
77 if not m
.base_ring() == SR
:
78 raise TypeError, 'the matrix "m" must be symbolic'
80 if isinstance(equations
[0], dict):
81 eq_dict
= equations
[0]
82 equations
= [ x
== eq_dict
[x
] for x
in eq_dict
.keys() ]
84 if not all([is_SymbolicEquation(eq
) for eq
in equations
]):
85 raise TypeError, "each expression must be an equation"
87 d
= dict([(eq
.lhs(), eq
.rhs()) for eq
in equations
])