Opened 8 years ago
Closed 8 years ago
#10246 closed defect (fixed)
Can't get symbol from callable function x |--> x
Reported by: | kcrisman | Owned by: | burcin |
---|---|---|---|
Priority: | critical | Milestone: | sage-4.7 |
Component: | symbolics | Keywords: | plot, beginner |
Cc: | jason | Merged in: | sage-4.7.alpha4 |
Authors: | Karl-Dieter Crisman | Reviewers: | Mike Hansen |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
From this ask.sagemath question:
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.
Attachments (1)
Change History (6)
comment:1 Changed 8 years ago by
- Cc jason added
comment:2 Changed 8 years ago by
- Keywords beginner added
- Priority changed from major to critical
comment:3 Changed 8 years ago by
- 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 8 years ago by
- Reviewers set to Mike Hansen
- Status changed from needs_review to positive_review
Looks good to me.
comment:5 Changed 8 years ago by
- 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.
See also this ask.sagemath.org question where exactly the same thing comes up.
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.