details:   http://hg.sympy.org/sympy/rev/8d7fc8ac251a
changeset: 1847:8d7fc8ac251a
user:      Andy R. Terrel <[EMAIL PROTECTED]>
date:      Wed Oct 22 22:39:07 2008 +0200
description:
Move evaluation of interval to _eval_interval method of Basic.  Allows for 
functions to override for integration with limits.

diffs (120 lines):

diff -r 95089a89cabd -r 8d7fc8ac251a sympy/core/basic.py
--- a/sympy/core/basic.py       Wed Oct 22 22:13:34 2008 +0200
+++ b/sympy/core/basic.py       Wed Oct 22 22:39:07 2008 +0200
@@ -1123,6 +1123,31 @@
             if e.has(p):
                 return True
         return False
+
+    def _eval_interval(self, x, a, b):
+        """
+        Returns evaluation over an interval.  For most funtions this is:
+
+        self.subs(x, b) - self.subs(x, a),
+
+        possibly using limit() if NaN is returned from subs.
+
+        """
+        from sympy.series import limit
+        A = self.subs(x, a)
+
+        if A is S.NaN:
+            A = limit(self, x, a)
+            if A is S.NaN:
+                return self
+
+        B = self.subs(x, b)
+
+        if B is S.NaN:
+            B = limit(self, x, b)
+        if B is S.NaN:
+            return self
+        return B - A
 
     def _eval_power(self, other):
         return None
diff -r 95089a89cabd -r 8d7fc8ac251a sympy/functions/elementary/piecewise.py
--- a/sympy/functions/elementary/piecewise.py   Wed Oct 22 22:13:34 2008 +0200
+++ b/sympy/functions/elementary/piecewise.py   Wed Oct 22 22:39:07 2008 +0200
@@ -116,14 +116,13 @@
         from sympy.integrals import integrate
         return  Piecewise(*[(integrate(e, x), c) for e, c in self.args])
 
-    def _eval_interval(self, sym, ab):
+    def _eval_interval(self, sym, a, b):
         """Evaluates the function along the sym in a given interval ab"""
         # FIXME: Currently only supports conds of type sym < Num, or Num < sym
         int_expr = []
-        a, b = ab
         mul = 1
         if a > b:
-            a = ab[1]; b = ab[0]; mul = -1
+            a, b, mul = b, a, -1
         default = None
 
         # Determine what intervals the expr,cond pairs affect.
@@ -179,20 +178,9 @@
                               ", ".join([str((h[0], h[1])) for h in holes])
 
         # Finally run through the intervals and sum the evaluation.
-        # TODO: Either refactor this code or Integral.doit to call 
_eval_interval
         ret_fun = 0
         for int_a, int_b, expr in int_expr:
-            B = expr.subs(sym, min(b,int_b))
-            if B is S.NaN:
-                B = limit(expr, sym, min(b,int_b))
-            if B is S.NaN:
-                return self
-            A = expr.subs(sym, max(a,int_a))
-            if A is S.NaN:
-                A = limit(expr, sym, max(a,int_a))
-            if A is S.NaN:
-                return self
-            ret_fun += B - A
+            ret_fun += expr._eval_interval(sym,  max(a, int_a), min(b, int_b))
         return mul * ret_fun
 
     def _eval_derivative(self, s):
diff -r 95089a89cabd -r 8d7fc8ac251a 
sympy/functions/elementary/tests/test_piecewise.py
--- a/sympy/functions/elementary/tests/test_piecewise.py        Wed Oct 22 
22:13:34 2008 +0200
+++ b/sympy/functions/elementary/tests/test_piecewise.py        Wed Oct 22 
22:39:07 2008 +0200
@@ -49,7 +49,7 @@
     f2 = x*y**2 + 3
     peval = Piecewise( (f1, x<0), (f2, x>0))
     peval_interval = f1.subs(x,0) - f1.subs(x,-1) + f2.subs(x,1) - f2.subs(x,0)
-    assert peval._eval_interval(x,(-1,1)) == peval_interval
+    assert peval._eval_interval(x, -1, 1) == peval_interval
 
     # Test integration
     p_int =  Piecewise((-x,x < -1), (x**3/3.0, x < 0), (-x + x*log(x), x >= 0))
diff -r 95089a89cabd -r 8d7fc8ac251a sympy/integrals/integrals.py
--- a/sympy/integrals/integrals.py      Wed Oct 22 22:13:34 2008 +0200
+++ b/sympy/integrals/integrals.py      Wed Oct 22 22:39:07 2008 +0200
@@ -132,26 +132,8 @@
                 if ab is None:
                     function = antideriv
                 else:
-                    if isinstance(antideriv,Piecewise):
-                        function = antideriv._eval_interval(x,ab)
-                        continue
-
                     a,b = ab
-                    A = antideriv.subs(x, a)
-
-                    if A is S.NaN:
-                        A = limit(antideriv, x, a)
-                    if A is S.NaN:
-                        return self
-
-                    B = antideriv.subs(x, b)
-
-                    if B is S.NaN:
-                        B = limit(antideriv, x, b)
-                    if B is S.NaN:
-                        return self
-
-                    function = B - A
+                    function = antideriv._eval_interval(x, a, b)
 
         return function
 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy-commits" group.
To post to this group, send email to sympy-commits@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sympy-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to