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 b  
    54045404
    54055405    def simplify_trig(self,expand=True):
    54065406        r"""
    5407         Optionally expands and then employs the identities
    5408         `\sin(x)^2 + \cos(x)^2 = 1` and `\cosh(x)^2 - \sinh(x)^2 = 1`
     5407        Optionally expands and then employs identities such as
     5408        `\sin(x)^2 + \cos(x)^2 = 1`, `\cosh(x)^2 - \sinh(x)^2 = 1`,
     5409        `\sin(x)\csc(x) = 1`, or `\tanh(x)=\sinh(x)/\cosh(x)`
    54095410        to simplify expressions containing tan, sec, etc., to sin,
    54105411        cos, sinh, cosh.
    54115412       
     
    54295430            sin(x)^2 + cos(x)^2
    54305431            sage: f.simplify_trig()
    54315432            1
     5433            sage: h = sin(x)*csc(x)
     5434            sage: h.simplify_trig()
     5435            1
     5436            sage: k = tanh(x)*cosh(2*x)
     5437            sage: k.simplify_trig()
     5438            (2*sinh(x)^3 + sinh(x))/cosh(x)
    54325439
    54335440        In some cases we do not want to expand::
    54345441
     
    54605467          method for simplifications. Possible values are
    54615468
    54625469          - 'simple' (simplify rational functions into quotient of two
    5463             poylnomials),
     5470            polynomials),
    54645471
    54655472          - 'full' (apply repeatedly, if necessary)
    54665473
     
    54695476        - ``map`` - (default: False) if True, the result is an
    54705477          expression whose leading operator is the same as that of the
    54715478          expression ``self`` but whose subparts are the results of
    5472           applying simplifaction rules to the corresponding subparts
     5479          applying simplification rules to the corresponding subparts
    54735480          of the expressions.
    54745481
    54755482        ALIAS: :meth:`rational_simplify` and :meth:`simplify_rational`
     
    55075514            sage: f.simplify_rational(map=True)
    55085515            x - log(x)/(x + 2) - 1
    55095516
     5517        Here is an example from the Maxima documentation of where
     5518        ``method='simple'`` produces an (possibly useful) intermediate
     5519        step::
     5520
     5521            sage: y = var('y')
     5522            sage: g = (x^(y/2) + 1)^2*(x^(y/2) - 1)^2/(x^y - 1)
     5523            sage: g.simplify_rational(method='simple')
     5524            -(2*x^y - x^(2*y) - 1)/(x^y - 1)
     5525            sage: g.simplify_rational()
     5526            x^y - 1
     5527
    55105528        With option ``method='noexpand'`` we only convert to common
    55115529        denominators and add. No expansion of products is performed::
    55125530
     
    56765694        ratnump(m)$ . Then logcontract(1/2*log(x)); will give
    56775695        log(sqrt(x))."
    56785696       
    5679         ALIAS: :meth:`log_simplify` and :meth:`log_simplify` are the
     5697        ALIAS: :meth:`log_simplify` and :meth:`simplify_log` are the
    56805698        same
    56815699
    56825700        EXAMPLES::
     
    56975715
    56985716        This shows that the option ``method`` from the previous call
    56995717        has no influence to future calls (we changed some default
    5700         Maxima flag and have to ensure, that this flag has been
     5718        Maxima flag, and have to ensure that this flag has been
    57015719        restored)::
    57025720       
    57035721            sage: f.simplify_log('one')
     
    57095727            sage: f.simplify_log()
    57105728            log(x*y^2) + 1/2*log(t)     
    57115729
    5712         To contract terms with no coefficient (more preciselly, with
     5730        To contract terms with no coefficient (more precisely, with
    57135731        coefficients 1 and -1) use option ``method``::
    57145732       
    57155733            sage: f = log(x)+2*log(y)-log(t)   
     
    57785796        Simplifies symbolic expression, which can contain logs.
    57795797
    57805798        Expands logarithms of powers, logarithms of products and
    5781         logarithms of quotients.  the option ``mehotd`` tells, which
    5782         expression should be expanded.
     5799        logarithms of quotients.  The option ``method`` specifies
     5800        which expression types should be expanded.
    57835801
    57845802        INPUT:
    57855803       
    57865804        - ``self`` - expression to be simplified
    57875805
    5788         - ``method`` - (default: 'product') optional, governs which
     5806        - ``method`` - (default: 'products') optional, governs which
    57895807          expression is expanded. Possible values are
    57905808         
    57915809          - 'nothing' (no expansion),
     
    58085826        set to false, all of these simplifications will be turned
    58095827        off. "
    58105828       
    5811         ALIAS: :meth:`log_expand` and :meth:`expand(log)` are the same
     5829        ALIAS: :meth:`log_expand` and :meth:`expand_log` are the same
    58125830
    58135831        EXAMPLES::
    58145832
     
    58355853            sage: (log((3*x)^6)).log_expand('powers')
    58365854            log(729*x^6)
    58375855
     5856        This shows that the option ``method`` from the previous call
     5857        has no influence to future calls (we changed some default
     5858        Maxima flag, and have to ensure that this flag has been
     5859        restored)::
     5860       
     5861            sage: (log(3/4*x^pi)).log_expand()
     5862            pi*log(x) + log(3/4)
     5863
     5864            sage: (log(3/4*x^pi)).log_expand('all')
     5865            pi*log(x) + log(3) - log(4)
     5866
     5867            sage: (log(3/4*x^pi)).log_expand()
     5868            pi*log(x) + log(3/4)
    58385869               
    58395870        AUTHORS:
    58405871       
    58415872        - Robert Marik (11-2009)
    58425873        """
    58435874        from sage.calculus.calculus import maxima
    5844         maxima.eval('domain: real$')
     5875        maxima.eval('domain: real$ savelogexpand:logexpand$')
    58455876        if method == 'nothing':
    58465877            maxima_method='false'
    58475878        elif method == 'powers':
     
    58525883            maxima_method='super'
    58535884        else:
    58545885            raise NotImplementedError, "unknown method, see the help for available methods"
    5855         self_m = self._maxima_()
    5856         res = self_m.ev("logexpand:%s"%maxima_method)
     5886        maxima.eval('logexpand:%s'%maxima_method)
     5887        res = self._maxima_()
    58575888        res = res.sage()
    5858         maxima.eval('domain: complex$')
     5889        maxima.eval('domain: complex$ logexpand:savelogexpand$')             
    58595890        return res   
    58605891
    58615892    log_expand = expand_log