calculus.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from sympy.assumptions import Predicate
  2. from sympy.multipledispatch import Dispatcher
  3. class FinitePredicate(Predicate):
  4. """
  5. Finite number predicate.
  6. Explanation
  7. ===========
  8. ``Q.finite(x)`` is true if ``x`` is a number but neither an infinity
  9. nor a ``NaN``. In other words, ``ask(Q.finite(x))`` is true for all
  10. numerical ``x`` having a bounded absolute value.
  11. Examples
  12. ========
  13. >>> from sympy import Q, ask, S, oo, I, zoo
  14. >>> from sympy.abc import x
  15. >>> ask(Q.finite(oo))
  16. False
  17. >>> ask(Q.finite(-oo))
  18. False
  19. >>> ask(Q.finite(zoo))
  20. False
  21. >>> ask(Q.finite(1))
  22. True
  23. >>> ask(Q.finite(2 + 3*I))
  24. True
  25. >>> ask(Q.finite(x), Q.positive(x))
  26. True
  27. >>> print(ask(Q.finite(S.NaN)))
  28. None
  29. References
  30. ==========
  31. .. [1] https://en.wikipedia.org/wiki/Finite
  32. """
  33. name = 'finite'
  34. handler = Dispatcher(
  35. "FiniteHandler",
  36. doc=("Handler for Q.finite. Test that an expression is bounded respect"
  37. " to all its variables.")
  38. )
  39. class InfinitePredicate(Predicate):
  40. """
  41. Infinite number predicate.
  42. ``Q.infinite(x)`` is true iff the absolute value of ``x`` is
  43. infinity.
  44. """
  45. # TODO: Add examples
  46. name = 'infinite'
  47. handler = Dispatcher(
  48. "InfiniteHandler",
  49. doc="""Handler for Q.infinite key."""
  50. )
  51. class PositiveInfinitePredicate(Predicate):
  52. """
  53. Positive infinity predicate.
  54. ``Q.positive_infinite(x)`` is true iff ``x`` is positive infinity ``oo``.
  55. """
  56. name = 'positive_infinite'
  57. handler = Dispatcher("PositiveInfiniteHandler")
  58. class NegativeInfinitePredicate(Predicate):
  59. """
  60. Negative infinity predicate.
  61. ``Q.negative_infinite(x)`` is true iff ``x`` is negative infinity ``-oo``.
  62. """
  63. name = 'negative_infinite'
  64. handler = Dispatcher("NegativeInfiniteHandler")