Opened 12 years ago

Closed 11 years ago

# Can't get symbol from callable function x |--> x

Reported by: Owned by: kcrisman burcin critical sage-4.7 symbolics plot, beginner jason sage-4.7.alpha4 Karl-Dieter Crisman Mike Hansen N/A

```I was plotting sin(x)/x and also wanted a seperate plot of sin(x) and x so I could visualize those components as well. However I get an error when plotting x saying "free variable x -> x". If I add a coefficient to h(x) such as h(x) = 1.0001*x then it works fine.

This is the code I am using:

f(x) = sin(x)/x
g(x) = sin(x)
h(x) = x

fig1 = plot(f,-10,10,rgbcolor='green')
fig2 = plot(g,-10,10,rgbcolor='purple')
fig3 = plot(h,-10,10,rgbcolor='red')

figure = fig1 + fig2 + fig3
show(figure,xmin=-10,xmax=10,ymin=-10,ymax=10,figsize=[8,8],fontsize=20)
```

The underlying problem is

```The exception arises in `sage.symbolic.expression_conversions.FastFloatConverter.symbol`:

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

so that it assumes if a callable expression doesn't have the variable, it must be a constant.  However, it before this asks for `if name in vars` and `if name in svars`, but here the `name` is `'x |--> x'`.

So what we need to do is fix it so that if the operator is `None` in the previous traceback in your error message, we check for this case explicitly, where the name isn't just one of the variables.
```

### comment:2 Changed 11 years ago by kcrisman

• Priority changed from major to critical

I'm putting this as 'beginner', and moving to 'critical', though that is pretty meaningless... Anyway, it's really dumb that we can't plot x.

### Changed 11 years ago by kcrisman

Based on 4.7.alpha1

### comment:3 Changed 11 years ago by kcrisman

• Authors set to Karl-Dieter Crisman
• Description modified (diff)
• Status changed from new to needs_review

Ready for review. This should fix the problem, and I tried to do it in a relatively elegant way. Unfortunately, there really is no such elegant way, since `symbol` shouldn't be relying on strings anyway, right? Oh well.

### comment:4 Changed 11 years ago by mhansen

• Reviewers set to Mike Hansen
• Status changed from needs_review to positive_review

Looks good to me.

### comment:5 Changed 11 years ago by jdemeyer

• Merged in set to sage-4.7.alpha4
• Resolution set to fixed
• Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.