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 b  
    72107210            0
    72117211        """
    72127212        from sage.calculus.calculus import maxima
    7213         maxima.eval('domain: real$')
    72147213        res = self.parent()(self._maxima_().radcan())
    7215         maxima.eval('domain: complex$')
    72167214        return res
    72177215
    72187216    radical_simplify = simplify_radical
     
    73357333            0
    73367334            sage: log_expr.simplify_full()   # applies both simplify_log and simplify_rational
    73377335            0
    7338            
     7336
     7337        We should use the current simplification domain rather than
     7338        set it to 'real' explicitly (:trac:`12780`)::
     7339
     7340            sage: f = sqrt(x^2)
     7341            sage: f.simplify_log()
     7342            sqrt(x^2)
     7343            sage: from sage.calculus.calculus import maxima
     7344            sage: maxima('domain: real;')
     7345            real
     7346            sage: f.simplify_log()
     7347            abs(x)
     7348            sage: maxima('domain: complex;')
     7349            complex
     7350
    73397351        AUTHORS:
    73407352       
    73417353        - Robert Marik (11-2009)
    73427354        """
    73437355        from sage.calculus.calculus import maxima
    7344         maxima.eval('domain: real$ savelogexpand:logexpand$ logexpand:false$')
     7356        maxima.eval('savelogexpand:logexpand$ logexpand:false$')
    73457357        if algorithm is not None:
    73467358            maxima.eval('logconcoeffp:\'logconfun$')
    73477359        if algorithm == 'ratios':
     
    73557367        elif algorithm is not None:
    73567368            raise NotImplementedError, "unknown algorithm, see the help for available algorithms"
    73577369        res = self.parent()(self._maxima_().logcontract())
    7358         maxima.eval('domain: complex$')
    73597370        if algorithm is not None:
    73607371            maxima.eval('logconcoeffp:false$')
    73617372        maxima.eval('logexpand:savelogexpand$')             
     
    74397450
    74407451            sage: (log(3/4*x^pi)).log_expand()
    74417452            pi*log(x) + log(3/4)
    7442                
     7453
     7454        TESTS:
     7455
     7456        Most of these log expansions only make sense over the
     7457        reals. So, we should set the Maxima ``domain`` variable to
     7458        'real' before we call out to Maxima. When we return, however, we
     7459        should set the ``domain`` back to what it was, rather than
     7460        assuming that it was 'complex'. See :trac:`12780`::
     7461
     7462            sage: from sage.calculus.calculus import maxima
     7463            sage: maxima('domain: real;')
     7464            real
     7465            sage: x.expand_log()
     7466            x
     7467            sage: maxima('domain;')
     7468            real
     7469            sage: maxima('domain: complex;')
     7470            complex
     7471
    74437472        AUTHORS:
    74447473       
    74457474        - Robert Marik (11-2009)
    74467475        """
    74477476        from sage.calculus.calculus import maxima
     7477        original_domain = maxima.eval('domain')
    74487478        maxima.eval('domain: real$ savelogexpand:logexpand$')
    74497479        if algorithm == 'nothing':
    74507480            maxima_method='false'
     
    74597489        maxima.eval('logexpand:%s'%maxima_method)
    74607490        res = self._maxima_()
    74617491        res = res.sage()
    7462         maxima.eval('domain: complex$ logexpand:savelogexpand$')             
     7492        # Set the domain back to what it was before expand_log() was called.
     7493        maxima.eval('domain: %s$ logexpand:savelogexpand$' % original_domain)
    74637494        return res   
    74647495
    74657496    log_expand = expand_log