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

File trac-7344-logcontract-2.patch, 3.0 KB (added by robert.marik, 4 years ago)
  • sage/symbolic/expression.pyx

    # HG changeset patch
    # User Robert Marik <marik@mendelu.cz>
    # Date 1257631858 -3600
    # Node ID 0498c15fabde58d49dc04ee291fde681082069f9
    # Parent  bb1cdd11d71ca04ccf83d96a0a1edb88e33fa71c
    trac #7334
    
    diff -r bb1cdd11d71c -r 0498c15fabde sage/symbolic/expression.pyx
    a b  
    52155215        among the components of the expression for simplifications based on 
    52165216        factoring and partial fraction expansions of exponents." 
    52175217         
    5218         ALIAS: radical_simplify, simplify_radical, simplify_log, 
    5219         log_simplify, exp_simplify, simplify_exp are all the same 
     5218        ALIAS: radical_simplify, simplify_radical,  
     5219        exp_simplify, simplify_exp are all the same 
    52205220         
    52215221        EXAMPLES:: 
    52225222         
     
    52475247        maxima.eval('domain: complex$') 
    52485248        return res 
    52495249 
    5250     radical_simplify = simplify_log = log_simplify = simplify_radical 
     5250    radical_simplify = simplify_radical 
    52515251    simplify_exp = exp_simplify = simplify_radical 
    52525252 
     5253    def simplify_log(self,coeff='integers'): 
     5254        r""" 
     5255        Simplifies this symbolic expression, which can contain logs 
     5256 
     5257        INPUT:: 
     5258            self -- expression to be simplified 
     5259 
     5260            coeff -- if 'integers' then only integers multiples are  
     5261                     contracted as powers inside logarithm. If 'ratios',  
     5262                     then also quotients of integers are treated this way.         
     5263 
     5264         
     5265        DETAILS: This uses the Maxima logcontract() command. From the 
     5266        Maxima documentation: "Recursively scans the expression expr, 
     5267        transforming subexpressions of the form a1*log(b1) + 
     5268        a2*log(b2) + c into log(ratsimp(b1^a1 * b2^a2)) + c. The user 
     5269        can control which coefficients are contracted by setting the 
     5270        option logconcoeffp to the name of a predicate function of one 
     5271        argument. E.g. if you like to generate SQRTs, you can do 
     5272        logconcoeffp:'logconfun$ logconfun(m):=featurep(m,integer) or 
     5273        ratnump(m)$ . Then logcontract(1/2*log(x)); will give 
     5274        log(sqrt(x))." 
     5275         
     5276        ALIAS: log_simplify is the same 
     5277 
     5278        EXAMPLES:: 
     5279         
     5280            sage: x,y,t=var('x y t') 
     5281         
     5282        :: 
     5283         
     5284            sage: f = log(x)+2*log(y)+1/2*log(t) 
     5285            sage: f.simplify_log() 
     5286            log(x*y^2) + 1/2*log(t) 
     5287            sage: f.simplify_log(coeff='ratios') 
     5288            log(sqrt(t)*x*y^2) 
     5289         
     5290        """ 
     5291        from sage.calculus.calculus import maxima 
     5292        maxima.eval('domain: real$') 
     5293        if coeff == 'ratios': 
     5294            maxima.eval('logconcoeffp:\'logconfun$') 
     5295            maxima.eval('logconfun(m):=featurep(m,integer) or ratnump(m)$') 
     5296        res = self.parent()(self._maxima_().logcontract()) 
     5297        maxima.eval('domain: complex$') 
     5298        if coeff == 'ratios': 
     5299            maxima.eval('logconcoeffp:false$')   
     5300        return res 
     5301 
     5302    log_simplify = simplify_log 
     5303 
    52535304 
    52545305    def factor(self, dontfactor=[]): 
    52555306        """