Ticket #7334: trac-7344-logcontract-3.patch

File trac-7344-logcontract-3.patch, 5.0 KB (added by robert.marik, 11 years ago)

apply only this patch

  • sage/symbolic/expression.pyx

    # HG changeset patch
    # User Robert Marik <marik@mendelu.cz>
    # Date 1257685782 -3600
    # Node ID a64e5efe9bbc0cf71ccfa3343993e9bde805442a
    # Parent  bb1cdd11d71ca04ccf83d96a0a1edb88e33fa71c
    added support for logcontract
    
    diff -r bb1cdd11d71c -r a64e5efe9bbc sage/symbolic/expression.pyx
    a b  
    50965096        x = x.simplify_trig()
    50975097        x = x.simplify_rational()
    50985098        x = x.simplify_radical()
     5099        x = x.simplify_log(coeff='one')
    50995100        return x
    51005101
    51015102    full_simplify = simplify_full
     
    52155216        among the components of the expression for simplifications based on
    52165217        factoring and partial fraction expansions of exponents."
    52175218       
    5218         ALIAS: radical_simplify, simplify_radical, simplify_log,
    5219         log_simplify, exp_simplify, simplify_exp are all the same
     5219        ALIAS: radical_simplify, simplify_radical,
     5220        exp_simplify, simplify_exp are all the same
    52205221       
    52215222        EXAMPLES::
    52225223       
     
    52475248        maxima.eval('domain: complex$')
    52485249        return res
    52495250
    5250     radical_simplify = simplify_log = log_simplify = simplify_radical
     5251    radical_simplify = simplify_radical
    52515252    simplify_exp = exp_simplify = simplify_radical
    52525253
     5254    def simplify_log(self,coeff=None):
     5255        r"""
     5256        Simplifies this symbolic expression, which can contain logs.
     5257
     5258        Recursively scans the expression self, transforming
     5259        subexpressions of the form a1*log(b1) + a2*log(b2) + c into
     5260        log(b1^a1 * b2^a2) + c and simplifies inside logarithm. User
     5261        can specify, which conditions must satisfy a1 and a2 to use
     5262        this transformation in optional parameter ``coeff``.
     5263
     5264        INPUT::
     5265       
     5266        - ``self`` - expression to be simplified
     5267
     5268        - ``coeff`` - optional, gowerns the condition on a1 and a2
     5269                      which must be satisfied to contract expression
     5270                      a1*log(b1) + a2*log(b2). Options are None (use
     5271                      Maxima default, integers), 'one' (1 and -1),
     5272                      'ratios' (integers fractions of integers),
     5273                      'constants' (constants), 'all' (all expressions).
     5274                      See also examples below.
     5275                 
     5276       
     5277        DETAILS: This uses the Maxima logcontract() command. From the
     5278        Maxima documentation: "Recursively scans the expression expr,
     5279        transforming subexpressions of the form a1*log(b1) +
     5280        a2*log(b2) + c into log(ratsimp(b1^a1 * b2^a2)) + c. The user
     5281        can control which coefficients are contracted by setting the
     5282        option logconcoeffp to the name of a predicate function of one
     5283        argument. E.g. if you like to generate SQRTs, you can do
     5284        logconcoeffp:'logconfun$ logconfun(m):=featurep(m,integer) or
     5285        ratnump(m)$ . Then logcontract(1/2*log(x)); will give
     5286        log(sqrt(x))."
     5287       
     5288        ALIAS: log_simplify is the same
     5289
     5290        EXAMPLES::
     5291       
     5292            sage: x,y,t=var('x y t')
     5293       
     5294        ::
     5295       
     5296            sage: f = log(x)+2*log(y)+1/2*log(t)
     5297            sage: f.simplify_log()
     5298            log(x*y^2) + 1/2*log(t)
     5299
     5300            sage: f.simplify_log(coeff='ratios')
     5301            log(sqrt(t)*x*y^2)
     5302
     5303            sage: f.simplify_log(coeff='one')
     5304            1/2*log(t) + log(x) + 2*log(y)
     5305
     5306            sage: f.simplify_log(coeff='ratios')
     5307            log(sqrt(t)*x*y^2)     
     5308
     5309            sage: f = log(x)+2*log(y)-log(t)   
     5310            sage: f.simplify_log(coeff='one')   
     5311            2*log(y) + log(x/t)
     5312
     5313            sage: f = log(x)+log(y)-1/3*log((x+1))
     5314            sage: f.simplify_log()
     5315            -1/3*log(x + 1) + log(x*y)
     5316
     5317            sage: f.simplify_log(coeff='ratios')
     5318            log(x*y/(x + 1)^(1/3))
     5319
     5320            sage: f.simplify_log(coeff='ratios')
     5321            log(x*y/(x + 1)^(1/3))
     5322           
     5323            sage: f = log(x)+log(y)-pi*log((x+1))
     5324            sage: f.simplify_log(coeff='constants')
     5325            log(x*y/(x + 1)^pi)
     5326
     5327            sage: (x*log(9)).simplify_log()
     5328            x*log(9)
     5329            sage: (x*log(9)).simplify_log(coeff='all')
     5330            log(9^x)
     5331
     5332        TESTS::   This shows that the issue at trac #7344 is fixed
     5333
     5334            sage: (log(sqrt(2)-1)+log(sqrt(2)+1)).simplify_full()
     5335            0
     5336
     5337        """
     5338        from sage.calculus.calculus import maxima
     5339        maxima.eval('domain: real$')
     5340        if coeff is not None:
     5341            maxima.eval('logconcoeffp:\'logconfun$')
     5342        if coeff == 'ratios':
     5343            maxima.eval('logconfun(m):= featurep(m,integer) or ratnump(m)$')
     5344        elif coeff == 'one':
     5345            maxima.eval('logconfun(m):= is(m=1) or is(m=-1)$')
     5346        elif coeff == 'constants':
     5347            maxima.eval('logconfun(m):= constantp(m)$')
     5348        elif coeff == 'all':
     5349            maxima.eval('logconfun(m):= true$')
     5350        res = self.parent()(self._maxima_().logcontract())
     5351        maxima.eval('domain: complex$')
     5352        if coeff is not None:
     5353            maxima.eval('logconcoeffp:false$') 
     5354        return res
     5355
     5356    log_simplify = simplify_log
     5357
    52535358
    52545359    def factor(self, dontfactor=[]):
    52555360        """