# Ticket #7334: trac_7334-logcontract-5-reviewer.patch

File trac_7334-logcontract-5-reviewer.patch, 6.1 KB (added by kcrisman, 11 years ago)

Apply after others

• ## sage/symbolic/expression.pyx

# HG changeset patch
# User Karl-Dieter Crisman <kcrisman@gmail.com>
# Date 1265299344 18000
# Node ID c07e8cdddeb47c58463a2d4f49430158ec3e4674
# Parent  513aeb51f77fe178a6aa275881e018f744e5d77a
Trac 7334 - Referee fixes to documentation and the log_expand function

diff -r 513aeb51f77f -r c07e8cdddeb4 sage/symbolic/expression.pyx
 a def simplify_trig(self,expand=True): r""" Optionally expands and then employs the identities \sin(x)^2 + \cos(x)^2 = 1 and \cosh(x)^2 - \sinh(x)^2 = 1 Optionally expands and then employs identities such as \sin(x)^2 + \cos(x)^2 = 1, \cosh(x)^2 - \sinh(x)^2 = 1, \sin(x)\csc(x) = 1, or \tanh(x)=\sinh(x)/\cosh(x) to simplify expressions containing tan, sec, etc., to sin, cos, sinh, cosh. sin(x)^2 + cos(x)^2 sage: f.simplify_trig() 1 sage: h = sin(x)*csc(x) sage: h.simplify_trig() 1 sage: k = tanh(x)*cosh(2*x) sage: k.simplify_trig() (2*sinh(x)^3 + sinh(x))/cosh(x) In some cases we do not want to expand:: method for simplifications. Possible values are - 'simple' (simplify rational functions into quotient of two poylnomials), polynomials), - 'full' (apply repeatedly, if necessary) - map - (default: False) if True, the result is an expression whose leading operator is the same as that of the expression self but whose subparts are the results of applying simplifaction rules to the corresponding subparts applying simplification rules to the corresponding subparts of the expressions. ALIAS: :meth:rational_simplify and :meth:simplify_rational sage: f.simplify_rational(map=True) x - log(x)/(x + 2) - 1 Here is an example from the Maxima documentation of where method='simple' produces an (possibly useful) intermediate step:: sage: y = var('y') sage: g = (x^(y/2) + 1)^2*(x^(y/2) - 1)^2/(x^y - 1) sage: g.simplify_rational(method='simple') -(2*x^y - x^(2*y) - 1)/(x^y - 1) sage: g.simplify_rational() x^y - 1 With option method='noexpand' we only convert to common denominators and add. No expansion of products is performed:: ratnump(m)$. Then logcontract(1/2*log(x)); will give log(sqrt(x))." ALIAS: :meth:log_simplify and :meth:log_simplify are the ALIAS: :meth:log_simplify and :meth:simplify_log are the same EXAMPLES:: This shows that the option method from the previous call has no influence to future calls (we changed some default Maxima flag and have to ensure, that this flag has been Maxima flag, and have to ensure that this flag has been restored):: sage: f.simplify_log('one') sage: f.simplify_log() log(x*y^2) + 1/2*log(t) To contract terms with no coefficient (more preciselly, with To contract terms with no coefficient (more precisely, with coefficients 1 and -1) use option method:: sage: f = log(x)+2*log(y)-log(t) Simplifies symbolic expression, which can contain logs. Expands logarithms of powers, logarithms of products and logarithms of quotients. the option mehotd tells, which expression should be expanded. logarithms of quotients. The option method specifies which expression types should be expanded. INPUT: - self - expression to be simplified - method - (default: 'product') optional, governs which - method - (default: 'products') optional, governs which expression is expanded. Possible values are - 'nothing' (no expansion), set to false, all of these simplifications will be turned off. " ALIAS: :meth:log_expand and :meth:expand(log) are the same ALIAS: :meth:log_expand and :meth:expand_log are the same EXAMPLES:: sage: (log((3*x)^6)).log_expand('powers') log(729*x^6) This shows that the option method from the previous call has no influence to future calls (we changed some default Maxima flag, and have to ensure that this flag has been restored):: sage: (log(3/4*x^pi)).log_expand() pi*log(x) + log(3/4) sage: (log(3/4*x^pi)).log_expand('all') pi*log(x) + log(3) - log(4) sage: (log(3/4*x^pi)).log_expand() pi*log(x) + log(3/4) AUTHORS: - Robert Marik (11-2009) """ from sage.calculus.calculus import maxima maxima.eval('domain: real$') maxima.eval('domain: real$savelogexpand:logexpand$') if method == 'nothing': maxima_method='false' elif method == 'powers': maxima_method='super' else: raise NotImplementedError, "unknown method, see the help for available methods" self_m = self._maxima_() res = self_m.ev("logexpand:%s"%maxima_method) maxima.eval('logexpand:%s'%maxima_method) res = self._maxima_() res = res.sage() maxima.eval('domain: complex$') maxima.eval('domain: complex$ logexpand:savelogexpand\$') return res log_expand = expand_log