Opened 6 years ago
Closed 6 years ago
#7472 closed enhancement (fixed)
Taylor polynomial in two variables does not work
Reported by: | robert.marik | Owned by: | burcin |
---|---|---|---|
Priority: | major | Milestone: | sage-4.3.1 |
Component: | calculus | Keywords: | taylor polynomial, derivative |
Cc: | Merged in: | sage-4.3.1.rc1 | |
Authors: | Robert Marik | Reviewers: | Karl-Dieter Crisman |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by robert.marik)
make
taylor(x*y^3,[x,y],[1,-1],4)
work
Attachments (5)
Change History (19)
comment:1 Changed 6 years ago by robert.marik
- Status changed from new to needs_review
Changed 6 years ago by robert.marik
Changed 6 years ago by robert.marik
this patch should be installed on the top of previous patch and improves documentation
comment:2 Changed 6 years ago by robert.marik
- Description modified (diff)
comment:3 follow-up: ↓ 4 Changed 6 years ago by kcrisman
I'm waiting for a build of 4.2.1... but in the meantime, is the new syntax (list for variables, list for numbers) more or less equivalent to other Sage functionality, or Mathematica/Maple? syntax? I honestly don't know, just asking. It would be good to have compatibility, though. For instance, plotting has the variable and range together (x,-5,5), so maybe [x,4] and [y,1] would be more appropriate? Looks like Mma allows for different "distance" for different variables, see here... Just thinking out loud here.
comment:4 in reply to: ↑ 3 Changed 6 years ago by robert.marik
Replying to kcrisman:
I'm waiting for a build of 4.2.1... but in the meantime, is the new syntax (list for variables, list for numbers) more or less equivalent to other Sage functionality, or Mathematica/Maple? syntax? I honestly don't know, just asking. It would be good to have compatibility, though. For instance, plotting has the variable and range together (x,-5,5), so maybe [x,4] and [y,1] would be more appropriate? Looks like Mma allows for different "distance" for different variables, see here... Just thinking out loud here.
Can be done easily, the expression is passed to Maxima and Maxima allows many possibilities how to use taylor command. I wanted to do as minotr change as possible. I was thinking for example also on the possibility to use different order for different variable, but I do not know if there is a demand for this.
I do not know to much about habits in Sage notation, but I think that we evaluate expansion about point in n-dimensional space, so the coordinates should be together.
comment:5 Changed 6 years ago by burcin
- Milestone set to sage-4.3
- Report Upstream set to N/A
- Reviewers set to Karl-Dieter Crisman
FWIW, I also like the MMA notation better. It is more consistent with the interface to integrate, plot, etc. as kcrisman mentioned.
comment:6 Changed 6 years ago by robert.marik
OK. what about this, is it acceptable?
sage: y=var('y');taylor(sin(x)*exp(y),(x,y),(0,1),4) 1/6*(y - 1)^3*x*e - 1/6*(y - 1)*x^3*e + 1/2*(y - 1)^2*x*e - 1/6*x^3*e + (y - 1)*x*e + x*e sage: y=var('y');taylor(sin(x)*exp(y),(x,0,4),(y,1,4)) -1/144*((y - 1)^4*e + 4*(y - 1)^3*e + 12*(y - 1)^2*e + 24*(y - 1)*e + 24*e)*x^3 + 1/24*((y - 1)^4*e + 4*(y - 1)^3*e + 12*(y - 1)^2*e + 24*(y - 1)*e + 24*e)*x sage: y=var('y');taylor(sin(x)*exp(y),x,0,4) -1/6*x^3*e^y + x*e^y sage: y=var('y');taylor(sin(x)*exp(y),(x,0,4)) -1/6*x^3*e^y + x*e^y
Note that in the first example the degree of polynomial is 4 and in the second example the degree of polynomial is 7.
(Not yet documented in the experimental patch)
comment:7 Changed 6 years ago by robert.marik
- Status changed from needs_review to needs_info
comment:8 Changed 6 years ago by robert.marik
btw: it seems that taylor command in Maxima may return not only Taylor polynomial as in calculus books, but also truncated power expansion truncated at given power. I think that this could be something different from Taylor polynomial, so the name of the command is misleading. How is it in Mathematica and Maple? What should be in Sage?
Changed 6 years ago by robert.marik
New patch, replaces all previous patches. Notation is more Sage like.
comment:9 Changed 6 years ago by robert.marik
- Status changed from needs_info to needs_review
comment:10 follow-up: ↓ 11 Changed 6 years ago by kcrisman
I assume the idea of different degrees for different variables was lost? That really doesn't matter to me, though.
What about this one, from the documentation?
sage: x,y=var('x y'); taylor(x*y^3,(x,1),(y,-1),4) (y + 1)^3*(x - 1) + (y + 1)^3 - 3*(y + 1)^2*(x - 1) - 3*(y + 1)^2 + 3*(y + 1)*(x - 1) - x + 3*y + 3
Why doesn't it end this way?
-(x-1)+3*(y+1) -1
Maybe this is documented in Maxima? It does seem odd, though, if I'm understanding what a multivariable Taylor polynomial is supposed to look like.
But overall this looks fine, assuming the Maxima computations are correct. I am waiting for 4.3.alpha2 to build to see if there needs to be a rebase, but surely it would be trivial if so.
comment:11 in reply to: ↑ 10 ; follow-up: ↓ 12 Changed 6 years ago by robert.marik
Replying to kcrisman:
I assume the idea of different degrees for different variables was lost? That really doesn't matter to me, though.
Yes, different degrees for different variables seem odd to me (from the point of view of pure caculcus) and I do not know, if there is a demand to keep this functionality.
What about this one, from the documentation?
sage: x,y=var('x y'); taylor(x*y^3,(x,1),(y,-1),4) (y + 1)^3*(x - 1) + (y + 1)^3 - 3*(y + 1)^2*(x - 1) - 3*(y + 1)^2 + 3*(y + 1)*(x - 1) - x + 3*y + 3Why doesn't it end this way?
-(x-1)+3*(y+1) -1Maybe this is documented in Maxima? It does seem odd, though, if I'm understanding what a multivariable Taylor polynomial is supposed to look like.
Very good question :). Maxima in fact returns
-(x-1)+3*(y+1) -1
and Sage changes it somehow into
-x+3y+....
I do not know why, perhaps I should ask on sage-devel. The same problem is also in current Sage. The linear Taylor polynomial hal always slope intercept form f'(a)*x+q, but should be (and Maxima returns) point slope form f'(a)*(x-a)+f(a)
---------------------------------------------------------------------- | Sage Version 4.3, Release Date: 2009-12-24 | | Type notebook() for the GUI, and license() for information. | ---------------------------------------------------------------------- sage: maxima("taylor(x^3,x,2,1)") 8+12*(x-2) sage: maxima("taylor(x^3,x,2,1)").sage() 12*x - 16 sage: taylor(x^3,x,2,1) 12*x - 16 sage:
But overall this looks fine, assuming the Maxima computations are correct. I am waiting for 4.3.alpha2 to build to see if there needs to be a rebase, but surely it would be trivial if so.
comment:12 in reply to: ↑ 11 Changed 6 years ago by robert.marik
Replying to robert.marik:
I do not know why, perhaps I should ask on sage-devel.
The question at sage-devel.
comment:13 Changed 6 years ago by kcrisman
- Status changed from needs_review to positive_review
I have made some trivial changes. The new thing is a bug in some ways, but shouldn't keep us from merging this valuable functionality.
comment:14 Changed 6 years ago by rlm
- Merged in set to sage-4.3.1.rc1
- Resolution set to fixed
- Status changed from positive_review to closed
I hope it has been fixed by the attached patch.