Commits

Volker Braun committed 35fd45e

finished sage-5.11.beta2

  • Participants
  • Parent commits d1d9469

Comments (0)

Files changed (3)

File trac_13125_misc.patch

 diff --git a/sage/sets/real_set.py b/sage/sets/real_set.py
 --- a/sage/sets/real_set.py
 +++ b/sage/sets/real_set.py
-@@ -51,6 +51,7 @@
+@@ -12,7 +12,7 @@
+     sage: RealSet((0,1), [2,3])
+     (0, 1) + [2, 3]
+     sage: RealSet(-oo, oo)
+-    (-Infinity, +Infinity)
++    (-oo, +oo)
+ 
+ Brackets must be balanced in Python, so the naive notation for
+ half-open intervals does not work::
+@@ -31,13 +31,30 @@
+     sage: RealSet.point(1/2)
+     {1/2}
+     sage: RealSet.unbounded_below_open(0)
+-    (-Infinity, 0)
++    (-oo, 0)
+     sage: RealSet.unbounded_below_closed(0)
+-    (-Infinity, 0]
++    (-oo, 0]
+     sage: RealSet.unbounded_above_open(1)
+-    (1, +Infinity)
++    (1, +oo)
+     sage: RealSet.unbounded_above_closed(1)
+-    [1, +Infinity)
++    [1, +oo)
++
++AUTHORS:
++
++- Laurent Claessens (2010-12-10): Interval and ContinuousSet, posted
++  to sage-devel at
++  http://www.mail-archive.com/sage-support@googlegroups.com/msg21326.html_.
++
++- Ares Ribo (2011-10-24): Extended the previous work defining the
++  class RealSet.
++
++- Jordi Saludes (2011-12-10): Documentation and file reorganization.
++
++- Volker Braun (2013-06-22): Rewrite
++
++This module has, in part, received funding from the European Union's
++Seventh Framework Programme (FP7/2007-2013) under grant agreement
++FP7-ICT-247914.
+ """
+ 
+ ########################################################################
+@@ -51,6 +68,7 @@
  
  from sage.structure.parent import Parent
  from sage.structure.unique_representation import UniqueRepresentation
  from sage.rings.real_lazy import LazyFieldElement, RLF
  from sage.rings.infinity import infinity, minus_infinity
  
-@@ -110,7 +111,7 @@
+@@ -64,6 +82,23 @@
+         You are not supposed to create :class:`RealInterval` objects
+         yourself. Always use :class:`RealSet` instead.
+ 
++        INPUT:
++
++        - ``lower`` -- real or minus infinity. The lower bound of the
++          interval.
++
++        - ``lower_closed`` -- boolean. Whether the interval is closed
++          at the lower bound.
++
++        - ``upper`` -- real or (plus) infinity. The upper bound of the
++          interval.
++
++        - ``upper_closed`` -- boolean. Whether the interval is closed
++          at the upper bound.
++
++        - ``check`` -- boolean keyword argument. Whether to check the
++          other arguments for validity.
++
+         EXAMPLES::
+ 
+             sage: RealSet([0, oo])
+@@ -76,17 +111,16 @@
+         self._lower_closed = lower_closed
+         self._upper_closed = upper_closed
+         if check:
+-            if not isinstance(lower, LazyFieldElement):
+-                raise ValueError('lower bound must be in RLF')
+-            if not isinstance(upper, LazyFieldElement):
+-                raise ValueError('upper bound must be in RLF')
++            if not (isinstance(lower, LazyFieldElement) or lower is minus_infinity):
++                raise ValueError('lower bound must be in RLF or minus infinity')
++            if not (isinstance(upper, LazyFieldElement) or upper is infinity):
++                raise ValueError('upper bound must be in RLF or plus infinity')
+             if not isinstance(lower_closed, bool):
+                 raise ValueError('lower_closed must be boolean')
+             if not isinstance(upper_closed, bool):
+                 raise ValueError('upper_closed must be boolean')
+-            if lower == infinity or upper == minus_infinity:
+-                raise ValueError('only lower/upper bound can be minus/plus infinity')
+-            if lower > upper:
++            # comparison of infinity with RLF is broken
++            if not(lower is minus_infinity or upper is infinity) and lower > upper:
+                 raise ValueError('lower/upper bounds are not sorted')
+             if (lower_closed and lower == minus_infinity):
+                 raise ValueError('interval cannot be closed at -oo')
+@@ -110,7 +144,7 @@
              sage: I.is_empty()
              False
          """
  
      def is_point(self):
          """
-@@ -512,7 +513,39 @@
+@@ -144,8 +178,11 @@
+             sage: I.upper()
+             1
+         """
+-        return self._lower._value
+-
++        if self._lower is minus_infinity:
++            return minus_infinity
++        else:
++            return self._lower._value
++    
+     def upper(self):
+         """
+         Return the upper bound
+@@ -162,7 +199,10 @@
+             sage: I.upper()
+             1
+         """
+-        return self._upper._value
++        if self._upper is infinity:
++            return infinity
++        else:
++            return self._upper._value
+                 
+     def lower_closed(self):
+         """
+@@ -296,11 +336,17 @@
+             {0}
+         """
+         if self.is_point():
+-            return '{' + str(self._lower._value) + '}'
++            return '{' + str(self.lower()) + '}'
+         s =  '[' if self._lower_closed else '('
+-        s += str(self._lower._value)
++        if self.lower() is minus_infinity:
++            s += '-oo'
++        else:
++            s += str(self.lower())
+         s += ', '
+-        s += str(self._upper._value)
++        if self.upper() is infinity:
++            s += '+oo'
++        else:
++            s += str(self.upper())
+         s +=  ']' if self._upper_closed else ')'
+         return s
+ 
+@@ -317,9 +363,9 @@
+             sage: RealSet.open(0,1)[0].closure()
+             [0, 1]
+             sage: RealSet.open(-oo,1)[0].closure()
+-            (-Infinity, 1]
++            (-oo, 1]
+             sage: RealSet.open(0, oo)[0].closure()
+-            [0, +Infinity)
++            [0, +oo)
+         """
+         lower_closed = (self._lower != minus_infinity)
+         upper_closed = (self._upper != infinity)
+@@ -338,9 +384,9 @@
+             sage: RealSet.closed(0, 1)[0].interior()
+             (0, 1)
+             sage: RealSet.open_closed(-oo, 1)[0].interior()
+-            (-Infinity, 1)
++            (-oo, 1)
+             sage: RealSet.closed_open(0, oo)[0].interior()
+-            (0, +Infinity)
++            (0, +oo)
+         """
+         return RealInterval(self._lower, False, self._upper, False)
+         
+@@ -512,7 +558,39 @@
              lower = upper = RLF(0)
              lower_closed = upper_closed = False
          return RealInterval(lower, lower_closed, upper, upper_closed)
  
  
  class RealSet(UniqueRepresentation, Parent):
-@@ -588,6 +621,31 @@
+@@ -535,6 +613,8 @@
+             sage: RealSet(RealSet.open_closed(0,1), RealSet.closed_open(2,3))
+             (0, 1] + [2, 3)
+         """
++        if len(args) == 1 and isinstance(args[0], RealSet):
++            return args[0]   # common optimization
+         intervals = []
+         if len(args) == 2:
+             # allow RealSet(0,1) interval constructor
+@@ -588,6 +668,31 @@
          """
          self._intervals = intervals
      
      def __iter__(self):
          """
          Iterate over the component intervals is ascending order
-@@ -625,6 +683,19 @@
+@@ -618,12 +723,45 @@
+             sage: s = RealSet(RealSet.open_closed(0,1), RealSet.closed_open(2,3))
+             sage: s.n_components()
+             2
+-            sage: len(s)   # shorthand
+-            2
+         """
+         return len(self._intervals)
  
-     __len__ = n_components
- 
+-    __len__ = n_components
++    def cardinality(self):
++        """
++        Return the cardinality of the subset of the real line.
++
++        OUTPUT:
++        
++        Integer or infinity. The size of a discrete set is the number
++        of points; the size of a real interval is Infinity.
++
++        EXAMPLES::
++
++           sage: RealSet([0, 0], [1, 1], [3, 3]).cardinality()
++           3
++           sage: RealSet(0,3).cardinality()
++           +Infinity
++        """
++        n = ZZ(0)
++        for interval in self._intervals:
++            if interval.is_point():
++                n += 1
++            else:
++                return infinity
++        return n
++
 +    def is_empty(self):
 +        """
 +        Return whether the set is empty
 +            True
 +        """
 +        return len(self._intervals) == 0
-+
+ 
      def get_interval(self, i):
          """
-         Return the ``i``-th connected component.
-@@ -994,6 +1065,19 @@
+@@ -734,7 +872,7 @@
+             return ' + '.join(map(repr, self._intervals))
+ 
+     @staticmethod
+-    def _prep(lower, upper):
++    def _prep(lower, upper=None):
+         """
+         Helper to prepare the lower and upper bound
+ 
+@@ -742,10 +880,28 @@
+ 
+             sage: RealSet._prep(1, 0)
+             (0, 1)
++            sage: RealSet._prep(oo)
++            +Infinity
+         """
+-        lower = RLF(lower)
+-        upper = RLF(upper)
+-        if upper < lower:
++        if lower == minus_infinity:
++            lower = minus_infinity
++        if lower == infinity:
++            lower = infinity
++        else:
++            lower = RLF(lower)
++        if upper is None:
++            return lower
++        if upper == minus_infinity:
++            upper = minus_infinity
++        if upper == infinity:
++            upper = infinity
++        else:
++            upper = RLF(upper)
++        if upper is infinity or lower is minus_infinity:
++            return lower, upper
++        elif lower is infinity or upper is minus_infinity:
++            return upper, lower
++        elif upper < lower:
+             return upper, lower
+         else:
+             return lower, upper
+@@ -801,7 +957,7 @@
+ 
+         INPUT:
+ 
+-        - ``p``, ``upper`` -- a real number.
++        - ``p`` -- a real number.
+ 
+         OUTPUT:
+ 
+@@ -812,7 +968,7 @@
+             sage: RealSet.open(1, 0)
+             (0, 1)
+         """
+-        p = RLF(p)
++        p = RealSet._prep(p)
+         return RealSet(RealInterval(p, True, p, True))
+     
+     @staticmethod
+@@ -877,9 +1033,10 @@
+         EXAMPLES::
+ 
+             sage: RealSet.unbounded_below_closed(1)
+-            (-Infinity, 1]
++            (-oo, 1]
+         """
+-        return RealSet(RealInterval(RLF(minus_infinity), False, RLF(bound), True))
++        bound = RealSet._prep(bound)
++        return RealSet(RealInterval(minus_infinity, False, bound, True))
+ 
+     @staticmethod
+     def unbounded_below_open(bound):
+@@ -897,8 +1054,9 @@
+         EXAMPLES::
+ 
+             sage: RealSet.unbounded_below_open(1)
+-            (-Infinity, 1)
++            (-oo, 1)
+         """
++        bound = RealSet._prep(bound)
+         return RealSet(RealInterval(RLF(minus_infinity), False, RLF(bound), False))
+ 
+     @staticmethod
+@@ -918,8 +1076,9 @@
+         EXAMPLES::
+ 
+             sage: RealSet.unbounded_above_closed(1)
+-            [1, +Infinity)
++            [1, +oo)
+         """
++        bound = RealSet._prep(bound)
+         return RealSet(RealInterval(RLF(bound), True, RLF(infinity), False))
+ 
+     @staticmethod
+@@ -939,17 +1098,18 @@
+         EXAMPLES::
+ 
+             sage: RealSet.unbounded_above_open(1)
+-            (1, +Infinity)
++            (1, +oo)
+         """
++        bound = RealSet._prep(bound)
+         return RealSet(RealInterval(RLF(bound), False, RLF(infinity), False))
+ 
+-    def union(self, other):
++    def union(self, *other):
+         """
+         Return the union of the two sets
+ 
+         INPUT:
+         
+-        - ``other`` -- a :class:`RealSet`.
++        - ``other`` -- a :class:`RealSet` or data that defines one.
+ 
+         OUTPUT:
+         
+@@ -961,24 +1121,27 @@
+             sage: s2 = RealSet(1,3)
+             sage: s1.union(s2)
+             (0, 3)
++            sage: s1.union(1,3)
++            (0, 3)
+             sage: s1 | s2    # syntactic sugar
+             (0, 3)
+             sage: s1 + s2    # syntactic sugar
+             (0, 3)
+         """
++        other = RealSet(*other)
+         intervals = self._intervals + other._intervals
+         return RealSet(*intervals)
+     
+     __or__ = union
+     __add__ = union
+ 
+-    def intersection(self, other):
++    def intersection(self, *other):
+         """
+         Return the intersection of the two sets
+ 
+         INPUT:
+         
+-        - ``other`` -- a :class:`RealSet`.
++        - ``other`` -- a :class:`RealSet` or data that defines one.
+ 
+         OUTPUT:
+         
+@@ -987,14 +1150,28 @@
+         EXAMPLES::
+ 
+             sage: s1 = RealSet(0,2) + RealSet.unbounded_above_closed(10);  s1
+-            (0, 2) + [10, +Infinity)
++            (0, 2) + [10, +oo)
+             sage: s2 = RealSet(1,3) + RealSet.unbounded_below_closed(-10);  s2
+-            (-Infinity, -10] + (1, 3)
++            (-oo, -10] + (1, 3)
+             sage: s1.intersection(s2)
              (1, 2)
              sage: s1 & s2    # syntactic sugar
              (1, 2)
 +            sage: s2.intersection(s3)
 +            {1} + {2}
          """
++        other = RealSet(*other)
          # TODO: this can be done in linear time since the intervals are already sorted
          intervals = []
-@@ -1128,3 +1212,114 @@
+         for i1 in self._intervals:
+@@ -1015,12 +1192,12 @@
+         EXAMPLES::
+ 
+             sage: s1 = RealSet(0,2) + RealSet.unbounded_above_closed(10);  s1
+-            (0, 2) + [10, +Infinity)
++            (0, 2) + [10, +oo)
+             sage: s1.inf()
+             0
+ 
+             sage: s2 = RealSet(1,3) + RealSet.unbounded_below_closed(-10);  s2
+-            (-Infinity, -10] + (1, 3)
++            (-oo, -10] + (1, 3)
+             sage: s2.inf()
+             -Infinity
+         """
+@@ -1039,12 +1216,12 @@
+         EXAMPLES::
+ 
+             sage: s1 = RealSet(0,2) + RealSet.unbounded_above_closed(10);  s1
+-            (0, 2) + [10, +Infinity)
++            (0, 2) + [10, +oo)
+             sage: s1.sup()
+             +Infinity
+ 
+             sage: s2 = RealSet(1,3) + RealSet.unbounded_below_closed(-10);  s2
+-            (-Infinity, -10] + (1, 3)
++            (-oo, -10] + (1, 3)
+             sage: s2.sup()
+             3
+         """
+@@ -1063,17 +1240,17 @@
+         EXAMPLES::
+ 
+             sage: RealSet(0,1).complement()
+-            (-Infinity, 0] + [1, +Infinity)
++            (-oo, 0] + [1, +oo)
+        
+             sage: s1 = RealSet(0,2) + RealSet.unbounded_above_closed(10);  s1
+-            (0, 2) + [10, +Infinity)
++            (0, 2) + [10, +oo)
+             sage: s1.complement()
+-            (-Infinity, 0] + [2, 10)
++            (-oo, 0] + [2, 10)
+ 
+             sage: s2 = RealSet(1,3) + RealSet.unbounded_below_closed(-10);  s2
+-            (-Infinity, -10] + (1, 3)
++            (-oo, -10] + (1, 3)
+             sage: s2.complement()
+-            (-10, 1] + [3, +Infinity)
++            (-10, 1] + [3, +oo)
+         """
+         n = self.n_components()
+         if n == 0:
+@@ -1095,13 +1272,13 @@
+             intervals.append(i)
+         return RealSet(*intervals)
+                              
+-    def difference(self, other):
++    def difference(self, *other):
+         """
+         Return ``self`` with ``other`` subtracted
+ 
+         INPUT:
+         
+-        - ``other`` -- a :class:`RealSet`.
++        - ``other`` -- a :class:`RealSet` or data that defines one.
+ 
+         OUTPUT:
+         
+@@ -1113,18 +1290,164 @@
+         A new :class:`RealSet`
+ 
+             sage: s1 = RealSet(0,2) + RealSet.unbounded_above_closed(10);  s1
+-            (0, 2) + [10, +Infinity)
++            (0, 2) + [10, +oo)
+             sage: s2 = RealSet(1,3) + RealSet.unbounded_below_closed(-10);  s2
+-            (-Infinity, -10] + (1, 3)
++            (-oo, -10] + (1, 3)
+             sage: s1.difference(s2)
+-            (0, 1] + [10, +Infinity)
++            (0, 1] + [10, +oo)
+             sage: s1 - s2    # syntactic sugar
+-            (0, 1] + [10, +Infinity)
++            (0, 1] + [10, +oo)
+             sage: s2.difference(s1)
+-            (-Infinity, -10] + [2, 3)
++            (-oo, -10] + [2, 3)
+             sage: s2 - s1    # syntactic sugar
+-            (-Infinity, -10] + [2, 3)
++            (-oo, -10] + [2, 3)
++            sage: s1.difference(1,11)
++            (0, 1] + [11, +oo)
+         """
++        other = RealSet(*other)
          return self.intersection(other.complement())
  
      __sub__ = difference
 +        EXAMPLES::
 +        
 +            sage: s = RealSet(0,2) + RealSet.unbounded_above_closed(10);  s
-+            (0, 2) + [10, +Infinity)
++            (0, 2) + [10, +oo)
 +            sage: s.contains(1)
 +            True
 +            sage: s.contains(0)
 +    
 +    __contains__ = contains
 +    
++    def is_included_in(self, *other):
++        r"""
++        Tests interval inclusion
++            
++        INPUT:
++
++        - ``*args`` -- a :class:`RealSet` or something that defines
++          one.
++
++        OUTPUT:
++        
++        Boolean.
++
++        EXAMPLES::
++        
++            sage: I = RealSet((1,2))
++            sage: J = RealSet((1,3))
++            sage: K = RealSet((2,3))
++            sage: I.is_included_in(J)
++            True
++            sage: J.is_included_in(K)
++            False
++        """
++        return RealSet(*other).intersection(self) == self
++
 +    def an_element(self):
 +        """
 +        Return a point of the set
 +            return i.upper()
 +        return (i.lower() + i.upper())/ZZ(2)
 +
-+    def is_disjoint_from(self, other):
++    def is_disjoint_from(self, *other):
 +        """
 +        Test whether the two sets are disjoint
 +
++        INPUT:
++
++        - ``other`` -- a :class:`RealSet` or data defining one.
++
 +        OUTPUT:
 +
 +        Boolean.
 +            [1, 2]
 +            sage: s1.is_disjoint_from(s2)
 +            True
++            sage: s1.is_disjoint_from([1, 2])
++            True
 +        """
++        other = RealSet(*other)
 +        return self.intersection(other).is_empty()
 +
 +    @staticmethod
 +       
 +        INPUT:
 +
-+        - ``*real_set_collection`` -- a list/tuple/iterable of real
-+          sets.
++        - ``*real_set_collection`` -- a list/tuple/iterable of
++          :class:`RealSet`.
 + 
 +        OUTPUT:
 +        

File trac_14523_readline.patch

 # HG changeset patch
-# Parent 9e5420548311780051bce6ca1f3100de71ce0b36
+# Parent 1735ebddf6d8ea7f338308e8a6d34b69be13235b
 
 Add interface to readline and clear up signal handling
 
 diff --git a/sage/misc/sage_extension.py b/sage/misc/sage_extension.py
 --- a/sage/misc/sage_extension.py
 +++ b/sage/misc/sage_extension.py
-@@ -401,9 +401,9 @@
+@@ -98,6 +98,7 @@
+             sage: shell.run_cell('%attach ' + tmp)
+             sage: shell.run_cell('a')
+             2
++            sage: sleep(1)  # filesystem timestamp granularity
+             sage: f = open(tmp, 'w'); f.write('a = 3\n'); f.close()
+ 
+         Note that the doctests are never really at the command prompt, so
+@@ -401,9 +402,9 @@
          self.init_inspector()
          self.init_line_transforms()
          self.register_interface_magics()

File trac_14801_piecewiese.patch

  AUTHORS:
  
  - David Joyner (2006-04): initial version
-@@ -44,1674 +44,426 @@
+@@ -44,1674 +44,482 @@
  
  - Paul Butler (2009-01): added indefinite integration and default_variable
  
 -            sage: f = Piecewise([[(0,1),f1],[(1,2),f2]])
 -            sage: f.length()
 -            2
--        """
++        for domain, func in parameters:
++            if domain.contains(point):
++                return subs_map.apply_to(func, 0)
++        raise ValueError('point is not in the domain')
++
++    @staticmethod
++    def in_operands(ex):
+         """
 -        return self._length
 - 
 -    def __repr__(self):
 -            tex.append('%s &\\text{on $(%s, %s)$}\\cr\n' % (latex(f), left, right))
 -        tex.append(r'\end{cases}')
 -        return ''.join(tex)
-+        for domain, func in parameters:
-+            print domain, point, domain.contains(point)
-+            if domain.contains(point):
-+                return subs_map.apply_to(func, 0)
-+        raise ValueError('point is not in the domain')
++        Return whether a symbolic expression contains a piecewise
++        function as operand
  
 -    def intervals(self):
 -        """
 -        """
 -        endpoints = sum(self.intervals(), ())
 -        return (min(endpoints), max(endpoints))
- 
+-
 -    def functions(self):
 -        """
 -        Returns the list of functions (the "pieces").
 -        if xmax > b:
 -            list_of_pairs = list_of_pairs + [[(b, xmax), zero]]
 -        return Piecewise(list_of_pairs)
-+    class EvaluationMethods:
- 
+-
 -    def unextend(self):
 -        """
 -        This removes any parts in the front or back of the function which
 -        if funcs[-1] == 0:
 -            list_of_pairs = list_of_pairs[:-1]
 -        return Piecewise(list_of_pairs)
-+        def expression_at(self, parameters, variable, point):
-+            """
-+            Return the expression defining the piecewise function at
-+            ``value``
- 
+-
 -    def _riemann_sum_helper(self, N, func, initial=0):
 -        """
 -        A helper function for computing Riemann sums.
 -        
--        INPUT:
--        
+         INPUT:
+         
 -        
 -        -  ``N`` - the number of subdivisions
 -        
 -            x1 = a+(i+1)*h
 -            rsum += func(x0, x1)
 -        return rsum
-+            INPUT:
-+            
-+            - ``point`` -- a real number.
++        - ``ex`` -- a symbolic expression.
  
 -    def riemann_sum_integral_approximation(self,N,mode=None):
 -        """
 -            return self._riemann_sum_helper(N, lambda x0, x1: (x1-x0)*self((x0+x1)/2))
 -        else:
 -            raise ValueError, "invalid mode"
-+            OUTPUT:
++        OUTPUT:
  
 -    def riemann_sum(self,N,mode=None):
 -        """
 -        else:
 -            raise ValueError, "invalid mode"
 -        return Piecewise(rsum)
-+            The symbolic expression defining the function value at the
-+            given ``point``.
- 
+-
 -    def trapezoid(self,N):
 -        """
 -        Returns the piecewise line function defined by the trapezoid rule
 -            sage: Q = tf.plot(rgbcolor=(0.7,0.6,0.6), plot_points=40)
 -            sage: L = add([line([[a,0],[a,f(a)]],rgbcolor=(0.7,0.6,0.6)) for (a,b),f in tf.list()])
 -            sage: P+Q+L
-+            EXAMPLES::
- 
+-
 -        TESTS:
-+                sage: f = piecewise([([0,0], sin(x)), ((0,2), cos(x))]);  f
-+                piecewise(x|-->sin(x) on {0}, x|-->cos(x) on (0, 2); x)
-+                sage: f.expression_at(0)
-+                sin(x)
-+                sage: f.expression_at(1)
-+                cos(x)
-+                sage: f.expression_at(2)
-+                Traceback (most recent call last):
-+                ...
-+                ValueError: point is not in the domain
-+            """
-+            for domain, func in parameters:
-+                if domain.contains(point):
-+                    return func
-+            raise ValueError('point is not in the domain')
- 
+-
 -        Use variables other than x (:trac:`13836`)::
-+        which_function = expression_at
- 
+-
 -            sage: R.<y> = QQ[]
 -            sage: f1 = y^2
 -            sage: f2 = 5-y^2
 -            sage: f = Piecewise([[(0,1),f1],[(1,2),f2]])
 -            sage: f.trapezoid(4)
 -            Piecewise defined function with 4 parts, [[(0, 1/2), 1/2*y], [(1/2, 1), 9/2*y - 2], [(1, 3/2), 1/2*y + 2], [(3/2, 2), -7/2*y + 8]]
-+        def domains(self, parameters, variable):
-+            """
-+            Return the individual domains
-+            
-+            See also :meth:`~expressions`.
- 
+-
 -        """
 -        x = QQ[self.default_variable()].gen()
 -        def f(x0, x1):
 -            return [[(x0,x1),f0+(f1-f0)*(x1-x0)**(-1)*(x-x0)]]
 -        rsum = self._riemann_sum_helper(N, f, initial=[])
 -        return Piecewise(rsum)
-+            OUTPUT:
- 
+-
 -    def trapezoid_integral_approximation(self,N):
 -        """
 -        Returns the approximation given by the trapezoid rule for numerical
 -            f0, f1 = self(x0), self(x1)
 -            return ((f1+f0)/2)*(x1-x0)
 -        return self._riemann_sum_helper(N, f)
-+            The collection of domains of the component functions as a
-+            tuple of :class:`~sage.sets.real_set.RealSet`.
-+            
-+            EXAMPLES::
- 
+-
 -    def critical_points(self):
 -        """
 -        Return the critical points of this piecewise function.
 -        
 -        .. warning::
-+                sage: f = piecewise([([0,0], sin(x)), ((0,2), cos(x))]);  f
-+                piecewise(x|-->sin(x) on {0}, x|-->cos(x) on (0, 2); x)
-+                sage: f.domains()
-+                ({0}, (0, 2))
-+            """
-+            return tuple(dom for dom, fun in parameters)
- 
+-
 -           Uses maxima, which prints the warning to use results with
 -           caution. Only works for piecewise functions whose parts are
 -           polynomials with real critical not occurring on the
 -            sage: expected = [5, 12, 13, 14]
 -            sage: all(abs(e-a) < 0.001 for e,a in zip(expected, f.critical_points()))
 -            True
-+        def domain(self, parameters, variable):
-+            """
-+            Return the domain
-+            
-+            OUTPUT:
- 
+-
 -        TESTS:
-+            The union of the domains of the individual pieces as a
-+            :class:`~sage.sets.real_set.RealSet`.
-+            
-+            EXAMPLES::
- 
+-
 -        Use variables other than x (:trac:`13836`)::
-+                sage: f = piecewise([([0,0], sin(x)), ((0,2), cos(x))]);  f
-+                piecewise(x|-->sin(x) on {0}, x|-->cos(x) on (0, 2); x)
-+                sage: f.domain()
-+                [0, 2)
-+            """
-+            intervals = []
-+            for domain, func in parameters:
-+                intervals += list(domain)
-+            return RealSet(*intervals)
- 
+-
 -            sage: R.<y> = QQ[]
 -            sage: f1 = y^0
 -            sage: f2 = 10*y - y^2
 -        """
 -        Returns the base ring of the function pieces.   This
 -        is useful when this class is extended.
-+        def __len__(self, parameters, variable):
-+            """
-+            Return the number of "pieces"
- 
+-
 -        EXAMPLES::
 -        
 -            sage: f1(x) = 1
 -            sage: f = Piecewise([[(0,1),f1],[(1,2),f2],[(2,3),f3]])
 -            sage: base_ring(f)
 -            Symbolic Ring
-+            OUTPUT:
- 
+-
 -        ::
-+            Integer.
- 
+-
 -            sage: R.<x> = QQ[]
 -            sage: f1 = x^0
 -            sage: f2 = 10*x - x^2
 -            Rational Field
 -        """
 -        return (self.functions()[0]).base_ring()
-+            EXAMPLES::
- 
+-
 -    def end_points(self):
 -        """
 -        Returns a list of all interval endpoints for this function.
 -        """
 -        intervals = self.intervals()
 -        return [ intervals[0][0] ] + [b for a,b in intervals]
-+                sage: f = piecewise([([0,0], sin(x)), ((0,2), cos(x))]);  f
-+                piecewise(x|-->sin(x) on {0}, x|-->cos(x) on (0, 2); x)
-+                sage: len(f)
-+                2
-+            """
-+            len(parameters)
- 
+-
 -    def __call__(self,x0):
 -        """
 -        Evaluates self at x0. Returns the average value of the jump if x0
 -            if endpts[i] < x0 < endpts[i+1]:
 -                return self.functions()[i](x0)
 -        raise ValueError,"Value not defined outside of domain."
-+        def expressions(self, parameters, variable):
-+            """
-+            Return the individual domains
-+            
-+            See also :meth:`~domains`.
- 
+-
 -    def which_function(self,x0):
 -        """
 -        Returns the function piece used to evaluate self at x0.
 -            if a <= x0 <= b:
 -                return f
 -        raise ValueError,"Function not defined outside of domain."
-+            OUTPUT:
- 
+-
 -    def default_variable(self):
 -        r"""
 -        Return the default variable. The default variable is defined as the
 -        first variable in the first piece that has a variable. If no pieces have
 -        a variable (each piece is a constant value), `x` is returned.
-+            The collection of expressions of the component functions.
-+            
-+            EXAMPLES::
- 
+-
 -        The result is cached.
-+                sage: f = piecewise([([0,0], sin(x)), ((0,2), cos(x))]);  f
-+                piecewise(x|-->sin(x) on {0}, x|-->cos(x) on (0, 2); x)
-+                sage: f.expressions()
-+                (sin(x), cos(x))
-+            """
-+            return tuple(fun for dom, fun in parameters)
- 
+-
 -        AUTHOR: Paul Butler
-+        def iteritems(self, parameters, variable):
-+            for pair in parameters:
-+                yield pair
- 
+-
 -        EXAMPLES::
 -        
 -            sage: f1(x) = 1
 -            sage: p = Piecewise([[(0,1),f1],[(1,4),f2]])
 -            sage: p.default_variable()
 -            x
-+        def __call__(self, parameters, variable, value=None, **kwds):
-+            """
-+            Call the piecewise function
- 
+-
 -            sage: f1 = 3*var('y')
 -            sage: p = Piecewise([[(0,1),4],[(1,4),f1]])
 -            sage: p.default_variable()
 -            y
-+            EXAMPLES::
- 
+-
 -        """
 -        try:
 -            return self.__default_variable
 -        v = var('x')
 -        self.__default_value = v
 -        return v
+-
+-    def integral(self, x=None, a=None, b=None, definite=False):
+-        r"""
+-        By default, returns the indefinite integral of the function.
+-        If definite=True is given, returns the definite integral.
+-
+-        AUTHOR: 
+-
+-        - Paul Butler
++        Boolean
+ 
+         EXAMPLES::
+ 
+-            sage: f1(x) = 1-x
+-            sage: f = Piecewise([[(0,1),1],[(1,2),f1]])
+-            sage: f.integral(definite=True)
+-            1/2
++            sage: f = piecewise([([0,0], sin(x)), ((0,2), cos(x))]);  f
++            sage: piecewise.in_operands(f)
++            True
++            sage: piecewise.in_operands(1+sin(f))
++            True
++            sage: piecewise.in_operands(1+sin(0*f))
++            False
++        """
++        def is_piecewise(ex):
++            result = ex.operator() is piecewise
++            for op in ex.operands():
++                result = result or is_piecewise(op)
++            return result
++        return is_piecewise(ex)
++
++
++    @staticmethod
++    def simplify():
++        return self
++
++
++    class EvaluationMethods:
++
++        def expression_at(self, parameters, variable, point):
++            """
++            Return the expression defining the piecewise function at
++            ``value``
++
++            INPUT:
++            
++            - ``point`` -- a real number.
++
++            OUTPUT:
++
++            The symbolic expression defining the function value at the
++            given ``point``.
++
++            EXAMPLES::
++
++                sage: f = piecewise([([0,0], sin(x)), ((0,2), cos(x))]);  f
++                piecewise(x|-->sin(x) on {0}, x|-->cos(x) on (0, 2); x)
++                sage: f.expression_at(0)
++                sin(x)
++                sage: f.expression_at(1)
++                cos(x)
++                sage: f.expression_at(2)
++                Traceback (most recent call last):
++                ...
++                ValueError: point is not in the domain
++            """
++            for domain, func in parameters:
++                if domain.contains(point):
++                    return func
++            raise ValueError('point is not in the domain')
++
++        which_function = expression_at
++
++        def domains(self, parameters, variable):
++            """
++            Return the individual domains
++            
++            See also :meth:`~expressions`.
++
++            OUTPUT:
++
++            The collection of domains of the component functions as a
++            tuple of :class:`~sage.sets.real_set.RealSet`.
++            
++            EXAMPLES::
++
++                sage: f = piecewise([([0,0], sin(x)), ((0,2), cos(x))]);  f
++                piecewise(x|-->sin(x) on {0}, x|-->cos(x) on (0, 2); x)
++                sage: f.domains()
++                ({0}, (0, 2))
++            """
++            return tuple(dom for dom, fun in parameters)
++
++        def domain(self, parameters, variable):
++            """
++            Return the domain
++            
++            OUTPUT:
++
++            The union of the domains of the individual pieces as a
++            :class:`~sage.sets.real_set.RealSet`.
++            
++            EXAMPLES::
++
++                sage: f = piecewise([([0,0], sin(x)), ((0,2), cos(x))]);  f
++                piecewise(x|-->sin(x) on {0}, x|-->cos(x) on (0, 2); x)
++                sage: f.domain()
++                [0, 2)
++            """
++            intervals = []
++            for domain, func in parameters:
++                intervals += list(domain)
++            return RealSet(*intervals)
++
++        def __len__(self, parameters, variable):
++            """
++            Return the number of "pieces"
++
++            OUTPUT:
++
++            Integer.
++
++            EXAMPLES::
++
++                sage: f = piecewise([([0,0], sin(x)), ((0,2), cos(x))]);  f
++                piecewise(x|-->sin(x) on {0}, x|-->cos(x) on (0, 2); x)
++                sage: len(f)
++                2
++            """
++            return len(parameters)
++
++        def expressions(self, parameters, variable):
++            """
++            Return the individual domains
++            
++            See also :meth:`~domains`.
++
++            OUTPUT:
++
++            The collection of expressions of the component functions.
++            
++            EXAMPLES::
++
++                sage: f = piecewise([([0,0], sin(x)), ((0,2), cos(x))]);  f
++                piecewise(x|-->sin(x) on {0}, x|-->cos(x) on (0, 2); x)
++                sage: f.expressions()
++                (sin(x), cos(x))
++            """
++            return tuple(fun for dom, fun in parameters)
++
++        def iteritems(self, parameters, variable):
++            for pair in parameters:
++                yield pair
++
++        def __call__(self, parameters, variable, value=None, **kwds):
++            """
++            Call the piecewise function
++
++            EXAMPLES::
++
 +                sage: f = piecewise([([0,0], sin(x)), ((0,2), cos(x))]);  f
 +                piecewise(x|-->sin(x) on {0}, x|-->cos(x) on (0, 2); x)
 +                sage: f(0)
 +            if value is not None:
 +                substitution[variable] = value
 +            return self.subs(substitution)
- 
--    def integral(self, x=None, a=None, b=None, definite=False):
--        r"""
--        By default, returns the indefinite integral of the function.
--        If definite=True is given, returns the definite integral.
++
 +        def _fast_float_(self, *args):
 +            """
 +            Do not support the old ``fast_float``
- 
--        AUTHOR: 
++
 +            OUTPUT:
- 
--        - Paul Butler
++
 +            This method raises ``NotImplementedError`` so that
 +            plotting uses the newer `fast_callable` implementation.
- 
--        EXAMPLES::
++
 +            EXAMPLES::
 +            
 +                sage: f = piecewise([([0,0], sin(x)), ((0,2), cos(x))])
 +                NotImplementedError
 +            """
 +            raise NotImplementedError
- 
--            sage: f1(x) = 1-x
--            sage: f = Piecewise([[(0,1),1],[(1,2),f1]])
--            sage: f.integral(definite=True)
--            1/2
--        
--        ::
--        
--            sage: f1(x) = -1
--            sage: f2(x) = 2
--            sage: f = Piecewise([[(0,pi/2),f1],[(pi/2,pi),f2]])
--            sage: f.integral(definite=True)
--            1/2*pi
++
 +        def _fast_callable_(self, parameters, variable, etb):
 +            """
 +            Override the ``fast_callable``
 +            A :class:`~sage.ext.fast_callable.ExpressionCall`
 +            representing the piecewise function in the expression
 +            tree.
-             
++            
++            EXAMPLES::
++
++                sage: p = piecewise([((-1, 0), -x), ([0, 1], x)], var=x)
++                sage: from sage.ext.fast_callable import ExpressionTreeBuilder
++                sage: etb = ExpressionTreeBuilder(vars=['x'])
++                sage: p._fast_callable_(etb)
++                {CommutativeRings.element_class}(v_0)
++            """
++            # print 'ev_fast_cal', parameters, variable, etb
++            self = piecewise(parameters, var=variable)
++            return etb.call(self, variable)
++
++        def restriction(self, parameters, variable, restricted_domain):
++            """
++            Restrict the domain
++
++            INPUT:
++            
++            - ``restricted_domain`` -- a
++              :class:`~sage.sets.real_set.RealSet` or something that
++              defines one.
++
++            OUTPUT:
++
++            A new piecewise function obtained by restricting the domain.
++
++            EXAMPLES::
++
++                sage: f = piecewise([((-oo, oo), x)]);  f
++                piecewise(x|-->x on (-Infinity, +Infinity); x)
++                sage: f.restriction([[-1,1], [3,3]])
++                piecewise(x|-->x on [-1, 1] + {3}; x)
++            """
++            restricted_domain = RealSet(*restricted_domain)
++            new_param = []
++            for domain, func in parameters:
++                domain = domain.intersection(restricted_domain)
++                new_param.append((domain, func))
++            return piecewise(new_param, var=variable)
++
++        def extension(self, parameters, variable, extension, extension_domain=None):
++            """
++            Extend the function
++
++            INPUT:
++
++            - ``extension`` -- a symbolic expression
++
++            - ``extension_domain`` -- a
++              :class:`~sage.sets.real_set.RealSet` or ``None``
++              (default). The domain of the extension. By default, the
++              entire complement of the current domain.
++
++            EXAMPLES::
++
++                sage: f = piecewise([((-1,1), x)]);  f
++                piecewise(x|-->x on (-1, 1); x)
++                sage: f.extension(0)
++                piecewise(x|-->x on (-1, 1), x|-->0 on (-Infinity, -1] + [1, +Infinity); x)
++                sage: g = f.extension(1, RealSet.unbounded_above_closed(1));  g
++                piecewise(x|-->x on (-1, 1), x|-->1 on [1, +Infinity); x)
++                sage: g(3)
++                1
++            """
++            self = piecewise(parameters, var=variable)
++            if extension_domain is None:
++                extension_domain = self.domain().complement()
++            ext = ((extension_domain, SR(extension)),)
++            return piecewise(parameters + ext, var=variable)
+         
+-        ::
+-        
+-            sage: f1(x) = -1
+-            sage: f2(x) = 2
+-            sage: f = Piecewise([[(0,pi/2),f1],[(pi/2,pi),f2]])
+-            sage: f.integral(definite=True)
+-            1/2*pi
+-            
 -            sage: f1(x) = 2
 -            sage: f2(x) = 3 - x
 -            sage: f = Piecewise([[(-2, 0), f1], [(0, 3), f2]])
 -            sage: f.integral()
 -            Piecewise defined function with 2 parts, [[(-2, 0), x |--> 2*x + 4], [(0, 3), x |--> -1/2*x^2 + 3*x + 4]]
-+            EXAMPLES::
++        def pieces(self, parameters, variable):
++            """
++            Return the "pieces"
  
 -            sage: f1(y) = -1
 -            sage: f2(y) = y + 3
 -            sage: F = f.integral(y)
 -            sage: F
 -            Piecewise defined function with 5 parts, [[(-4, -3), y |--> -y - 4], [(-3, -2), y |--> 1/2*y^2 + 3*y + 7/2], [(-2, 0), y |--> -1/2*y^2 - y - 1/2], [(0, 2), y |--> 1/3*y^3 - y - 1/2], [(2, 3), y |--> 3*y - 35/6]]
-+                sage: p = piecewise([((-1, 0), -x), ([0, 1], x)], var=x)
-+                sage: from sage.ext.fast_callable import ExpressionTreeBuilder
-+                sage: etb = ExpressionTreeBuilder(vars=['x'])
-+                sage: p._fast_callable_(etb)
-+                {CommutativeRings.element_class}(v_0)
-+            """
-+            print 'ev_fast_cal', parameters, variable, etb
-+            self = piecewise(parameters, var=variable)
-+            return etb.call(self, variable)
-+
-+        def restriction(self, parameters, variable, restricted_domain):
-+            """
-+            Restrict the domain
-+
-+            INPUT:
-             
+-            
 -        Ensure results are consistent with FTC::
-+            - ``restricted_domain`` -- a
-+              :class:`~sage.sets.real_set.RealSet` or something that
-+              defines one.
++            OUTPUT:
  
 -            sage: F(-3) - F(-4)
 -            -1
 -            19/6
 -            
 -        ::
-+            OUTPUT:
++            A tuple of piecewise functions, each having only a single
++            expression.
  
 -            sage: f1(y) = (y+3)^2
 -            sage: f2(y) = y+3
 -            sage: f = Piecewise([[(-infinity, -3), f1], [(-3, 0), f2], [(0, infinity), f3]])
 -            sage: f.integral()
 -            Piecewise defined function with 3 parts, [[(-Infinity, -3), y |--> 1/3*y^3 + 3*y^2 + 9*y + 9], [(-3, 0), y |--> 1/2*y^2 + 3*y + 9/2], [(0, +Infinity), y |--> 3*y + 9/2]]
-+            A new piecewise function obtained by restricting the domain.
++            EXAMPLES::
  
 -        ::
-+            EXAMPLES::
++                sage: p = piecewise([((-1, 0), -x), ([0, 1], x)], var=x)
++                sage: p.pieces()
++                (piecewise(x|-->-x on (-1, 0); x), 
++                 piecewise(x|-->x on [0, 1]; x))
++            """
++            result = []
++            for domain, func in parameters:
++                result.append(piecewise([(domain, func)], var=variable))
++            return tuple(result)
  
 -            sage: f1(x) = e^(-abs(x))
 -            sage: f = Piecewise([[(-infinity, infinity), f1]])
 -            2
 -            sage: f.integral()
 -            Piecewise defined function with 1 parts, [[(-Infinity, +Infinity), x |--> -1/2*((sgn(x) - 1)*e^(2*x) - 2*e^x*sgn(x) + sgn(x) + 1)*e^(-x) - 1]]
-+                sage: f = piecewise([((-oo, oo), x)]);  f
-+                piecewise(x|-->x on (-Infinity, +Infinity); x)
-+                sage: f.restriction([[-1,1], [3,3]])
-+                piecewise(x|-->x on [-1, 1] + {3}; x)
-+            """
-+            restricted_domain = RealSet(*restricted_domain)
-+            new_param = []
-+            for domain, func in parameters:
-+                domain = domain.intersection(restricted_domain)
-+                new_param.append((domain, func))
-+            return piecewise(new_param, var=variable)
  
 -        ::
-+        def extension(self, parameters, variable, extension, extension_domain=None):
-+            """
-+            Extend the function
  
 -            sage: f = Piecewise([((0, 5), cos(x))])
 -            sage: f.integral()
 -            Piecewise defined function with 1 parts, [[(0, 5), x |--> sin(x)]]
-+            INPUT:
  
-+            - ``extension`` -- a symbolic expression
++piecewise = PiecewiseFunction()
  
 -        TESTS:
-+            - ``extension_domain`` -- a
-+              :class:`~sage.sets.real_set.RealSet` or ``None``
-+              (default). The domain of the extension. By default, the
-+              entire complement of the current domain.
++def Piecewise(*args, **kwds):
++    """
++    Deprecated spelling of ``piecewise``
  
 -        Verify that piecewise integrals of zero work (trac #10841)::
-+            EXAMPLES::
++    EXAMPLES::
  
 -            sage: f0(x) = 0 
 -            sage: f = Piecewise([[(0,1),f0]])
 -            sage: f = Piecewise([[(0,1), SR(0)]])
 -            sage: f.integral(x,0,1)
 -            0
--
++        sage: Piecewise([((-1, 0), -x), ([0, 1], x)], var=x)
++        doctest:...: DeprecationWarning: use lower-case piecewise instead
++        See http://trac.sagemath.org/14801 for details.
++        piecewise(x|-->-x on (-1, 0), x|-->x on [0, 1]; x)
++    """
++    from sage.misc.superseded import deprecation
++    deprecation(14801, 'use lower-case piecewise instead')
++    return piecewise(*args, **kwds)
+ 
 -        """
 -        if a != None and b != None:
 -            F = self.integral(x)
 -            return F(b) - F(a)
--
+ 
 -        if a != None or b != None:
 -            raise TypeError, 'only one endpoint given'
--
+ 
 -        area = 0 # cumulative definite integral of parts to the left of the current interval
 -        integrand_pieces = self.list()
 -        integrand_pieces.sort()
 -                             scale_function(n)
 -                             for n in srange(1,N)])
 -        return result.expand()
-+                sage: f = piecewise([((-1,1), x)]);  f
-+                piecewise(x|-->x on (-1, 1); x)
-+                sage: f.extension(0)
-+                piecewise(x|-->x on (-1, 1), x|-->0 on (-Infinity, -1] + [1, +Infinity); x)
-+                sage: g = f.extension(1, RealSet.unbounded_above_closed(1));  g
-+                piecewise(x|-->x on (-1, 1), x|-->1 on [1, +Infinity); x)
-+                sage: g(3)
-+                1
-+            """
-+            self = piecewise(parameters, var=variable)
-+            if extension_domain is None:
-+                extension_domain = self.domain().complement()
-+            ext = ((extension_domain, SR(extension)),)
-+            return piecewise(parameters + ext, var=variable)
-         
- 
+-        
+-
 -    def fourier_series_partial_sum(self,N,L):
 -        r"""
 -        Returns the partial sum
 -            -2*cos(x)/pi - sin(2*x)/pi + 2*sin(x)/pi - 1/4
 -        """
 -        return self._fourier_series_helper(N, L, lambda n: 1-n/N)
- 
+-
 -    def fourier_series_partial_sum_hann(self,N,L):
 -        r"""
 -        Returns the Hann-filtered partial sum (named after von Hann, not
 -        """
 -        from sage.all import cos, pi
 -        return self._fourier_series_helper(N, L, lambda n: (1+cos(pi*n/N))/2)
- 
+-
 -    def fourier_series_partial_sum_filtered(self,N,L,F):
 -        r"""
 -        Returns the "filtered" partial sum
 -        """
 -        from sage.plot.all import plot
 -        return plot(self.fourier_series_partial_sum(N,L), xmin, xmax, **kwds)
- 
+-
 -    def plot_fourier_series_partial_sum_cesaro(self,N,L,xmin,xmax, **kwds):
 -        r"""
 -        Plots the partial sum
 -            return (self.functions()[0](endpts[0]) + self.functions()[-1](endpts[-1]))/2
 -        else:
 -            return self(xnew)
- 
+-
 -    def cosine_series_coefficient(self,n,L):
 -        r"""
 -        Returns the n-th cosine series coefficient of
 -            sage: f = Piecewise([[(0,pi),f1]])
 -            sage: f.cosine_series_coefficient(0,pi)
 -            1/3*pi^2
-+piecewise = PiecewiseFunction()
- 
+-
 -        """
 -        from sage.all import cos, pi
 -        x = var('x')
 -        if is_Expression(result):
 -            return result.simplify_trig()
 -        return result
-+def Piecewise(*args, **kwds):
-+    """
-+    Deprecated spelling of ``piecewise``
- 
-+    EXAMPLES::
- 
+-
+-
 -    def sine_series_coefficient(self,n,L):
 -        r"""
 -        Returns the n-th sine series coefficient of
 -        -  ``L`` - (the period)/2
 -        
 -        OUTPUT:
-+        sage: Piecewise([((-1, 0), -x), ([0, 1], x)], var=x)
-+        doctest:...: DeprecationWarning: use lower-case piecewise instead
-+        See http://trac.sagemath.org/14801 for details.
-+        piecewise(x|-->-x on (-1, 0), x|-->x on [0, 1]; x)
-+    """
-+    from sage.misc.superseded import deprecation
-+    deprecation(14801, 'use lower-case piecewise instead')
-+    return piecewise(*args, **kwds)
- 
+-
 -        `b_n = \frac{2}{L}\int_{-L}^L f(x)\sin(n\pi x/L)dx` such
 -        that
 -