details: http://hg.sympy.org/sympy/rev/1ec456a9f32a changeset: 1823:1ec456a9f32a user: Andy R. Terrel <[EMAIL PROTECTED]> date: Fri Oct 17 08:33:19 2008 +0200 description: This patch implements evalf for piecewise functions.
diffs (48 lines): diff -r 1ab457e8e482 -r 1ec456a9f32a sympy/core/evalf.py --- a/sympy/core/evalf.py Fri Oct 17 08:33:14 2008 +0200 +++ b/sympy/core/evalf.py Fri Oct 17 08:33:19 2008 +0200 @@ -576,6 +576,20 @@ raise NotImplementedError return fatan(xre, prec, round_nearest), None, prec, None +def evalf_piecewise(expr, prec, options): + if 'subs' in options: + expr = expr.subs(options['subs']) + del options['subs'] + if hasattr(expr,'func'): + return evalf(expr, prec, options) + if type(expr) == float: + return evalf(C.Real(expr), prec, options) + if type(expr) == int: + return evalf(C.Integer(expr), prec, options) + + # We still have undefined symbols + raise NotImplementedError + #----------------------------------------------------------------------------# # # @@ -902,6 +916,7 @@ C.Integral : evalf_integral, C.Sum : evalf_sum, + C.Piecewise : evalf_piecewise, } def evalf(x, prec, options): diff -r 1ab457e8e482 -r 1ec456a9f32a sympy/functions/elementary/tests/test_piecewise.py --- a/sympy/functions/elementary/tests/test_piecewise.py Fri Oct 17 08:33:14 2008 +0200 +++ b/sympy/functions/elementary/tests/test_piecewise.py Fri Oct 17 08:33:19 2008 +0200 @@ -31,6 +31,12 @@ assert p.subs(x,-1) == 1 assert p.subs(x,1) == log(1) + # Test evalf + assert p.evalf() == p + assert p.evalf(subs={x:-2}) == -1 + assert p.evalf(subs={x:-1}) == 1 + assert p.evalf(subs={x:1}) == log(1) + # Test doit f_int = Piecewise((Integral(x,(x,0,1)), x < 1)) assert f_int.doit() == Piecewise( (1.0/2.0, x < 1) ) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---