Opened 6 years ago

# numerical integral needs an operand for callable symbolic functions

Reported by: Owned by: kcrisman minor sage-6.4 calculus eviatarbach N/A

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)()
1267
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)
209
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)
1185
1186     def arithmetic(self, ex, operator):

ValueError: free variable: x |--> x
```

but

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

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

### comment:1 Changed 6 years ago by kcrisman

Here's the relevant code.

```    def symbol(self, ex):
r"""
EXAMPLES::

sage: f = x._fast_float_('x', 'y')
sage: f(1,2)
1.0
sage: f = x._fast_float_('y', 'x')
sage: f(1,2)
2.0
"""
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))

try:
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 6 years ago by kcrisman

• Description modified (diff)
```\$ hg log -r 12287
changeset:   12287:d7533ae4895e
user:        Mike Hansen <mhansen@gmail.com>
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.