Opened 5 years ago

Last modified 4 years ago

#15219 new defect

numerical integral needs an operand for callable symbolic functions

Reported by: kcrisman Owned by:
Priority: minor Milestone: sage-6.4
Component: calculus Keywords:
Cc: eviatarbach Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by kcrisman)

I feel like I've seen this before, so close if appropriate... See this ask.sagemath question.

sage: h(x) = x
sage: numerical_integral(h, 1, 2)
/Users/.../sage-5.11.rc0/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.pyc in fast_float(ex, *vars)
   1264         1.4142135623730951
   1265     """
-> 1266     return FastFloatConverter(ex, *vars)()
   1268 #################

/Users/.../sage-5.11.rc0/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.pyc in __call__(self, ex)
    206         operator = ex.operator()
    207         if operator is None:
--> 208             return self.symbol(ex)
    210         if operator in arithmetic_operators:

/Users/.../sage-5.11.rc0/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.pyc in symbol(self, ex)
   1182             return self.ff.fast_float_constant(float(ex))
   1183         except TypeError:
-> 1184             raise ValueError, "free variable: %s" % repr(ex)
   1186     def arithmetic(self, ex, operator):

ValueError: free variable: x |--> x


sage: numerical_integral(x, 1, 2)
(1.5, 1.6653345369377348e-14)

I think this should be easy to fix by catching this somehow.

Change History (6)

comment:1 Changed 5 years ago by kcrisman

Here's the relevant code.

    def symbol(self, ex):
            sage: f = x._fast_float_('x', 'y')
            sage: f(1,2)
            sage: f = x._fast_float_('y', 'x')
            sage: f(1,2)
        if self.vars == ():
            return self.ff.fast_float_arg(0)

        vars = list(self.vars)
        name = repr(ex)
        if name in vars:
            return self.ff.fast_float_arg(vars.index(name))
        svars = [repr(x) for x in vars]
        if name in svars:
            return self.ff.fast_float_arg(svars.index(name))

        if ex.is_symbol(): # case of callable function which is the variable, like f(x)=x
            name = repr(SR(ex)) # this gets back just the 'output' of the function
            if name in svars: 
                return self.ff.fast_float_arg(svars.index(name))

            return self.ff.fast_float_constant(float(ex))
        except TypeError:
            raise ValueError, "free variable: %s" % repr(ex)

Note that this case is supposedly already taken care of! But apparently in this case name is not in svars. I'll investigate...

comment:2 Changed 5 years ago by kcrisman

  • Description modified (diff)
$ hg log -r 12287
changeset:   12287:d7533ae4895e
user:        Mike Hansen <>
date:        Tue May 19 16:11:30 2009 -0700
summary:     Updates for Pynac-0.1.7, main symbolics switch (#5930)

So apparently it's been here for a while.

comment:3 Changed 5 years ago by eviatarbach

  • Cc eviatarbach added

comment:4 Changed 5 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:5 Changed 5 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:6 Changed 4 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4
Note: See TracTickets for help on using tickets.