Spaces:
Sleeping
Sleeping
File size: 9,511 Bytes
6a86ad5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
from sympy.assumptions import Predicate
from sympy.multipledispatch import Dispatcher
class NegativePredicate(Predicate):
r"""
Negative number predicate.
Explanation
===========
``Q.negative(x)`` is true iff ``x`` is a real number and :math:`x < 0`, that is,
it is in the interval :math:`(-\infty, 0)`. Note in particular that negative
infinity is not negative.
A few important facts about negative numbers:
- Note that ``Q.nonnegative`` and ``~Q.negative`` are *not* the same
thing. ``~Q.negative(x)`` simply means that ``x`` is not negative,
whereas ``Q.nonnegative(x)`` means that ``x`` is real and not
negative, i.e., ``Q.nonnegative(x)`` is logically equivalent to
``Q.zero(x) | Q.positive(x)``. So for example, ``~Q.negative(I)`` is
true, whereas ``Q.nonnegative(I)`` is false.
- See the documentation of ``Q.real`` for more information about
related facts.
Examples
========
>>> from sympy import Q, ask, symbols, I
>>> x = symbols('x')
>>> ask(Q.negative(x), Q.real(x) & ~Q.positive(x) & ~Q.zero(x))
True
>>> ask(Q.negative(-1))
True
>>> ask(Q.nonnegative(I))
False
>>> ask(~Q.negative(I))
True
"""
name = 'negative'
handler = Dispatcher(
"NegativeHandler",
doc=("Handler for Q.negative. Test that an expression is strictly less"
" than zero.")
)
class NonNegativePredicate(Predicate):
"""
Nonnegative real number predicate.
Explanation
===========
``ask(Q.nonnegative(x))`` is true iff ``x`` belongs to the set of
positive numbers including zero.
- Note that ``Q.nonnegative`` and ``~Q.negative`` are *not* the same
thing. ``~Q.negative(x)`` simply means that ``x`` is not negative,
whereas ``Q.nonnegative(x)`` means that ``x`` is real and not
negative, i.e., ``Q.nonnegative(x)`` is logically equivalent to
``Q.zero(x) | Q.positive(x)``. So for example, ``~Q.negative(I)`` is
true, whereas ``Q.nonnegative(I)`` is false.
Examples
========
>>> from sympy import Q, ask, I
>>> ask(Q.nonnegative(1))
True
>>> ask(Q.nonnegative(0))
True
>>> ask(Q.nonnegative(-1))
False
>>> ask(Q.nonnegative(I))
False
>>> ask(Q.nonnegative(-I))
False
"""
name = 'nonnegative'
handler = Dispatcher(
"NonNegativeHandler",
doc=("Handler for Q.nonnegative.")
)
class NonZeroPredicate(Predicate):
"""
Nonzero real number predicate.
Explanation
===========
``ask(Q.nonzero(x))`` is true iff ``x`` is real and ``x`` is not zero. Note in
particular that ``Q.nonzero(x)`` is false if ``x`` is not real. Use
``~Q.zero(x)`` if you want the negation of being zero without any real
assumptions.
A few important facts about nonzero numbers:
- ``Q.nonzero`` is logically equivalent to ``Q.positive | Q.negative``.
- See the documentation of ``Q.real`` for more information about
related facts.
Examples
========
>>> from sympy import Q, ask, symbols, I, oo
>>> x = symbols('x')
>>> print(ask(Q.nonzero(x), ~Q.zero(x)))
None
>>> ask(Q.nonzero(x), Q.positive(x))
True
>>> ask(Q.nonzero(x), Q.zero(x))
False
>>> ask(Q.nonzero(0))
False
>>> ask(Q.nonzero(I))
False
>>> ask(~Q.zero(I))
True
>>> ask(Q.nonzero(oo))
False
"""
name = 'nonzero'
handler = Dispatcher(
"NonZeroHandler",
doc=("Handler for key 'nonzero'. Test that an expression is not identically"
" zero.")
)
class ZeroPredicate(Predicate):
"""
Zero number predicate.
Explanation
===========
``ask(Q.zero(x))`` is true iff the value of ``x`` is zero.
Examples
========
>>> from sympy import ask, Q, oo, symbols
>>> x, y = symbols('x, y')
>>> ask(Q.zero(0))
True
>>> ask(Q.zero(1/oo))
True
>>> print(ask(Q.zero(0*oo)))
None
>>> ask(Q.zero(1))
False
>>> ask(Q.zero(x*y), Q.zero(x) | Q.zero(y))
True
"""
name = 'zero'
handler = Dispatcher(
"ZeroHandler",
doc="Handler for key 'zero'."
)
class NonPositivePredicate(Predicate):
"""
Nonpositive real number predicate.
Explanation
===========
``ask(Q.nonpositive(x))`` is true iff ``x`` belongs to the set of
negative numbers including zero.
- Note that ``Q.nonpositive`` and ``~Q.positive`` are *not* the same
thing. ``~Q.positive(x)`` simply means that ``x`` is not positive,
whereas ``Q.nonpositive(x)`` means that ``x`` is real and not
positive, i.e., ``Q.nonpositive(x)`` is logically equivalent to
`Q.negative(x) | Q.zero(x)``. So for example, ``~Q.positive(I)`` is
true, whereas ``Q.nonpositive(I)`` is false.
Examples
========
>>> from sympy import Q, ask, I
>>> ask(Q.nonpositive(-1))
True
>>> ask(Q.nonpositive(0))
True
>>> ask(Q.nonpositive(1))
False
>>> ask(Q.nonpositive(I))
False
>>> ask(Q.nonpositive(-I))
False
"""
name = 'nonpositive'
handler = Dispatcher(
"NonPositiveHandler",
doc="Handler for key 'nonpositive'."
)
class PositivePredicate(Predicate):
r"""
Positive real number predicate.
Explanation
===========
``Q.positive(x)`` is true iff ``x`` is real and `x > 0`, that is if ``x``
is in the interval `(0, \infty)`. In particular, infinity is not
positive.
A few important facts about positive numbers:
- Note that ``Q.nonpositive`` and ``~Q.positive`` are *not* the same
thing. ``~Q.positive(x)`` simply means that ``x`` is not positive,
whereas ``Q.nonpositive(x)`` means that ``x`` is real and not
positive, i.e., ``Q.nonpositive(x)`` is logically equivalent to
`Q.negative(x) | Q.zero(x)``. So for example, ``~Q.positive(I)`` is
true, whereas ``Q.nonpositive(I)`` is false.
- See the documentation of ``Q.real`` for more information about
related facts.
Examples
========
>>> from sympy import Q, ask, symbols, I
>>> x = symbols('x')
>>> ask(Q.positive(x), Q.real(x) & ~Q.negative(x) & ~Q.zero(x))
True
>>> ask(Q.positive(1))
True
>>> ask(Q.nonpositive(I))
False
>>> ask(~Q.positive(I))
True
"""
name = 'positive'
handler = Dispatcher(
"PositiveHandler",
doc=("Handler for key 'positive'. Test that an expression is strictly"
" greater than zero.")
)
class ExtendedPositivePredicate(Predicate):
r"""
Positive extended real number predicate.
Explanation
===========
``Q.extended_positive(x)`` is true iff ``x`` is extended real and
`x > 0`, that is if ``x`` is in the interval `(0, \infty]`.
Examples
========
>>> from sympy import ask, I, oo, Q
>>> ask(Q.extended_positive(1))
True
>>> ask(Q.extended_positive(oo))
True
>>> ask(Q.extended_positive(I))
False
"""
name = 'extended_positive'
handler = Dispatcher("ExtendedPositiveHandler")
class ExtendedNegativePredicate(Predicate):
r"""
Negative extended real number predicate.
Explanation
===========
``Q.extended_negative(x)`` is true iff ``x`` is extended real and
`x < 0`, that is if ``x`` is in the interval `[-\infty, 0)`.
Examples
========
>>> from sympy import ask, I, oo, Q
>>> ask(Q.extended_negative(-1))
True
>>> ask(Q.extended_negative(-oo))
True
>>> ask(Q.extended_negative(-I))
False
"""
name = 'extended_negative'
handler = Dispatcher("ExtendedNegativeHandler")
class ExtendedNonZeroPredicate(Predicate):
"""
Nonzero extended real number predicate.
Explanation
===========
``ask(Q.extended_nonzero(x))`` is true iff ``x`` is extended real and
``x`` is not zero.
Examples
========
>>> from sympy import ask, I, oo, Q
>>> ask(Q.extended_nonzero(-1))
True
>>> ask(Q.extended_nonzero(oo))
True
>>> ask(Q.extended_nonzero(I))
False
"""
name = 'extended_nonzero'
handler = Dispatcher("ExtendedNonZeroHandler")
class ExtendedNonPositivePredicate(Predicate):
"""
Nonpositive extended real number predicate.
Explanation
===========
``ask(Q.extended_nonpositive(x))`` is true iff ``x`` is extended real and
``x`` is not positive.
Examples
========
>>> from sympy import ask, I, oo, Q
>>> ask(Q.extended_nonpositive(-1))
True
>>> ask(Q.extended_nonpositive(oo))
False
>>> ask(Q.extended_nonpositive(0))
True
>>> ask(Q.extended_nonpositive(I))
False
"""
name = 'extended_nonpositive'
handler = Dispatcher("ExtendedNonPositiveHandler")
class ExtendedNonNegativePredicate(Predicate):
"""
Nonnegative extended real number predicate.
Explanation
===========
``ask(Q.extended_nonnegative(x))`` is true iff ``x`` is extended real and
``x`` is not negative.
Examples
========
>>> from sympy import ask, I, oo, Q
>>> ask(Q.extended_nonnegative(-1))
False
>>> ask(Q.extended_nonnegative(oo))
True
>>> ask(Q.extended_nonnegative(0))
True
>>> ask(Q.extended_nonnegative(I))
False
"""
name = 'extended_nonnegative'
handler = Dispatcher("ExtendedNonNegativeHandler")
|