# Ticket #12780: sage-trac_12780.patch

File sage-trac_12780.patch, 4.0 KB (added by mjo, 7 years ago)

Same patch with the functional.py doctest removed

• ## sage/symbolic/expression.pyx

```# HG changeset patch
# User Michael Orlitzky <michael@orlitzky.com>
# Date 1333041842 14400
# Node ID 0c28428dcb3906dab977e59c825454879a282768
# Parent  7d8ac0ee679de0e5eeba4966fe280f5f65295472
Trac #12780: Remove all domain assignments in simplification functions.

This removes assignments to Maxima's 'domain' variable in the
simplify_radical() and simplify_log() functions. This setting should
be up to the user ultimately; but for now, should at least be
consistent throughout our symbolics.

We also fix expand_log(), which used to assume that the domain was
'complex' when it was called. Now, it makes note of the current domain
when it was called and restores it before returning.

diff --git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx```
 a 0 """ from sage.calculus.calculus import maxima maxima.eval('domain: real\$') res = self.parent()(self._maxima_().radcan()) maxima.eval('domain: complex\$') return res radical_simplify = simplify_radical 0 sage: log_expr.simplify_full()   # applies both simplify_log and simplify_rational 0 We should use the current simplification domain rather than set it to 'real' explicitly (:trac:`12780`):: sage: f = sqrt(x^2) sage: f.simplify_log() sqrt(x^2) sage: from sage.calculus.calculus import maxima sage: maxima('domain: real;') real sage: f.simplify_log() abs(x) sage: maxima('domain: complex;') complex AUTHORS: - Robert Marik (11-2009) """ from sage.calculus.calculus import maxima maxima.eval('domain: real\$ savelogexpand:logexpand\$ logexpand:false\$') maxima.eval('savelogexpand:logexpand\$ logexpand:false\$') if algorithm is not None: maxima.eval('logconcoeffp:\'logconfun\$') if algorithm == 'ratios': elif algorithm is not None: raise NotImplementedError, "unknown algorithm, see the help for available algorithms" res = self.parent()(self._maxima_().logcontract()) maxima.eval('domain: complex\$') if algorithm is not None: maxima.eval('logconcoeffp:false\$') maxima.eval('logexpand:savelogexpand\$') sage: (log(3/4*x^pi)).log_expand() pi*log(x) + log(3/4) TESTS: Most of these log expansions only make sense over the reals. So, we should set the Maxima ``domain`` variable to 'real' before we call out to Maxima. When we return, however, we should set the ``domain`` back to what it was, rather than assuming that it was 'complex'. See :trac:`12780`:: sage: from sage.calculus.calculus import maxima sage: maxima('domain: real;') real sage: x.expand_log() x sage: maxima('domain;') real sage: maxima('domain: complex;') complex AUTHORS: - Robert Marik (11-2009) """ from sage.calculus.calculus import maxima original_domain = maxima.eval('domain') maxima.eval('domain: real\$ savelogexpand:logexpand\$') if algorithm == 'nothing': maxima_method='false' maxima.eval('logexpand:%s'%maxima_method) res = self._maxima_() res = res.sage() maxima.eval('domain: complex\$ logexpand:savelogexpand\$') # Set the domain back to what it was before expand_log() was called. maxima.eval('domain: %s\$ logexpand:savelogexpand\$' % original_domain) return res log_expand = expand_log