#17553: substitute_function() can leave limits unevaluated
-----------------------------+------------------------
       Reporter:  wonder     |        Owner:
           Type:  defect     |       Status:  new
       Priority:  major      |    Milestone:  sage-6.4
      Component:  symbolics  |   Resolution:
       Keywords:             |    Merged in:
        Authors:             |    Reviewers:
Report Upstream:  N/A        |  Work issues:
         Branch:             |       Commit:
   Dependencies:             |     Stopgaps:
-----------------------------+------------------------

Comment (by wonder):

 Unfortunately that workaround doesn't work when exponentials are involved.
 The `repr` stage causes the constant `e` to be replaced by an unbound
 variable `e`:

 {{{
 sage: l = limit( function('f')(x), x=0.1 )
 sage: ls = l.substitute_function( function('f'), (1 - exp(x)).function(x)
 )
 sage: ls
 limit(-e^x + 1, x, 0.1)
 sage: mls = maxima(repr(ls))
 sage: mls
 1-e^0.1
 sage: N(mls)
 ---------------------------------------------------------------------------
 TypeError                                 Traceback (most recent call
 last)
 <ipython-input-22-518484fcab94> in <module>()
 ----> 1 N(mls)

 /usr/local/sage/local/lib/python2.7/site-packages/sage/misc/functional.pyc
 in numerical_approx(x, prec, digits, algorithm)
    1466             except (TypeError, ValueError):
    1467                 pass
 -> 1468         return sage.rings.complex_field.ComplexField(prec)(x)
    1469
    1470 n = numerical_approx

 /usr/local/sage/local/lib/python2.7/site-
 packages/sage/rings/complex_field.pyc in __call__(self, x, im)
     349         if im is not None:
     350             x = x, im
 --> 351         return Parent.__call__(self, x)
     352
     353     def _element_constructor_(self, x):

 /usr/local/sage/local/lib/python2.7/site-packages/sage/structure/parent.so
 in sage.structure.parent.Parent.__call__
 (build/cythonized/sage/structure/parent.c:9666)()

 /usr/local/sage/local/lib/python2.7/site-
 packages/sage/structure/coerce_maps.so in
 sage.structure.coerce_maps.DefaultConvertMap_unique._call_
 (build/cythonized/sage/structure/coerce_maps.c:4263)()

 /usr/local/sage/local/lib/python2.7/site-
 packages/sage/structure/coerce_maps.so in
 sage.structure.coerce_maps.DefaultConvertMap_unique._call_
 (build/cythonized/sage/structure/coerce_maps.c:4170)()

 /usr/local/sage/local/lib/python2.7/site-
 packages/sage/rings/complex_field.pyc in _element_constructor_(self, x)
     388                 pass
     389             try:
 --> 390                 return x._complex_mpfr_field_( self )
     391             except AttributeError:
     392                 pass

 /usr/local/sage/local/lib/python2.7/site-
 packages/sage/interfaces/maxima_abstract.pyc in _complex_mpfr_field_(self,
 C)
    1287
 8.0751148893563733350506651837615871941533119425962889089783e-62 +
 1.4142135623730950488016887242096980785696718753769480731767*I
    1288         """
 -> 1289         return C(self._sage_())
    1290
    1291     def _mpfr_(self, R):

 /usr/local/sage/local/lib/python2.7/site-
 packages/sage/rings/complex_field.pyc in __call__(self, x, im)
     349         if im is not None:
     350             x = x, im
 --> 351         return Parent.__call__(self, x)
     352
     353     def _element_constructor_(self, x):

 /usr/local/sage/local/lib/python2.7/site-packages/sage/structure/parent.so
 in sage.structure.parent.Parent.__call__
 (build/cythonized/sage/structure/parent.c:9666)()

 /usr/local/sage/local/lib/python2.7/site-
 packages/sage/structure/coerce_maps.so in
 sage.structure.coerce_maps.DefaultConvertMap_unique._call_
 (build/cythonized/sage/structure/coerce_maps.c:4263)()

 /usr/local/sage/local/lib/python2.7/site-
 packages/sage/structure/coerce_maps.so in
 sage.structure.coerce_maps.DefaultConvertMap_unique._call_
 (build/cythonized/sage/structure/coerce_maps.c:4170)()

 /usr/local/sage/local/lib/python2.7/site-
 packages/sage/rings/complex_field.pyc in _element_constructor_(self, x)
     388                 pass
     389             try:
 --> 390                 return x._complex_mpfr_field_( self )
     391             except AttributeError:
     392                 pass

 /usr/local/sage/local/lib/python2.7/site-
 packages/sage/symbolic/expression.so in
 sage.symbolic.expression.Expression._complex_mpfr_field_
 (build/cythonized/sage/symbolic/expression.cpp:8185)()

 /usr/local/sage/local/lib/python2.7/site-
 packages/sage/symbolic/expression.so in
 sage.symbolic.expression.Expression._eval_self
 (build/cythonized/sage/symbolic/expression.cpp:7521)()

 TypeError: Cannot evaluate symbolic expression to a numeric value.
 sage: maxima(ls)
 'limit(1-%e^_SAGE_VAR_x,_SAGE_VAR_x,0.1)
 sage: maxima(SR(mls))
 1-_SAGE_VAR__e^0.1
 }}}

 Here's what I'm trying out to work around this:

 {{{
 sage: srls = SR(maxima(repr(ls)))
 sage: srls
 -_e^0.1 + 1
 sage: srls.subs( { SR.symbol('_e'): e } )
 -e^0.1 + 1
 sage: N(srls.subs( { SR.symbol('_e'): e } ))
 -0.105170918075648
 }}}

 I've tried poking around the maxima_lib module for a more straightforward
 way to ask Maxima to evaluate the limit without the data loss involved in
 the `repr` step, but so far I haven't found my way.  Advice would be
 welcome.  Thanks for this wonderfully useful package and for all the bug
 fixes!

--
Ticket URL: <http://trac.sagemath.org/ticket/17553#comment:1>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to