# HG changeset patch
# User Karl-Dieter Crisman <kcrisman@gmail.com>
# Date 1263534771 18000
# Node ID e1b04185feb44b627036c39ac64dad96fdf8af42
# Parent  2143fc76e6f179acadf089e7fc88f6c968c1c319
Ticket #7472 fixed (Taylor polynomial in more variables)

diff -r 2143fc76e6f1 -r e1b04185feb4 sage/calculus/functional.py
--- a/sage/calculus/functional.py	Wed Jan 13 03:40:27 2010 -0800
+++ b/sage/calculus/functional.py	Fri Jan 15 00:52:51 2010 -0500
@@ -329,35 +329,46 @@
 
 lim = limit
 
-def taylor(f, v, a, n):
+def taylor(f, *args):
     """
     Expands self in a truncated Taylor or Laurent series in the
     variable `v` around the point `a`, containing terms
-    through `(x - a)^n`.
-    
+    through `(x - a)^n`. Functions in more variables are also
+    supported.
+     
     INPUT:
-    
-    
-    -  ``v`` - variable
-    
-    -  ``a`` - number
-    
-    -  ``n`` - integer
-    
-    
+     
+    -  ``*args`` - the following notation is supported 
+          
+       - ``x, a, n`` - variable, point, degree
+        
+       - ``(x, a), (y, b), ..., n`` - variables with points, degree of polynomial
+      
     EXAMPLES::
     
         sage: var('x,k,n')
         (x, k, n)
         sage: taylor (sqrt (1 - k^2*sin(x)^2), x, 0, 6)
         -1/720*(45*k^6 - 60*k^4 + 16*k^2)*x^6 - 1/24*(3*k^4 - 4*k^2)*x^4 - 1/2*k^2*x^2 + 1
+        
+    ::
+
         sage: taylor ((x + 1)^n, x, 0, 4)
         1/24*(n^4 - 6*n^3 + 11*n^2 - 6*n)*x^4 + 1/6*(n^3 - 3*n^2 + 2*n)*x^3 + 1/2*(n^2 - n)*x^2 + n*x + 1
+        
+    ::
+
+        sage: taylor ((x + 1)^n, x, 0, 4)
+        1/24*(n^4 - 6*n^3 + 11*n^2 - 6*n)*x^4 + 1/6*(n^3 - 3*n^2 + 2*n)*x^3 + 1/2*(n^2 - n)*x^2 + n*x + 1
+                 
+    Taylor polynomial in two variables:: 
+
+        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 
     """
     if not isinstance(f, Expression):
         f = SR(f)
-    return f.taylor(v=v,a=a,n=n)
-    
+    return f.taylor(*args)
 
 def expand(x, *args, **kwds):
     """
diff -r 2143fc76e6f1 -r e1b04185feb4 sage/symbolic/expression.pyx
--- a/sage/symbolic/expression.pyx	Wed Jan 13 03:40:27 2010 -0800
+++ b/sage/symbolic/expression.pyx	Fri Jan 15 00:52:51 2010 -0500
@@ -2490,17 +2490,20 @@
         _sig_off
         return new_Expression_from_GEx(self._parent, x)
 
-    def taylor(self, v, a, n):
+    def taylor(self, *args):
         r"""
         Expands this symbolic expression in a truncated Taylor or
         Laurent series in the variable `v` around the point `a`,
-        containing terms through `(x - a)^n`.
-        
-        INPUT:
-        
-        -  ``v`` - variable
-        -  ``a`` - number
-        -  ``n`` - integer
+        containing terms through `(x - a)^n`. Functions in more 
+        variables is also supported.
+        
+        INPUT:
+        
+        -  ``*args`` - the following notation is supported 
+            
+           - ``x, a, n`` - variable, point, degree
+        
+           - ``(x, a), (y, b), n`` - variables with points, degree of polynomial
         
         EXAMPLES::
         
@@ -2508,24 +2511,63 @@
             (a, x, z)
             sage: taylor(a*log(z), z, 2, 3)
             1/24*(z - 2)^3*a - 1/8*(z - 2)^2*a + 1/2*(z - 2)*a + a*log(2)
+
+   	::
+
             sage: taylor(sqrt (sin(x) + a*x + 1), x, 0, 3)
             1/48*(3*a^3 + 9*a^2 + 9*a - 1)*x^3 - 1/8*(a^2 + 2*a + 1)*x^2 + 1/2*(a + 1)*x + 1
+
+   	::
+
             sage: taylor (sqrt (x + 1), x, 0, 5)
             7/256*x^5 - 5/128*x^4 + 1/16*x^3 - 1/8*x^2 + 1/2*x + 1
+
+   	::
+
             sage: taylor (1/log (x + 1), x, 0, 3)
             -19/720*x^3 + 1/24*x^2 - 1/12*x + 1/x + 1/2
+
+   	::
+
             sage: taylor (cos(x) - sec(x), x, 0, 5)
             -1/6*x^4 - x^2
+
+   	::
+
             sage: taylor ((cos(x) - sec(x))^3, x, 0, 9)
             -1/2*x^8 - x^6
+
+   	::
+
             sage: taylor (1/(cos(x) - sec(x))^3, x, 0, 5)
             -15377/7983360*x^4 - 6767/604800*x^2 + 11/120/x^2 + 1/2/x^4 - 1/x^6 - 347/15120
+
+ 
+        Ticket #7472 fixed (Taylor polynomial in more variables) ::
+ 
+            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
+            sage: expand(_) 
+            x*y^3 
+
         """
         from sage.all import SR, Integer
-        l = self._maxima_().taylor(v, SR(a), Integer(n))
+        A=args
+        try:
+            if isinstance(A[0],tuple):
+                B=[]
+                B.append([SR(A[i][0]) for i in range(len(A)-1)])
+                B.append([A[i][1] for i in range(len(A)-1)])
+            else:
+                B=[A[0],SR(A[1])]
+            B.append(Integer(A[len(A)-1]))
+        except:
+            raise NotImplementedError, "Wrong arguments passed to taylor. See taylor? for more details."
+        l = self._maxima_().taylor(B)
         return self.parent()(l)
 
 
+
     def truncate(self):
         """
         Given a power series or expression, return the corresponding
