# HG changeset patch
# User Alexandru Ghitza <aghitza@alum.mit.edu>
# Date 1255956460 -39600
# Node ID ffc907c45884e8cd940495b57f57d43b0b26faf4
# Parent  5bf36a37cd0c2ce42b6bf42038e84a1968d3ad8b
trac 7077: Make all variables() methods return tuples

diff -r 5bf36a37cd0c -r ffc907c45884 sage/crypto/mq/mpolynomialsystem.py
--- a/sage/crypto/mq/mpolynomialsystem.py	Wed Oct 14 14:43:41 2009 -0700
+++ b/sage/crypto/mq/mpolynomialsystem.py	Mon Oct 19 23:47:40 2009 +1100
@@ -391,7 +391,7 @@
 
     def variables(self):
         """
-        Return an unordered list of variables appearing in polynomials
+        Return an unordered tuple of variables appearing in polynomials
         in this system.
 
         EXAMPLE::
@@ -399,6 +399,8 @@
             sage: sr = mq.SR(allow_zero_inversions=True,gf2=True,order='block')
             sage: F,s = sr.polynomial_system()
             sage: R1 = F.round(1)
+            sage: R1.variables()
+            (k000, k001, k002, k003)
             sage: sorted(R1.variables())
             [k003, k002, k001, k000]
         """
@@ -406,7 +408,7 @@
         for f in self._gens:
             for v in f.variables():
                 V.add(v)
-        return list(V)
+        return tuple(V)
 
     def monomials(self):
         """
diff -r 5bf36a37cd0c -r ffc907c45884 sage/rings/polynomial/infinite_polynomial_element.py
--- a/sage/rings/polynomial/infinite_polynomial_element.py	Wed Oct 14 14:43:41 2009 -0700
+++ b/sage/rings/polynomial/infinite_polynomial_element.py	Mon Oct 19 23:47:40 2009 +1100
@@ -366,23 +366,23 @@
     @cached_method
     def variables(self):
         """
-        Return the variables occurring in self (list of elements of some polynomial ring)
+        Return the variables occurring in self (tuple of elements of some polynomial ring)
         
         EXAMPLES::
 
             sage: X.<x> = InfinitePolynomialRing(QQ)
             sage: p = x[1] + x[2] - 2*x[1]*x[3]
             sage: p.variables()
-            [x3, x2, x1]
+            (x3, x2, x1)
             sage: x[1].variables()
-            [x1]
+            (x1,)
             sage: X(1).variables()
-            []
+            ()
 
         """
         if hasattr(self._p, 'variables'):
-            return list(self._p.variables())
-        return []
+            return tuple(self._p.variables())
+        return ()
 
     @cached_method
     def max_index(self):
diff -r 5bf36a37cd0c -r ffc907c45884 sage/rings/polynomial/laurent_polynomial.pyx
--- a/sage/rings/polynomial/laurent_polynomial.pyx	Wed Oct 14 14:43:41 2009 -0700
+++ b/sage/rings/polynomial/laurent_polynomial.pyx	Mon Oct 19 23:47:40 2009 +1100
@@ -283,7 +283,7 @@
 
     def variables(self, sort=True):
         """
-        Return a list of all variables occurring in self.
+        Return a tuple of all variables occurring in self.
 
         INPUT:
 
@@ -294,9 +294,9 @@
             sage: L.<x,y,z> = LaurentPolynomialRing(QQ)
             sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 
             sage: f.variables()
-            [z, y, x]
+            (z, y, x)
             sage: f.variables(sort=False) #random
-            [y, z, x]
+            (y, z, x)
         """
         d = self.dict();
         g = self.parent().gens()
@@ -309,7 +309,7 @@
         v = [ g[i] for i in vars]
         if sort:
             v.sort()
-        return v
+        return tuple(v)
 
     def dict(self):
         """
diff -r 5bf36a37cd0c -r ffc907c45884 sage/rings/polynomial/multi_polynomial_element.py
--- a/sage/rings/polynomial/multi_polynomial_element.py	Wed Oct 14 14:43:41 2009 -0700
+++ b/sage/rings/polynomial/multi_polynomial_element.py	Mon Oct 19 23:47:40 2009 +1100
@@ -1080,20 +1080,28 @@
 
     def variables(self):
         """
-        Returns the list of variables occurring in this polynomial.
+        Returns the tuple of variables occurring in this polynomial.
         
         EXAMPLES::
         
             sage: R.<x,y> = QQbar[]
             sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5
             sage: f.variables()
-            [x, y]
+            (x, y)
             sage: g = f.subs({x:10}); g
             700*y^2 + (-2)*y + 305
             sage: g.variables()
-            [y]
+            (y,)
+
+        TESTS:
+
+        This shows that the issue at trac ticket 7077 is fixed::
+
+            sage: x,y,z=polygens(QQ,'x,y,z')
+            sage: (x^2).variables()
+            (x,)
         """
-        return [self.parent().gen(index) for index in self.degrees().nonzero_positions()]
+        return tuple([self.parent().gen(index) for index in self.degrees().nonzero_positions()])
 
     def variable(self,i):
         """
diff -r 5bf36a37cd0c -r ffc907c45884 sage/rings/polynomial/multi_polynomial_libsingular.pyx
--- a/sage/rings/polynomial/multi_polynomial_libsingular.pyx	Wed Oct 14 14:43:41 2009 -0700
+++ b/sage/rings/polynomial/multi_polynomial_libsingular.pyx	Mon Oct 19 23:47:40 2009 +1100
@@ -3065,14 +3065,14 @@
 
     def variables(self):
         """
-        Return a list of all variables occurring in self.
+        Return a tuple of all variables occurring in self.
 
         EXAMPLES::
 
             sage: P.<x,y,z> = GF(2)[]
             sage: f = x*z^2 + z + 1
             sage: f.variables()
-            [x, z]
+            (x, z)
         """
         cdef poly *p, *v
         cdef ring *r = (<MPolynomialRing_libsingular>self._parent)._ring
@@ -3090,7 +3090,7 @@
                     l.append(new_MP(self._parent, v))
                     si.add(i)
             p = pNext(p)
-        return sorted(l,reverse=True)
+        return tuple(sorted(l,reverse=True))
 
     def variable(self, i=0):
         """
@@ -3103,7 +3103,7 @@
             sage: P.<x,y,z> = GF(2)[]
             sage: f = x*z^2 + z + 1
             sage: f.variables()
-            [x, z]
+            (x, z)
             sage: f.variable(1)
             z
         """
diff -r 5bf36a37cd0c -r ffc907c45884 sage/rings/polynomial/pbori.pyx
--- a/sage/rings/polynomial/pbori.pyx	Wed Oct 14 14:43:41 2009 -0700
+++ b/sage/rings/polynomial/pbori.pyx	Mon Oct 19 23:47:40 2009 +1100
@@ -2146,7 +2146,7 @@
 
     def variables(self):
         """
-        Return a list of the variables in this monomial.
+        Return a tuple of the variables in this monomial.
         
         EXAMPLE::
         
@@ -2154,9 +2154,9 @@
             sage: P.<x,y,z> = BooleanPolynomialRing(3)
             sage: M = BooleanMonomialMonoid(P)
             sage: M(x*z).variables() # indirect doctest
-            [x, z]
-        """
-        return list(self)
+            (x, z)
+        """
+        return tuple(self)
 
     def iterindex(self):
         """
@@ -3089,34 +3089,34 @@
 
     def variables(self):  
         r"""  
-        Return a list of all variables appearing in ``self``.
+        Return a tuple of all variables appearing in ``self``.
         
         EXAMPLE::
         
             sage: P.<x,y,z> = BooleanPolynomialRing(3)  
             sage: (x + y).variables()  
-            [x, y]  
+            (x, y)
         
         ::
         
             sage: (x*y + z).variables()  
-            [x, y, z]  
+            (x, y, z)  
         
         ::
         
             sage: P.zero_element().variables()  
-            []  
+            ()
         
         ::
         
             sage: P.one_element().variables()  
-            [1]
+            (1,)
         """  
         P = self.parent()  
         o = P.one_element()  
         if self is o or self == o:  
-            return [o]  
-        return list(self.vars_as_monomial()) 
+            return tuple([o])
+        return tuple(self.vars_as_monomial()) 
 
     def nvariables(self):
         """
diff -r 5bf36a37cd0c -r ffc907c45884 sage/rings/polynomial/polynomial_element.pyx
--- a/sage/rings/polynomial/polynomial_element.pyx	Wed Oct 14 14:43:41 2009 -0700
+++ b/sage/rings/polynomial/polynomial_element.pyx	Mon Oct 19 23:47:40 2009 +1100
@@ -4466,7 +4466,7 @@
         
     def variables(self):
         """
-        Returns the list of variables occurring in this polynomial.
+        Returns the tuple of variables occurring in this polynomial.
         
         EXAMPLES::
         
diff -r 5bf36a37cd0c -r ffc907c45884 sage/rings/quotient_ring_element.py
--- a/sage/rings/quotient_ring_element.py	Wed Oct 14 14:43:41 2009 -0700
+++ b/sage/rings/quotient_ring_element.py	Mon Oct 19 23:47:40 2009 +1100
@@ -540,17 +540,17 @@
             sage: R.<x,y> = QQ[]; S.<a,b> = R.quo(x^2 + y^2); type(a)
             <class 'sage.rings.quotient_ring_element.QuotientRingElement'>
             sage: a.variables()
-            [a]
+            (a,)
             sage: b.variables()
-            [b]
+            (b,)
             sage: s = a^2 + b^2 + 1; s
             1
             sage: s.variables()
-            []
+            ()
             sage: (a+b).variables()
-            [a, b]
+            (a, b)
         """
-        return [QuotientRingElement(self.parent(),v) for v in self.__rep.variables()]
+        return tuple([QuotientRingElement(self.parent(),v) for v in self.__rep.variables()])
 
     def monomials(self):
         """
diff -r 5bf36a37cd0c -r ffc907c45884 sage/server/support.py
--- a/sage/server/support.py	Wed Oct 14 14:43:41 2009 -0700
+++ b/sage/server/support.py	Mon Oct 19 23:47:40 2009 +1100
@@ -378,7 +378,7 @@
         w = [x for x, v in sage_globals.iteritems() if \
              _is_new_var(x, v)]
     w.sort()
-    return w
+    return tuple(w)
 
 
 
diff -r 5bf36a37cd0c -r ffc907c45884 sage/symbolic/expression.pyx
--- a/sage/symbolic/expression.pyx	Wed Oct 14 14:43:41 2009 -0700
+++ b/sage/symbolic/expression.pyx	Mon Oct 19 23:47:40 2009 +1100
@@ -2952,7 +2952,7 @@
 
     def variables(self):
         """
-        Return sorted list of variables that occur in this expression.
+        Return sorted tuple of variables that occur in this expression.
 
         EXAMPLES::
         
