Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- data/home/.local/lib/python3.8/site-packages/sympy/core/benchmarks/__pycache__/__init__.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/benchmarks/__pycache__/bench_arit.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/benchmarks/__pycache__/bench_assumptions.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/benchmarks/__pycache__/bench_basic.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/benchmarks/__pycache__/bench_expand.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/benchmarks/__pycache__/bench_numbers.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/benchmarks/__pycache__/bench_sympify.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__init__.py +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/__init__.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_arit.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_assumptions.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_basic.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_cache.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_compatibility.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_complex.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_constructor_postprocessor.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_containers.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_count_ops.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_diff.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_equal.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_eval.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_evalf.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_expand.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_expr.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_exprtools.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_facts.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_function.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_kind.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_logic.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_match.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_multidimensional.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_noncommutative.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_numbers.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_operations.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_parameters.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_power.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_priority.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_random.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_relational.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_rules.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_singleton.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_sorting.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_subs.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_symbol.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_sympify.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_traversal.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_truediv.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_var.cpython-38.pyc +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/test_args.py +0 -0
- data/home/.local/lib/python3.8/site-packages/sympy/core/tests/test_arit.py +2472 -0
data/home/.local/lib/python3.8/site-packages/sympy/core/benchmarks/__pycache__/__init__.cpython-38.pyc
ADDED
|
Binary file (157 Bytes). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/benchmarks/__pycache__/bench_arit.cpython-38.pyc
ADDED
|
Binary file (1.51 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/benchmarks/__pycache__/bench_assumptions.cpython-38.pyc
ADDED
|
Binary file (544 Bytes). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/benchmarks/__pycache__/bench_basic.cpython-38.pyc
ADDED
|
Binary file (630 Bytes). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/benchmarks/__pycache__/bench_expand.cpython-38.pyc
ADDED
|
Binary file (1.02 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/benchmarks/__pycache__/bench_numbers.cpython-38.pyc
ADDED
|
Binary file (3.19 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/benchmarks/__pycache__/bench_sympify.cpython-38.pyc
ADDED
|
Binary file (491 Bytes). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__init__.py
ADDED
|
File without changes
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/__init__.cpython-38.pyc
ADDED
|
Binary file (152 Bytes). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_arit.cpython-38.pyc
ADDED
|
Binary file (65.8 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_assumptions.cpython-38.pyc
ADDED
|
Binary file (34.5 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_basic.cpython-38.pyc
ADDED
|
Binary file (12.4 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_cache.cpython-38.pyc
ADDED
|
Binary file (3.26 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_compatibility.cpython-38.pyc
ADDED
|
Binary file (417 Bytes). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_complex.cpython-38.pyc
ADDED
|
Binary file (13.4 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_constructor_postprocessor.cpython-38.pyc
ADDED
|
Binary file (3.13 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_containers.cpython-38.pyc
ADDED
|
Binary file (9.58 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_count_ops.cpython-38.pyc
ADDED
|
Binary file (6.19 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_diff.cpython-38.pyc
ADDED
|
Binary file (6.23 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_equal.cpython-38.pyc
ADDED
|
Binary file (2.43 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_eval.cpython-38.pyc
ADDED
|
Binary file (3.15 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_evalf.cpython-38.pyc
ADDED
|
Binary file (31.8 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_expand.cpython-38.pyc
ADDED
|
Binary file (14.4 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_expr.cpython-38.pyc
ADDED
|
Binary file (82.6 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_exprtools.cpython-38.pyc
ADDED
|
Binary file (16.9 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_facts.cpython-38.pyc
ADDED
|
Binary file (9.16 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_function.cpython-38.pyc
ADDED
|
Binary file (58.7 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_kind.cpython-38.pyc
ADDED
|
Binary file (2.69 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_logic.cpython-38.pyc
ADDED
|
Binary file (8.35 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_match.cpython-38.pyc
ADDED
|
Binary file (25 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_multidimensional.cpython-38.pyc
ADDED
|
Binary file (1.25 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_noncommutative.cpython-38.pyc
ADDED
|
Binary file (5.97 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_numbers.cpython-38.pyc
ADDED
|
Binary file (79.8 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_operations.cpython-38.pyc
ADDED
|
Binary file (4.49 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_parameters.cpython-38.pyc
ADDED
|
Binary file (3.29 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_power.cpython-38.pyc
ADDED
|
Binary file (25.6 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_priority.cpython-38.pyc
ADDED
|
Binary file (5.09 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_random.cpython-38.pyc
ADDED
|
Binary file (1.49 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_relational.cpython-38.pyc
ADDED
|
Binary file (46.6 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_rules.cpython-38.pyc
ADDED
|
Binary file (852 Bytes). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_singleton.cpython-38.pyc
ADDED
|
Binary file (2.06 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_sorting.cpython-38.pyc
ADDED
|
Binary file (1.67 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_subs.cpython-38.pyc
ADDED
|
Binary file (33.7 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_symbol.cpython-38.pyc
ADDED
|
Binary file (14.2 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_sympify.cpython-38.pyc
ADDED
|
Binary file (33 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_traversal.cpython-38.pyc
ADDED
|
Binary file (4.5 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_truediv.cpython-38.pyc
ADDED
|
Binary file (1.34 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/__pycache__/test_var.cpython-38.pyc
ADDED
|
Binary file (1.9 kB). View file
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/test_args.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/home/.local/lib/python3.8/site-packages/sympy/core/tests/test_arit.py
ADDED
|
@@ -0,0 +1,2472 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.core.add import Add
|
| 2 |
+
from sympy.core.basic import Basic
|
| 3 |
+
from sympy.core.mod import Mod
|
| 4 |
+
from sympy.core.mul import Mul
|
| 5 |
+
from sympy.core.numbers import (Float, I, Integer, Rational, comp, nan,
|
| 6 |
+
oo, pi, zoo)
|
| 7 |
+
from sympy.core.power import Pow
|
| 8 |
+
from sympy.core.singleton import S
|
| 9 |
+
from sympy.core.symbol import (Dummy, Symbol, symbols)
|
| 10 |
+
from sympy.core.sympify import sympify
|
| 11 |
+
from sympy.functions.combinatorial.factorials import factorial
|
| 12 |
+
from sympy.functions.elementary.complexes import (im, re, sign)
|
| 13 |
+
from sympy.functions.elementary.exponential import (exp, log)
|
| 14 |
+
from sympy.functions.elementary.integers import floor
|
| 15 |
+
from sympy.functions.elementary.miscellaneous import (Max, sqrt)
|
| 16 |
+
from sympy.functions.elementary.trigonometric import (atan, cos, sin)
|
| 17 |
+
from sympy.polys.polytools import Poly
|
| 18 |
+
from sympy.sets.sets import FiniteSet
|
| 19 |
+
|
| 20 |
+
from sympy.core.parameters import distribute, evaluate
|
| 21 |
+
from sympy.core.expr import unchanged
|
| 22 |
+
from sympy.utilities.iterables import permutations
|
| 23 |
+
from sympy.testing.pytest import XFAIL, raises, warns
|
| 24 |
+
from sympy.utilities.exceptions import SymPyDeprecationWarning
|
| 25 |
+
from sympy.core.random import verify_numerically
|
| 26 |
+
from sympy.functions.elementary.trigonometric import asin
|
| 27 |
+
|
| 28 |
+
from itertools import product
|
| 29 |
+
|
| 30 |
+
a, c, x, y, z = symbols('a,c,x,y,z')
|
| 31 |
+
b = Symbol("b", positive=True)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def same_and_same_prec(a, b):
|
| 35 |
+
# stricter matching for Floats
|
| 36 |
+
return a == b and a._prec == b._prec
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def test_bug1():
|
| 40 |
+
assert re(x) != x
|
| 41 |
+
x.series(x, 0, 1)
|
| 42 |
+
assert re(x) != x
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def test_Symbol():
|
| 46 |
+
e = a*b
|
| 47 |
+
assert e == a*b
|
| 48 |
+
assert a*b*b == a*b**2
|
| 49 |
+
assert a*b*b + c == c + a*b**2
|
| 50 |
+
assert a*b*b - c == -c + a*b**2
|
| 51 |
+
|
| 52 |
+
x = Symbol('x', complex=True, real=False)
|
| 53 |
+
assert x.is_imaginary is None # could be I or 1 + I
|
| 54 |
+
x = Symbol('x', complex=True, imaginary=False)
|
| 55 |
+
assert x.is_real is None # could be 1 or 1 + I
|
| 56 |
+
x = Symbol('x', real=True)
|
| 57 |
+
assert x.is_complex
|
| 58 |
+
x = Symbol('x', imaginary=True)
|
| 59 |
+
assert x.is_complex
|
| 60 |
+
x = Symbol('x', real=False, imaginary=False)
|
| 61 |
+
assert x.is_complex is None # might be a non-number
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def test_arit0():
|
| 65 |
+
p = Rational(5)
|
| 66 |
+
e = a*b
|
| 67 |
+
assert e == a*b
|
| 68 |
+
e = a*b + b*a
|
| 69 |
+
assert e == 2*a*b
|
| 70 |
+
e = a*b + b*a + a*b + p*b*a
|
| 71 |
+
assert e == 8*a*b
|
| 72 |
+
e = a*b + b*a + a*b + p*b*a + a
|
| 73 |
+
assert e == a + 8*a*b
|
| 74 |
+
e = a + a
|
| 75 |
+
assert e == 2*a
|
| 76 |
+
e = a + b + a
|
| 77 |
+
assert e == b + 2*a
|
| 78 |
+
e = a + b*b + a + b*b
|
| 79 |
+
assert e == 2*a + 2*b**2
|
| 80 |
+
e = a + Rational(2) + b*b + a + b*b + p
|
| 81 |
+
assert e == 7 + 2*a + 2*b**2
|
| 82 |
+
e = (a + b*b + a + b*b)*p
|
| 83 |
+
assert e == 5*(2*a + 2*b**2)
|
| 84 |
+
e = (a*b*c + c*b*a + b*a*c)*p
|
| 85 |
+
assert e == 15*a*b*c
|
| 86 |
+
e = (a*b*c + c*b*a + b*a*c)*p - Rational(15)*a*b*c
|
| 87 |
+
assert e == Rational(0)
|
| 88 |
+
e = Rational(50)*(a - a)
|
| 89 |
+
assert e == Rational(0)
|
| 90 |
+
e = b*a - b - a*b + b
|
| 91 |
+
assert e == Rational(0)
|
| 92 |
+
e = a*b + c**p
|
| 93 |
+
assert e == a*b + c**5
|
| 94 |
+
e = a/b
|
| 95 |
+
assert e == a*b**(-1)
|
| 96 |
+
e = a*2*2
|
| 97 |
+
assert e == 4*a
|
| 98 |
+
e = 2 + a*2/2
|
| 99 |
+
assert e == 2 + a
|
| 100 |
+
e = 2 - a - 2
|
| 101 |
+
assert e == -a
|
| 102 |
+
e = 2*a*2
|
| 103 |
+
assert e == 4*a
|
| 104 |
+
e = 2/a/2
|
| 105 |
+
assert e == a**(-1)
|
| 106 |
+
e = 2**a**2
|
| 107 |
+
assert e == 2**(a**2)
|
| 108 |
+
e = -(1 + a)
|
| 109 |
+
assert e == -1 - a
|
| 110 |
+
e = S.Half*(1 + a)
|
| 111 |
+
assert e == S.Half + a/2
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def test_div():
|
| 115 |
+
e = a/b
|
| 116 |
+
assert e == a*b**(-1)
|
| 117 |
+
e = a/b + c/2
|
| 118 |
+
assert e == a*b**(-1) + Rational(1)/2*c
|
| 119 |
+
e = (1 - b)/(b - 1)
|
| 120 |
+
assert e == (1 + -b)*((-1) + b)**(-1)
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def test_pow_arit():
|
| 124 |
+
n1 = Rational(1)
|
| 125 |
+
n2 = Rational(2)
|
| 126 |
+
n5 = Rational(5)
|
| 127 |
+
e = a*a
|
| 128 |
+
assert e == a**2
|
| 129 |
+
e = a*a*a
|
| 130 |
+
assert e == a**3
|
| 131 |
+
e = a*a*a*a**Rational(6)
|
| 132 |
+
assert e == a**9
|
| 133 |
+
e = a*a*a*a**Rational(6) - a**Rational(9)
|
| 134 |
+
assert e == Rational(0)
|
| 135 |
+
e = a**(b - b)
|
| 136 |
+
assert e == Rational(1)
|
| 137 |
+
e = (a + Rational(1) - a)**b
|
| 138 |
+
assert e == Rational(1)
|
| 139 |
+
|
| 140 |
+
e = (a + b + c)**n2
|
| 141 |
+
assert e == (a + b + c)**2
|
| 142 |
+
assert e.expand() == 2*b*c + 2*a*c + 2*a*b + a**2 + c**2 + b**2
|
| 143 |
+
|
| 144 |
+
e = (a + b)**n2
|
| 145 |
+
assert e == (a + b)**2
|
| 146 |
+
assert e.expand() == 2*a*b + a**2 + b**2
|
| 147 |
+
|
| 148 |
+
e = (a + b)**(n1/n2)
|
| 149 |
+
assert e == sqrt(a + b)
|
| 150 |
+
assert e.expand() == sqrt(a + b)
|
| 151 |
+
|
| 152 |
+
n = n5**(n1/n2)
|
| 153 |
+
assert n == sqrt(5)
|
| 154 |
+
e = n*a*b - n*b*a
|
| 155 |
+
assert e == Rational(0)
|
| 156 |
+
e = n*a*b + n*b*a
|
| 157 |
+
assert e == 2*a*b*sqrt(5)
|
| 158 |
+
assert e.diff(a) == 2*b*sqrt(5)
|
| 159 |
+
assert e.diff(a) == 2*b*sqrt(5)
|
| 160 |
+
e = a/b**2
|
| 161 |
+
assert e == a*b**(-2)
|
| 162 |
+
|
| 163 |
+
assert sqrt(2*(1 + sqrt(2))) == (2*(1 + 2**S.Half))**S.Half
|
| 164 |
+
|
| 165 |
+
x = Symbol('x')
|
| 166 |
+
y = Symbol('y')
|
| 167 |
+
|
| 168 |
+
assert ((x*y)**3).expand() == y**3 * x**3
|
| 169 |
+
assert ((x*y)**-3).expand() == y**-3 * x**-3
|
| 170 |
+
|
| 171 |
+
assert (x**5*(3*x)**(3)).expand() == 27 * x**8
|
| 172 |
+
assert (x**5*(-3*x)**(3)).expand() == -27 * x**8
|
| 173 |
+
assert (x**5*(3*x)**(-3)).expand() == x**2 * Rational(1, 27)
|
| 174 |
+
assert (x**5*(-3*x)**(-3)).expand() == x**2 * Rational(-1, 27)
|
| 175 |
+
|
| 176 |
+
# expand_power_exp
|
| 177 |
+
_x = Symbol('x', zero=False)
|
| 178 |
+
_y = Symbol('y', zero=False)
|
| 179 |
+
assert (_x**(y**(x + exp(x + y)) + z)).expand(deep=False) == \
|
| 180 |
+
_x**z*_x**(y**(x + exp(x + y)))
|
| 181 |
+
assert (_x**(_y**(x + exp(x + y)) + z)).expand() == \
|
| 182 |
+
_x**z*_x**(_y**x*_y**(exp(x)*exp(y)))
|
| 183 |
+
|
| 184 |
+
n = Symbol('n', even=False)
|
| 185 |
+
k = Symbol('k', even=True)
|
| 186 |
+
o = Symbol('o', odd=True)
|
| 187 |
+
|
| 188 |
+
assert unchanged(Pow, -1, x)
|
| 189 |
+
assert unchanged(Pow, -1, n)
|
| 190 |
+
assert (-2)**k == 2**k
|
| 191 |
+
assert (-1)**k == 1
|
| 192 |
+
assert (-1)**o == -1
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
def test_pow2():
|
| 196 |
+
# x**(2*y) is always (x**y)**2 but is only (x**2)**y if
|
| 197 |
+
# x.is_positive or y.is_integer
|
| 198 |
+
# let x = 1 to see why the following are not true.
|
| 199 |
+
assert (-x)**Rational(2, 3) != x**Rational(2, 3)
|
| 200 |
+
assert (-x)**Rational(5, 7) != -x**Rational(5, 7)
|
| 201 |
+
assert ((-x)**2)**Rational(1, 3) != ((-x)**Rational(1, 3))**2
|
| 202 |
+
assert sqrt(x**2) != x
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def test_pow3():
|
| 206 |
+
assert sqrt(2)**3 == 2 * sqrt(2)
|
| 207 |
+
assert sqrt(2)**3 == sqrt(8)
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
def test_mod_pow():
|
| 211 |
+
for s, t, u, v in [(4, 13, 497, 445), (4, -3, 497, 365),
|
| 212 |
+
(3.2, 2.1, 1.9, 0.1031015682350942), (S(3)/2, 5, S(5)/6, S(3)/32)]:
|
| 213 |
+
assert pow(S(s), t, u) == v
|
| 214 |
+
assert pow(S(s), S(t), u) == v
|
| 215 |
+
assert pow(S(s), t, S(u)) == v
|
| 216 |
+
assert pow(S(s), S(t), S(u)) == v
|
| 217 |
+
assert pow(S(2), S(10000000000), S(3)) == 1
|
| 218 |
+
assert pow(x, y, z) == x**y%z
|
| 219 |
+
raises(TypeError, lambda: pow(S(4), "13", 497))
|
| 220 |
+
raises(TypeError, lambda: pow(S(4), 13, "497"))
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def test_pow_E():
|
| 224 |
+
assert 2**(y/log(2)) == S.Exp1**y
|
| 225 |
+
assert 2**(y/log(2)/3) == S.Exp1**(y/3)
|
| 226 |
+
assert 3**(1/log(-3)) != S.Exp1
|
| 227 |
+
assert (3 + 2*I)**(1/(log(-3 - 2*I) + I*pi)) == S.Exp1
|
| 228 |
+
assert (4 + 2*I)**(1/(log(-4 - 2*I) + I*pi)) == S.Exp1
|
| 229 |
+
assert (3 + 2*I)**(1/(log(-3 - 2*I, 3)/2 + I*pi/log(3)/2)) == 9
|
| 230 |
+
assert (3 + 2*I)**(1/(log(3 + 2*I, 3)/2)) == 9
|
| 231 |
+
# every time tests are run they will affirm with a different random
|
| 232 |
+
# value that this identity holds
|
| 233 |
+
while 1:
|
| 234 |
+
b = x._random()
|
| 235 |
+
r, i = b.as_real_imag()
|
| 236 |
+
if i:
|
| 237 |
+
break
|
| 238 |
+
assert verify_numerically(b**(1/(log(-b) + sign(i)*I*pi).n()), S.Exp1)
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def test_pow_issue_3516():
|
| 242 |
+
assert 4**Rational(1, 4) == sqrt(2)
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
def test_pow_im():
|
| 246 |
+
for m in (-2, -1, 2):
|
| 247 |
+
for d in (3, 4, 5):
|
| 248 |
+
b = m*I
|
| 249 |
+
for i in range(1, 4*d + 1):
|
| 250 |
+
e = Rational(i, d)
|
| 251 |
+
assert (b**e - b.n()**e.n()).n(2, chop=1e-10) == 0
|
| 252 |
+
|
| 253 |
+
e = Rational(7, 3)
|
| 254 |
+
assert (2*x*I)**e == 4*2**Rational(1, 3)*(I*x)**e # same as Wolfram Alpha
|
| 255 |
+
im = symbols('im', imaginary=True)
|
| 256 |
+
assert (2*im*I)**e == 4*2**Rational(1, 3)*(I*im)**e
|
| 257 |
+
|
| 258 |
+
args = [I, I, I, I, 2]
|
| 259 |
+
e = Rational(1, 3)
|
| 260 |
+
ans = 2**e
|
| 261 |
+
assert Mul(*args, evaluate=False)**e == ans
|
| 262 |
+
assert Mul(*args)**e == ans
|
| 263 |
+
args = [I, I, I, 2]
|
| 264 |
+
e = Rational(1, 3)
|
| 265 |
+
ans = 2**e*(-I)**e
|
| 266 |
+
assert Mul(*args, evaluate=False)**e == ans
|
| 267 |
+
assert Mul(*args)**e == ans
|
| 268 |
+
args.append(-3)
|
| 269 |
+
ans = (6*I)**e
|
| 270 |
+
assert Mul(*args, evaluate=False)**e == ans
|
| 271 |
+
assert Mul(*args)**e == ans
|
| 272 |
+
args.append(-1)
|
| 273 |
+
ans = (-6*I)**e
|
| 274 |
+
assert Mul(*args, evaluate=False)**e == ans
|
| 275 |
+
assert Mul(*args)**e == ans
|
| 276 |
+
|
| 277 |
+
args = [I, I, 2]
|
| 278 |
+
e = Rational(1, 3)
|
| 279 |
+
ans = (-2)**e
|
| 280 |
+
assert Mul(*args, evaluate=False)**e == ans
|
| 281 |
+
assert Mul(*args)**e == ans
|
| 282 |
+
args.append(-3)
|
| 283 |
+
ans = (6)**e
|
| 284 |
+
assert Mul(*args, evaluate=False)**e == ans
|
| 285 |
+
assert Mul(*args)**e == ans
|
| 286 |
+
args.append(-1)
|
| 287 |
+
ans = (-6)**e
|
| 288 |
+
assert Mul(*args, evaluate=False)**e == ans
|
| 289 |
+
assert Mul(*args)**e == ans
|
| 290 |
+
assert Mul(Pow(-1, Rational(3, 2), evaluate=False), I, I) == I
|
| 291 |
+
assert Mul(I*Pow(I, S.Half, evaluate=False)) == sqrt(I)*I
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
def test_real_mul():
|
| 295 |
+
assert Float(0) * pi * x == 0
|
| 296 |
+
assert set((Float(1) * pi * x).args) == {Float(1), pi, x}
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
def test_ncmul():
|
| 300 |
+
A = Symbol("A", commutative=False)
|
| 301 |
+
B = Symbol("B", commutative=False)
|
| 302 |
+
C = Symbol("C", commutative=False)
|
| 303 |
+
assert A*B != B*A
|
| 304 |
+
assert A*B*C != C*B*A
|
| 305 |
+
assert A*b*B*3*C == 3*b*A*B*C
|
| 306 |
+
assert A*b*B*3*C != 3*b*B*A*C
|
| 307 |
+
assert A*b*B*3*C == 3*A*B*C*b
|
| 308 |
+
|
| 309 |
+
assert A + B == B + A
|
| 310 |
+
assert (A + B)*C != C*(A + B)
|
| 311 |
+
|
| 312 |
+
assert C*(A + B)*C != C*C*(A + B)
|
| 313 |
+
|
| 314 |
+
assert A*A == A**2
|
| 315 |
+
assert (A + B)*(A + B) == (A + B)**2
|
| 316 |
+
|
| 317 |
+
assert A**-1 * A == 1
|
| 318 |
+
assert A/A == 1
|
| 319 |
+
assert A/(A**2) == 1/A
|
| 320 |
+
|
| 321 |
+
assert A/(1 + A) == A/(1 + A)
|
| 322 |
+
|
| 323 |
+
assert set((A + B + 2*(A + B)).args) == \
|
| 324 |
+
{A, B, 2*(A + B)}
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
def test_mul_add_identity():
|
| 328 |
+
m = Mul(1, 2)
|
| 329 |
+
assert isinstance(m, Rational) and m.p == 2 and m.q == 1
|
| 330 |
+
m = Mul(1, 2, evaluate=False)
|
| 331 |
+
assert isinstance(m, Mul) and m.args == (1, 2)
|
| 332 |
+
m = Mul(0, 1)
|
| 333 |
+
assert m is S.Zero
|
| 334 |
+
m = Mul(0, 1, evaluate=False)
|
| 335 |
+
assert isinstance(m, Mul) and m.args == (0, 1)
|
| 336 |
+
m = Add(0, 1)
|
| 337 |
+
assert m is S.One
|
| 338 |
+
m = Add(0, 1, evaluate=False)
|
| 339 |
+
assert isinstance(m, Add) and m.args == (0, 1)
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
def test_ncpow():
|
| 343 |
+
x = Symbol('x', commutative=False)
|
| 344 |
+
y = Symbol('y', commutative=False)
|
| 345 |
+
z = Symbol('z', commutative=False)
|
| 346 |
+
a = Symbol('a')
|
| 347 |
+
b = Symbol('b')
|
| 348 |
+
c = Symbol('c')
|
| 349 |
+
|
| 350 |
+
assert (x**2)*(y**2) != (y**2)*(x**2)
|
| 351 |
+
assert (x**-2)*y != y*(x**2)
|
| 352 |
+
assert 2**x*2**y != 2**(x + y)
|
| 353 |
+
assert 2**x*2**y*2**z != 2**(x + y + z)
|
| 354 |
+
assert 2**x*2**(2*x) == 2**(3*x)
|
| 355 |
+
assert 2**x*2**(2*x)*2**x == 2**(4*x)
|
| 356 |
+
assert exp(x)*exp(y) != exp(y)*exp(x)
|
| 357 |
+
assert exp(x)*exp(y)*exp(z) != exp(y)*exp(x)*exp(z)
|
| 358 |
+
assert exp(x)*exp(y)*exp(z) != exp(x + y + z)
|
| 359 |
+
assert x**a*x**b != x**(a + b)
|
| 360 |
+
assert x**a*x**b*x**c != x**(a + b + c)
|
| 361 |
+
assert x**3*x**4 == x**7
|
| 362 |
+
assert x**3*x**4*x**2 == x**9
|
| 363 |
+
assert x**a*x**(4*a) == x**(5*a)
|
| 364 |
+
assert x**a*x**(4*a)*x**a == x**(6*a)
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
def test_powerbug():
|
| 368 |
+
x = Symbol("x")
|
| 369 |
+
assert x**1 != (-x)**1
|
| 370 |
+
assert x**2 == (-x)**2
|
| 371 |
+
assert x**3 != (-x)**3
|
| 372 |
+
assert x**4 == (-x)**4
|
| 373 |
+
assert x**5 != (-x)**5
|
| 374 |
+
assert x**6 == (-x)**6
|
| 375 |
+
|
| 376 |
+
assert x**128 == (-x)**128
|
| 377 |
+
assert x**129 != (-x)**129
|
| 378 |
+
|
| 379 |
+
assert (2*x)**2 == (-2*x)**2
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
def test_Mul_doesnt_expand_exp():
|
| 383 |
+
x = Symbol('x')
|
| 384 |
+
y = Symbol('y')
|
| 385 |
+
assert unchanged(Mul, exp(x), exp(y))
|
| 386 |
+
assert unchanged(Mul, 2**x, 2**y)
|
| 387 |
+
assert x**2*x**3 == x**5
|
| 388 |
+
assert 2**x*3**x == 6**x
|
| 389 |
+
assert x**(y)*x**(2*y) == x**(3*y)
|
| 390 |
+
assert sqrt(2)*sqrt(2) == 2
|
| 391 |
+
assert 2**x*2**(2*x) == 2**(3*x)
|
| 392 |
+
assert sqrt(2)*2**Rational(1, 4)*5**Rational(3, 4) == 10**Rational(3, 4)
|
| 393 |
+
assert (x**(-log(5)/log(3))*x)/(x*x**( - log(5)/log(3))) == sympify(1)
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
def test_Mul_is_integer():
|
| 397 |
+
k = Symbol('k', integer=True)
|
| 398 |
+
n = Symbol('n', integer=True)
|
| 399 |
+
nr = Symbol('nr', rational=False)
|
| 400 |
+
ir = Symbol('ir', irrational=True)
|
| 401 |
+
nz = Symbol('nz', integer=True, zero=False)
|
| 402 |
+
e = Symbol('e', even=True)
|
| 403 |
+
o = Symbol('o', odd=True)
|
| 404 |
+
i2 = Symbol('2', prime=True, even=True)
|
| 405 |
+
|
| 406 |
+
assert (k/3).is_integer is None
|
| 407 |
+
assert (nz/3).is_integer is None
|
| 408 |
+
assert (nr/3).is_integer is False
|
| 409 |
+
assert (ir/3).is_integer is False
|
| 410 |
+
assert (x*k*n).is_integer is None
|
| 411 |
+
assert (e/2).is_integer is True
|
| 412 |
+
assert (e**2/2).is_integer is True
|
| 413 |
+
assert (2/k).is_integer is None
|
| 414 |
+
assert (2/k**2).is_integer is None
|
| 415 |
+
assert ((-1)**k*n).is_integer is True
|
| 416 |
+
assert (3*k*e/2).is_integer is True
|
| 417 |
+
assert (2*k*e/3).is_integer is None
|
| 418 |
+
assert (e/o).is_integer is None
|
| 419 |
+
assert (o/e).is_integer is False
|
| 420 |
+
assert (o/i2).is_integer is False
|
| 421 |
+
assert Mul(k, 1/k, evaluate=False).is_integer is None
|
| 422 |
+
assert Mul(2., S.Half, evaluate=False).is_integer is None
|
| 423 |
+
assert (2*sqrt(k)).is_integer is None
|
| 424 |
+
assert (2*k**n).is_integer is None
|
| 425 |
+
|
| 426 |
+
s = 2**2**2**Pow(2, 1000, evaluate=False)
|
| 427 |
+
m = Mul(s, s, evaluate=False)
|
| 428 |
+
assert m.is_integer
|
| 429 |
+
|
| 430 |
+
# broken in 1.6 and before, see #20161
|
| 431 |
+
xq = Symbol('xq', rational=True)
|
| 432 |
+
yq = Symbol('yq', rational=True)
|
| 433 |
+
assert (xq*yq).is_integer is None
|
| 434 |
+
e_20161 = Mul(-1,Mul(1,Pow(2,-1,evaluate=False),evaluate=False),evaluate=False)
|
| 435 |
+
assert e_20161.is_integer is not True # expand(e_20161) -> -1/2, but no need to see that in the assumption without evaluation
|
| 436 |
+
|
| 437 |
+
|
| 438 |
+
def test_Add_Mul_is_integer():
|
| 439 |
+
x = Symbol('x')
|
| 440 |
+
|
| 441 |
+
k = Symbol('k', integer=True)
|
| 442 |
+
n = Symbol('n', integer=True)
|
| 443 |
+
nk = Symbol('nk', integer=False)
|
| 444 |
+
nr = Symbol('nr', rational=False)
|
| 445 |
+
nz = Symbol('nz', integer=True, zero=False)
|
| 446 |
+
|
| 447 |
+
assert (-nk).is_integer is None
|
| 448 |
+
assert (-nr).is_integer is False
|
| 449 |
+
assert (2*k).is_integer is True
|
| 450 |
+
assert (-k).is_integer is True
|
| 451 |
+
|
| 452 |
+
assert (k + nk).is_integer is False
|
| 453 |
+
assert (k + n).is_integer is True
|
| 454 |
+
assert (k + x).is_integer is None
|
| 455 |
+
assert (k + n*x).is_integer is None
|
| 456 |
+
assert (k + n/3).is_integer is None
|
| 457 |
+
assert (k + nz/3).is_integer is None
|
| 458 |
+
assert (k + nr/3).is_integer is False
|
| 459 |
+
|
| 460 |
+
assert ((1 + sqrt(3))*(-sqrt(3) + 1)).is_integer is not False
|
| 461 |
+
assert (1 + (1 + sqrt(3))*(-sqrt(3) + 1)).is_integer is not False
|
| 462 |
+
|
| 463 |
+
|
| 464 |
+
def test_Add_Mul_is_finite():
|
| 465 |
+
x = Symbol('x', extended_real=True, finite=False)
|
| 466 |
+
|
| 467 |
+
assert sin(x).is_finite is True
|
| 468 |
+
assert (x*sin(x)).is_finite is None
|
| 469 |
+
assert (x*atan(x)).is_finite is False
|
| 470 |
+
assert (1024*sin(x)).is_finite is True
|
| 471 |
+
assert (sin(x)*exp(x)).is_finite is None
|
| 472 |
+
assert (sin(x)*cos(x)).is_finite is True
|
| 473 |
+
assert (x*sin(x)*exp(x)).is_finite is None
|
| 474 |
+
|
| 475 |
+
assert (sin(x) - 67).is_finite is True
|
| 476 |
+
assert (sin(x) + exp(x)).is_finite is not True
|
| 477 |
+
assert (1 + x).is_finite is False
|
| 478 |
+
assert (1 + x**2 + (1 + x)*(1 - x)).is_finite is None
|
| 479 |
+
assert (sqrt(2)*(1 + x)).is_finite is False
|
| 480 |
+
assert (sqrt(2)*(1 + x)*(1 - x)).is_finite is False
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
def test_Mul_is_even_odd():
|
| 484 |
+
x = Symbol('x', integer=True)
|
| 485 |
+
y = Symbol('y', integer=True)
|
| 486 |
+
|
| 487 |
+
k = Symbol('k', odd=True)
|
| 488 |
+
n = Symbol('n', odd=True)
|
| 489 |
+
m = Symbol('m', even=True)
|
| 490 |
+
|
| 491 |
+
assert (2*x).is_even is True
|
| 492 |
+
assert (2*x).is_odd is False
|
| 493 |
+
|
| 494 |
+
assert (3*x).is_even is None
|
| 495 |
+
assert (3*x).is_odd is None
|
| 496 |
+
|
| 497 |
+
assert (k/3).is_integer is None
|
| 498 |
+
assert (k/3).is_even is None
|
| 499 |
+
assert (k/3).is_odd is None
|
| 500 |
+
|
| 501 |
+
assert (2*n).is_even is True
|
| 502 |
+
assert (2*n).is_odd is False
|
| 503 |
+
|
| 504 |
+
assert (2*m).is_even is True
|
| 505 |
+
assert (2*m).is_odd is False
|
| 506 |
+
|
| 507 |
+
assert (-n).is_even is False
|
| 508 |
+
assert (-n).is_odd is True
|
| 509 |
+
|
| 510 |
+
assert (k*n).is_even is False
|
| 511 |
+
assert (k*n).is_odd is True
|
| 512 |
+
|
| 513 |
+
assert (k*m).is_even is True
|
| 514 |
+
assert (k*m).is_odd is False
|
| 515 |
+
|
| 516 |
+
assert (k*n*m).is_even is True
|
| 517 |
+
assert (k*n*m).is_odd is False
|
| 518 |
+
|
| 519 |
+
assert (k*m*x).is_even is True
|
| 520 |
+
assert (k*m*x).is_odd is False
|
| 521 |
+
|
| 522 |
+
# issue 6791:
|
| 523 |
+
assert (x/2).is_integer is None
|
| 524 |
+
assert (k/2).is_integer is False
|
| 525 |
+
assert (m/2).is_integer is True
|
| 526 |
+
|
| 527 |
+
assert (x*y).is_even is None
|
| 528 |
+
assert (x*x).is_even is None
|
| 529 |
+
assert (x*(x + k)).is_even is True
|
| 530 |
+
assert (x*(x + m)).is_even is None
|
| 531 |
+
|
| 532 |
+
assert (x*y).is_odd is None
|
| 533 |
+
assert (x*x).is_odd is None
|
| 534 |
+
assert (x*(x + k)).is_odd is False
|
| 535 |
+
assert (x*(x + m)).is_odd is None
|
| 536 |
+
|
| 537 |
+
# issue 8648
|
| 538 |
+
assert (m**2/2).is_even
|
| 539 |
+
assert (m**2/3).is_even is False
|
| 540 |
+
assert (2/m**2).is_odd is False
|
| 541 |
+
assert (2/m).is_odd is None
|
| 542 |
+
|
| 543 |
+
|
| 544 |
+
@XFAIL
|
| 545 |
+
def test_evenness_in_ternary_integer_product_with_odd():
|
| 546 |
+
# Tests that oddness inference is independent of term ordering.
|
| 547 |
+
# Term ordering at the point of testing depends on SymPy's symbol order, so
|
| 548 |
+
# we try to force a different order by modifying symbol names.
|
| 549 |
+
x = Symbol('x', integer=True)
|
| 550 |
+
y = Symbol('y', integer=True)
|
| 551 |
+
k = Symbol('k', odd=True)
|
| 552 |
+
assert (x*y*(y + k)).is_even is True
|
| 553 |
+
assert (y*x*(x + k)).is_even is True
|
| 554 |
+
|
| 555 |
+
|
| 556 |
+
def test_evenness_in_ternary_integer_product_with_even():
|
| 557 |
+
x = Symbol('x', integer=True)
|
| 558 |
+
y = Symbol('y', integer=True)
|
| 559 |
+
m = Symbol('m', even=True)
|
| 560 |
+
assert (x*y*(y + m)).is_even is None
|
| 561 |
+
|
| 562 |
+
|
| 563 |
+
@XFAIL
|
| 564 |
+
def test_oddness_in_ternary_integer_product_with_odd():
|
| 565 |
+
# Tests that oddness inference is independent of term ordering.
|
| 566 |
+
# Term ordering at the point of testing depends on SymPy's symbol order, so
|
| 567 |
+
# we try to force a different order by modifying symbol names.
|
| 568 |
+
x = Symbol('x', integer=True)
|
| 569 |
+
y = Symbol('y', integer=True)
|
| 570 |
+
k = Symbol('k', odd=True)
|
| 571 |
+
assert (x*y*(y + k)).is_odd is False
|
| 572 |
+
assert (y*x*(x + k)).is_odd is False
|
| 573 |
+
|
| 574 |
+
|
| 575 |
+
def test_oddness_in_ternary_integer_product_with_even():
|
| 576 |
+
x = Symbol('x', integer=True)
|
| 577 |
+
y = Symbol('y', integer=True)
|
| 578 |
+
m = Symbol('m', even=True)
|
| 579 |
+
assert (x*y*(y + m)).is_odd is None
|
| 580 |
+
|
| 581 |
+
|
| 582 |
+
def test_Mul_is_rational():
|
| 583 |
+
x = Symbol('x')
|
| 584 |
+
n = Symbol('n', integer=True)
|
| 585 |
+
m = Symbol('m', integer=True, nonzero=True)
|
| 586 |
+
|
| 587 |
+
assert (n/m).is_rational is True
|
| 588 |
+
assert (x/pi).is_rational is None
|
| 589 |
+
assert (x/n).is_rational is None
|
| 590 |
+
assert (m/pi).is_rational is False
|
| 591 |
+
|
| 592 |
+
r = Symbol('r', rational=True)
|
| 593 |
+
assert (pi*r).is_rational is None
|
| 594 |
+
|
| 595 |
+
# issue 8008
|
| 596 |
+
z = Symbol('z', zero=True)
|
| 597 |
+
i = Symbol('i', imaginary=True)
|
| 598 |
+
assert (z*i).is_rational is True
|
| 599 |
+
bi = Symbol('i', imaginary=True, finite=True)
|
| 600 |
+
assert (z*bi).is_zero is True
|
| 601 |
+
|
| 602 |
+
|
| 603 |
+
def test_Add_is_rational():
|
| 604 |
+
x = Symbol('x')
|
| 605 |
+
n = Symbol('n', rational=True)
|
| 606 |
+
m = Symbol('m', rational=True)
|
| 607 |
+
|
| 608 |
+
assert (n + m).is_rational is True
|
| 609 |
+
assert (x + pi).is_rational is None
|
| 610 |
+
assert (x + n).is_rational is None
|
| 611 |
+
assert (n + pi).is_rational is False
|
| 612 |
+
|
| 613 |
+
|
| 614 |
+
def test_Add_is_even_odd():
|
| 615 |
+
x = Symbol('x', integer=True)
|
| 616 |
+
|
| 617 |
+
k = Symbol('k', odd=True)
|
| 618 |
+
n = Symbol('n', odd=True)
|
| 619 |
+
m = Symbol('m', even=True)
|
| 620 |
+
|
| 621 |
+
assert (k + 7).is_even is True
|
| 622 |
+
assert (k + 7).is_odd is False
|
| 623 |
+
|
| 624 |
+
assert (-k + 7).is_even is True
|
| 625 |
+
assert (-k + 7).is_odd is False
|
| 626 |
+
|
| 627 |
+
assert (k - 12).is_even is False
|
| 628 |
+
assert (k - 12).is_odd is True
|
| 629 |
+
|
| 630 |
+
assert (-k - 12).is_even is False
|
| 631 |
+
assert (-k - 12).is_odd is True
|
| 632 |
+
|
| 633 |
+
assert (k + n).is_even is True
|
| 634 |
+
assert (k + n).is_odd is False
|
| 635 |
+
|
| 636 |
+
assert (k + m).is_even is False
|
| 637 |
+
assert (k + m).is_odd is True
|
| 638 |
+
|
| 639 |
+
assert (k + n + m).is_even is True
|
| 640 |
+
assert (k + n + m).is_odd is False
|
| 641 |
+
|
| 642 |
+
assert (k + n + x + m).is_even is None
|
| 643 |
+
assert (k + n + x + m).is_odd is None
|
| 644 |
+
|
| 645 |
+
|
| 646 |
+
def test_Mul_is_negative_positive():
|
| 647 |
+
x = Symbol('x', real=True)
|
| 648 |
+
y = Symbol('y', extended_real=False, complex=True)
|
| 649 |
+
z = Symbol('z', zero=True)
|
| 650 |
+
|
| 651 |
+
e = 2*z
|
| 652 |
+
assert e.is_Mul and e.is_positive is False and e.is_negative is False
|
| 653 |
+
|
| 654 |
+
neg = Symbol('neg', negative=True)
|
| 655 |
+
pos = Symbol('pos', positive=True)
|
| 656 |
+
nneg = Symbol('nneg', nonnegative=True)
|
| 657 |
+
npos = Symbol('npos', nonpositive=True)
|
| 658 |
+
|
| 659 |
+
assert neg.is_negative is True
|
| 660 |
+
assert (-neg).is_negative is False
|
| 661 |
+
assert (2*neg).is_negative is True
|
| 662 |
+
|
| 663 |
+
assert (2*pos)._eval_is_extended_negative() is False
|
| 664 |
+
assert (2*pos).is_negative is False
|
| 665 |
+
|
| 666 |
+
assert pos.is_negative is False
|
| 667 |
+
assert (-pos).is_negative is True
|
| 668 |
+
assert (2*pos).is_negative is False
|
| 669 |
+
|
| 670 |
+
assert (pos*neg).is_negative is True
|
| 671 |
+
assert (2*pos*neg).is_negative is True
|
| 672 |
+
assert (-pos*neg).is_negative is False
|
| 673 |
+
assert (pos*neg*y).is_negative is False # y.is_real=F; !real -> !neg
|
| 674 |
+
|
| 675 |
+
assert nneg.is_negative is False
|
| 676 |
+
assert (-nneg).is_negative is None
|
| 677 |
+
assert (2*nneg).is_negative is False
|
| 678 |
+
|
| 679 |
+
assert npos.is_negative is None
|
| 680 |
+
assert (-npos).is_negative is False
|
| 681 |
+
assert (2*npos).is_negative is None
|
| 682 |
+
|
| 683 |
+
assert (nneg*npos).is_negative is None
|
| 684 |
+
|
| 685 |
+
assert (neg*nneg).is_negative is None
|
| 686 |
+
assert (neg*npos).is_negative is False
|
| 687 |
+
|
| 688 |
+
assert (pos*nneg).is_negative is False
|
| 689 |
+
assert (pos*npos).is_negative is None
|
| 690 |
+
|
| 691 |
+
assert (npos*neg*nneg).is_negative is False
|
| 692 |
+
assert (npos*pos*nneg).is_negative is None
|
| 693 |
+
|
| 694 |
+
assert (-npos*neg*nneg).is_negative is None
|
| 695 |
+
assert (-npos*pos*nneg).is_negative is False
|
| 696 |
+
|
| 697 |
+
assert (17*npos*neg*nneg).is_negative is False
|
| 698 |
+
assert (17*npos*pos*nneg).is_negative is None
|
| 699 |
+
|
| 700 |
+
assert (neg*npos*pos*nneg).is_negative is False
|
| 701 |
+
|
| 702 |
+
assert (x*neg).is_negative is None
|
| 703 |
+
assert (nneg*npos*pos*x*neg).is_negative is None
|
| 704 |
+
|
| 705 |
+
assert neg.is_positive is False
|
| 706 |
+
assert (-neg).is_positive is True
|
| 707 |
+
assert (2*neg).is_positive is False
|
| 708 |
+
|
| 709 |
+
assert pos.is_positive is True
|
| 710 |
+
assert (-pos).is_positive is False
|
| 711 |
+
assert (2*pos).is_positive is True
|
| 712 |
+
|
| 713 |
+
assert (pos*neg).is_positive is False
|
| 714 |
+
assert (2*pos*neg).is_positive is False
|
| 715 |
+
assert (-pos*neg).is_positive is True
|
| 716 |
+
assert (-pos*neg*y).is_positive is False # y.is_real=F; !real -> !neg
|
| 717 |
+
|
| 718 |
+
assert nneg.is_positive is None
|
| 719 |
+
assert (-nneg).is_positive is False
|
| 720 |
+
assert (2*nneg).is_positive is None
|
| 721 |
+
|
| 722 |
+
assert npos.is_positive is False
|
| 723 |
+
assert (-npos).is_positive is None
|
| 724 |
+
assert (2*npos).is_positive is False
|
| 725 |
+
|
| 726 |
+
assert (nneg*npos).is_positive is False
|
| 727 |
+
|
| 728 |
+
assert (neg*nneg).is_positive is False
|
| 729 |
+
assert (neg*npos).is_positive is None
|
| 730 |
+
|
| 731 |
+
assert (pos*nneg).is_positive is None
|
| 732 |
+
assert (pos*npos).is_positive is False
|
| 733 |
+
|
| 734 |
+
assert (npos*neg*nneg).is_positive is None
|
| 735 |
+
assert (npos*pos*nneg).is_positive is False
|
| 736 |
+
|
| 737 |
+
assert (-npos*neg*nneg).is_positive is False
|
| 738 |
+
assert (-npos*pos*nneg).is_positive is None
|
| 739 |
+
|
| 740 |
+
assert (17*npos*neg*nneg).is_positive is None
|
| 741 |
+
assert (17*npos*pos*nneg).is_positive is False
|
| 742 |
+
|
| 743 |
+
assert (neg*npos*pos*nneg).is_positive is None
|
| 744 |
+
|
| 745 |
+
assert (x*neg).is_positive is None
|
| 746 |
+
assert (nneg*npos*pos*x*neg).is_positive is None
|
| 747 |
+
|
| 748 |
+
|
| 749 |
+
def test_Mul_is_negative_positive_2():
|
| 750 |
+
a = Symbol('a', nonnegative=True)
|
| 751 |
+
b = Symbol('b', nonnegative=True)
|
| 752 |
+
c = Symbol('c', nonpositive=True)
|
| 753 |
+
d = Symbol('d', nonpositive=True)
|
| 754 |
+
|
| 755 |
+
assert (a*b).is_nonnegative is True
|
| 756 |
+
assert (a*b).is_negative is False
|
| 757 |
+
assert (a*b).is_zero is None
|
| 758 |
+
assert (a*b).is_positive is None
|
| 759 |
+
|
| 760 |
+
assert (c*d).is_nonnegative is True
|
| 761 |
+
assert (c*d).is_negative is False
|
| 762 |
+
assert (c*d).is_zero is None
|
| 763 |
+
assert (c*d).is_positive is None
|
| 764 |
+
|
| 765 |
+
assert (a*c).is_nonpositive is True
|
| 766 |
+
assert (a*c).is_positive is False
|
| 767 |
+
assert (a*c).is_zero is None
|
| 768 |
+
assert (a*c).is_negative is None
|
| 769 |
+
|
| 770 |
+
|
| 771 |
+
def test_Mul_is_nonpositive_nonnegative():
|
| 772 |
+
x = Symbol('x', real=True)
|
| 773 |
+
|
| 774 |
+
k = Symbol('k', negative=True)
|
| 775 |
+
n = Symbol('n', positive=True)
|
| 776 |
+
u = Symbol('u', nonnegative=True)
|
| 777 |
+
v = Symbol('v', nonpositive=True)
|
| 778 |
+
|
| 779 |
+
assert k.is_nonpositive is True
|
| 780 |
+
assert (-k).is_nonpositive is False
|
| 781 |
+
assert (2*k).is_nonpositive is True
|
| 782 |
+
|
| 783 |
+
assert n.is_nonpositive is False
|
| 784 |
+
assert (-n).is_nonpositive is True
|
| 785 |
+
assert (2*n).is_nonpositive is False
|
| 786 |
+
|
| 787 |
+
assert (n*k).is_nonpositive is True
|
| 788 |
+
assert (2*n*k).is_nonpositive is True
|
| 789 |
+
assert (-n*k).is_nonpositive is False
|
| 790 |
+
|
| 791 |
+
assert u.is_nonpositive is None
|
| 792 |
+
assert (-u).is_nonpositive is True
|
| 793 |
+
assert (2*u).is_nonpositive is None
|
| 794 |
+
|
| 795 |
+
assert v.is_nonpositive is True
|
| 796 |
+
assert (-v).is_nonpositive is None
|
| 797 |
+
assert (2*v).is_nonpositive is True
|
| 798 |
+
|
| 799 |
+
assert (u*v).is_nonpositive is True
|
| 800 |
+
|
| 801 |
+
assert (k*u).is_nonpositive is True
|
| 802 |
+
assert (k*v).is_nonpositive is None
|
| 803 |
+
|
| 804 |
+
assert (n*u).is_nonpositive is None
|
| 805 |
+
assert (n*v).is_nonpositive is True
|
| 806 |
+
|
| 807 |
+
assert (v*k*u).is_nonpositive is None
|
| 808 |
+
assert (v*n*u).is_nonpositive is True
|
| 809 |
+
|
| 810 |
+
assert (-v*k*u).is_nonpositive is True
|
| 811 |
+
assert (-v*n*u).is_nonpositive is None
|
| 812 |
+
|
| 813 |
+
assert (17*v*k*u).is_nonpositive is None
|
| 814 |
+
assert (17*v*n*u).is_nonpositive is True
|
| 815 |
+
|
| 816 |
+
assert (k*v*n*u).is_nonpositive is None
|
| 817 |
+
|
| 818 |
+
assert (x*k).is_nonpositive is None
|
| 819 |
+
assert (u*v*n*x*k).is_nonpositive is None
|
| 820 |
+
|
| 821 |
+
assert k.is_nonnegative is False
|
| 822 |
+
assert (-k).is_nonnegative is True
|
| 823 |
+
assert (2*k).is_nonnegative is False
|
| 824 |
+
|
| 825 |
+
assert n.is_nonnegative is True
|
| 826 |
+
assert (-n).is_nonnegative is False
|
| 827 |
+
assert (2*n).is_nonnegative is True
|
| 828 |
+
|
| 829 |
+
assert (n*k).is_nonnegative is False
|
| 830 |
+
assert (2*n*k).is_nonnegative is False
|
| 831 |
+
assert (-n*k).is_nonnegative is True
|
| 832 |
+
|
| 833 |
+
assert u.is_nonnegative is True
|
| 834 |
+
assert (-u).is_nonnegative is None
|
| 835 |
+
assert (2*u).is_nonnegative is True
|
| 836 |
+
|
| 837 |
+
assert v.is_nonnegative is None
|
| 838 |
+
assert (-v).is_nonnegative is True
|
| 839 |
+
assert (2*v).is_nonnegative is None
|
| 840 |
+
|
| 841 |
+
assert (u*v).is_nonnegative is None
|
| 842 |
+
|
| 843 |
+
assert (k*u).is_nonnegative is None
|
| 844 |
+
assert (k*v).is_nonnegative is True
|
| 845 |
+
|
| 846 |
+
assert (n*u).is_nonnegative is True
|
| 847 |
+
assert (n*v).is_nonnegative is None
|
| 848 |
+
|
| 849 |
+
assert (v*k*u).is_nonnegative is True
|
| 850 |
+
assert (v*n*u).is_nonnegative is None
|
| 851 |
+
|
| 852 |
+
assert (-v*k*u).is_nonnegative is None
|
| 853 |
+
assert (-v*n*u).is_nonnegative is True
|
| 854 |
+
|
| 855 |
+
assert (17*v*k*u).is_nonnegative is True
|
| 856 |
+
assert (17*v*n*u).is_nonnegative is None
|
| 857 |
+
|
| 858 |
+
assert (k*v*n*u).is_nonnegative is True
|
| 859 |
+
|
| 860 |
+
assert (x*k).is_nonnegative is None
|
| 861 |
+
assert (u*v*n*x*k).is_nonnegative is None
|
| 862 |
+
|
| 863 |
+
|
| 864 |
+
def test_Add_is_negative_positive():
|
| 865 |
+
x = Symbol('x', real=True)
|
| 866 |
+
|
| 867 |
+
k = Symbol('k', negative=True)
|
| 868 |
+
n = Symbol('n', positive=True)
|
| 869 |
+
u = Symbol('u', nonnegative=True)
|
| 870 |
+
v = Symbol('v', nonpositive=True)
|
| 871 |
+
|
| 872 |
+
assert (k - 2).is_negative is True
|
| 873 |
+
assert (k + 17).is_negative is None
|
| 874 |
+
assert (-k - 5).is_negative is None
|
| 875 |
+
assert (-k + 123).is_negative is False
|
| 876 |
+
|
| 877 |
+
assert (k - n).is_negative is True
|
| 878 |
+
assert (k + n).is_negative is None
|
| 879 |
+
assert (-k - n).is_negative is None
|
| 880 |
+
assert (-k + n).is_negative is False
|
| 881 |
+
|
| 882 |
+
assert (k - n - 2).is_negative is True
|
| 883 |
+
assert (k + n + 17).is_negative is None
|
| 884 |
+
assert (-k - n - 5).is_negative is None
|
| 885 |
+
assert (-k + n + 123).is_negative is False
|
| 886 |
+
|
| 887 |
+
assert (-2*k + 123*n + 17).is_negative is False
|
| 888 |
+
|
| 889 |
+
assert (k + u).is_negative is None
|
| 890 |
+
assert (k + v).is_negative is True
|
| 891 |
+
assert (n + u).is_negative is False
|
| 892 |
+
assert (n + v).is_negative is None
|
| 893 |
+
|
| 894 |
+
assert (u - v).is_negative is False
|
| 895 |
+
assert (u + v).is_negative is None
|
| 896 |
+
assert (-u - v).is_negative is None
|
| 897 |
+
assert (-u + v).is_negative is None
|
| 898 |
+
|
| 899 |
+
assert (u - v + n + 2).is_negative is False
|
| 900 |
+
assert (u + v + n + 2).is_negative is None
|
| 901 |
+
assert (-u - v + n + 2).is_negative is None
|
| 902 |
+
assert (-u + v + n + 2).is_negative is None
|
| 903 |
+
|
| 904 |
+
assert (k + x).is_negative is None
|
| 905 |
+
assert (k + x - n).is_negative is None
|
| 906 |
+
|
| 907 |
+
assert (k - 2).is_positive is False
|
| 908 |
+
assert (k + 17).is_positive is None
|
| 909 |
+
assert (-k - 5).is_positive is None
|
| 910 |
+
assert (-k + 123).is_positive is True
|
| 911 |
+
|
| 912 |
+
assert (k - n).is_positive is False
|
| 913 |
+
assert (k + n).is_positive is None
|
| 914 |
+
assert (-k - n).is_positive is None
|
| 915 |
+
assert (-k + n).is_positive is True
|
| 916 |
+
|
| 917 |
+
assert (k - n - 2).is_positive is False
|
| 918 |
+
assert (k + n + 17).is_positive is None
|
| 919 |
+
assert (-k - n - 5).is_positive is None
|
| 920 |
+
assert (-k + n + 123).is_positive is True
|
| 921 |
+
|
| 922 |
+
assert (-2*k + 123*n + 17).is_positive is True
|
| 923 |
+
|
| 924 |
+
assert (k + u).is_positive is None
|
| 925 |
+
assert (k + v).is_positive is False
|
| 926 |
+
assert (n + u).is_positive is True
|
| 927 |
+
assert (n + v).is_positive is None
|
| 928 |
+
|
| 929 |
+
assert (u - v).is_positive is None
|
| 930 |
+
assert (u + v).is_positive is None
|
| 931 |
+
assert (-u - v).is_positive is None
|
| 932 |
+
assert (-u + v).is_positive is False
|
| 933 |
+
|
| 934 |
+
assert (u - v - n - 2).is_positive is None
|
| 935 |
+
assert (u + v - n - 2).is_positive is None
|
| 936 |
+
assert (-u - v - n - 2).is_positive is None
|
| 937 |
+
assert (-u + v - n - 2).is_positive is False
|
| 938 |
+
|
| 939 |
+
assert (n + x).is_positive is None
|
| 940 |
+
assert (n + x - k).is_positive is None
|
| 941 |
+
|
| 942 |
+
z = (-3 - sqrt(5) + (-sqrt(10)/2 - sqrt(2)/2)**2)
|
| 943 |
+
assert z.is_zero
|
| 944 |
+
z = sqrt(1 + sqrt(3)) + sqrt(3 + 3*sqrt(3)) - sqrt(10 + 6*sqrt(3))
|
| 945 |
+
assert z.is_zero
|
| 946 |
+
|
| 947 |
+
|
| 948 |
+
def test_Add_is_nonpositive_nonnegative():
|
| 949 |
+
x = Symbol('x', real=True)
|
| 950 |
+
|
| 951 |
+
k = Symbol('k', negative=True)
|
| 952 |
+
n = Symbol('n', positive=True)
|
| 953 |
+
u = Symbol('u', nonnegative=True)
|
| 954 |
+
v = Symbol('v', nonpositive=True)
|
| 955 |
+
|
| 956 |
+
assert (u - 2).is_nonpositive is None
|
| 957 |
+
assert (u + 17).is_nonpositive is False
|
| 958 |
+
assert (-u - 5).is_nonpositive is True
|
| 959 |
+
assert (-u + 123).is_nonpositive is None
|
| 960 |
+
|
| 961 |
+
assert (u - v).is_nonpositive is None
|
| 962 |
+
assert (u + v).is_nonpositive is None
|
| 963 |
+
assert (-u - v).is_nonpositive is None
|
| 964 |
+
assert (-u + v).is_nonpositive is True
|
| 965 |
+
|
| 966 |
+
assert (u - v - 2).is_nonpositive is None
|
| 967 |
+
assert (u + v + 17).is_nonpositive is None
|
| 968 |
+
assert (-u - v - 5).is_nonpositive is None
|
| 969 |
+
assert (-u + v - 123).is_nonpositive is True
|
| 970 |
+
|
| 971 |
+
assert (-2*u + 123*v - 17).is_nonpositive is True
|
| 972 |
+
|
| 973 |
+
assert (k + u).is_nonpositive is None
|
| 974 |
+
assert (k + v).is_nonpositive is True
|
| 975 |
+
assert (n + u).is_nonpositive is False
|
| 976 |
+
assert (n + v).is_nonpositive is None
|
| 977 |
+
|
| 978 |
+
assert (k - n).is_nonpositive is True
|
| 979 |
+
assert (k + n).is_nonpositive is None
|
| 980 |
+
assert (-k - n).is_nonpositive is None
|
| 981 |
+
assert (-k + n).is_nonpositive is False
|
| 982 |
+
|
| 983 |
+
assert (k - n + u + 2).is_nonpositive is None
|
| 984 |
+
assert (k + n + u + 2).is_nonpositive is None
|
| 985 |
+
assert (-k - n + u + 2).is_nonpositive is None
|
| 986 |
+
assert (-k + n + u + 2).is_nonpositive is False
|
| 987 |
+
|
| 988 |
+
assert (u + x).is_nonpositive is None
|
| 989 |
+
assert (v - x - n).is_nonpositive is None
|
| 990 |
+
|
| 991 |
+
assert (u - 2).is_nonnegative is None
|
| 992 |
+
assert (u + 17).is_nonnegative is True
|
| 993 |
+
assert (-u - 5).is_nonnegative is False
|
| 994 |
+
assert (-u + 123).is_nonnegative is None
|
| 995 |
+
|
| 996 |
+
assert (u - v).is_nonnegative is True
|
| 997 |
+
assert (u + v).is_nonnegative is None
|
| 998 |
+
assert (-u - v).is_nonnegative is None
|
| 999 |
+
assert (-u + v).is_nonnegative is None
|
| 1000 |
+
|
| 1001 |
+
assert (u - v + 2).is_nonnegative is True
|
| 1002 |
+
assert (u + v + 17).is_nonnegative is None
|
| 1003 |
+
assert (-u - v - 5).is_nonnegative is None
|
| 1004 |
+
assert (-u + v - 123).is_nonnegative is False
|
| 1005 |
+
|
| 1006 |
+
assert (2*u - 123*v + 17).is_nonnegative is True
|
| 1007 |
+
|
| 1008 |
+
assert (k + u).is_nonnegative is None
|
| 1009 |
+
assert (k + v).is_nonnegative is False
|
| 1010 |
+
assert (n + u).is_nonnegative is True
|
| 1011 |
+
assert (n + v).is_nonnegative is None
|
| 1012 |
+
|
| 1013 |
+
assert (k - n).is_nonnegative is False
|
| 1014 |
+
assert (k + n).is_nonnegative is None
|
| 1015 |
+
assert (-k - n).is_nonnegative is None
|
| 1016 |
+
assert (-k + n).is_nonnegative is True
|
| 1017 |
+
|
| 1018 |
+
assert (k - n - u - 2).is_nonnegative is False
|
| 1019 |
+
assert (k + n - u - 2).is_nonnegative is None
|
| 1020 |
+
assert (-k - n - u - 2).is_nonnegative is None
|
| 1021 |
+
assert (-k + n - u - 2).is_nonnegative is None
|
| 1022 |
+
|
| 1023 |
+
assert (u - x).is_nonnegative is None
|
| 1024 |
+
assert (v + x + n).is_nonnegative is None
|
| 1025 |
+
|
| 1026 |
+
|
| 1027 |
+
def test_Pow_is_integer():
|
| 1028 |
+
x = Symbol('x')
|
| 1029 |
+
|
| 1030 |
+
k = Symbol('k', integer=True)
|
| 1031 |
+
n = Symbol('n', integer=True, nonnegative=True)
|
| 1032 |
+
m = Symbol('m', integer=True, positive=True)
|
| 1033 |
+
|
| 1034 |
+
assert (k**2).is_integer is True
|
| 1035 |
+
assert (k**(-2)).is_integer is None
|
| 1036 |
+
assert ((m + 1)**(-2)).is_integer is False
|
| 1037 |
+
assert (m**(-1)).is_integer is None # issue 8580
|
| 1038 |
+
|
| 1039 |
+
assert (2**k).is_integer is None
|
| 1040 |
+
assert (2**(-k)).is_integer is None
|
| 1041 |
+
|
| 1042 |
+
assert (2**n).is_integer is True
|
| 1043 |
+
assert (2**(-n)).is_integer is None
|
| 1044 |
+
|
| 1045 |
+
assert (2**m).is_integer is True
|
| 1046 |
+
assert (2**(-m)).is_integer is False
|
| 1047 |
+
|
| 1048 |
+
assert (x**2).is_integer is None
|
| 1049 |
+
assert (2**x).is_integer is None
|
| 1050 |
+
|
| 1051 |
+
assert (k**n).is_integer is True
|
| 1052 |
+
assert (k**(-n)).is_integer is None
|
| 1053 |
+
|
| 1054 |
+
assert (k**x).is_integer is None
|
| 1055 |
+
assert (x**k).is_integer is None
|
| 1056 |
+
|
| 1057 |
+
assert (k**(n*m)).is_integer is True
|
| 1058 |
+
assert (k**(-n*m)).is_integer is None
|
| 1059 |
+
|
| 1060 |
+
assert sqrt(3).is_integer is False
|
| 1061 |
+
assert sqrt(.3).is_integer is False
|
| 1062 |
+
assert Pow(3, 2, evaluate=False).is_integer is True
|
| 1063 |
+
assert Pow(3, 0, evaluate=False).is_integer is True
|
| 1064 |
+
assert Pow(3, -2, evaluate=False).is_integer is False
|
| 1065 |
+
assert Pow(S.Half, 3, evaluate=False).is_integer is False
|
| 1066 |
+
# decided by re-evaluating
|
| 1067 |
+
assert Pow(3, S.Half, evaluate=False).is_integer is False
|
| 1068 |
+
assert Pow(3, S.Half, evaluate=False).is_integer is False
|
| 1069 |
+
assert Pow(4, S.Half, evaluate=False).is_integer is True
|
| 1070 |
+
assert Pow(S.Half, -2, evaluate=False).is_integer is True
|
| 1071 |
+
|
| 1072 |
+
assert ((-1)**k).is_integer
|
| 1073 |
+
|
| 1074 |
+
# issue 8641
|
| 1075 |
+
x = Symbol('x', real=True, integer=False)
|
| 1076 |
+
assert (x**2).is_integer is None
|
| 1077 |
+
|
| 1078 |
+
# issue 10458
|
| 1079 |
+
x = Symbol('x', positive=True)
|
| 1080 |
+
assert (1/(x + 1)).is_integer is False
|
| 1081 |
+
assert (1/(-x - 1)).is_integer is False
|
| 1082 |
+
assert (-1/(x + 1)).is_integer is False
|
| 1083 |
+
# issue 23287
|
| 1084 |
+
assert (x**2/2).is_integer is None
|
| 1085 |
+
|
| 1086 |
+
# issue 8648-like
|
| 1087 |
+
k = Symbol('k', even=True)
|
| 1088 |
+
assert (k**3/2).is_integer
|
| 1089 |
+
assert (k**3/8).is_integer
|
| 1090 |
+
assert (k**3/16).is_integer is None
|
| 1091 |
+
assert (2/k).is_integer is None
|
| 1092 |
+
assert (2/k**2).is_integer is False
|
| 1093 |
+
o = Symbol('o', odd=True)
|
| 1094 |
+
assert (k/o).is_integer is None
|
| 1095 |
+
o = Symbol('o', odd=True, prime=True)
|
| 1096 |
+
assert (k/o).is_integer is False
|
| 1097 |
+
|
| 1098 |
+
|
| 1099 |
+
def test_Pow_is_real():
|
| 1100 |
+
x = Symbol('x', real=True)
|
| 1101 |
+
y = Symbol('y', positive=True)
|
| 1102 |
+
|
| 1103 |
+
assert (x**2).is_real is True
|
| 1104 |
+
assert (x**3).is_real is True
|
| 1105 |
+
assert (x**x).is_real is None
|
| 1106 |
+
assert (y**x).is_real is True
|
| 1107 |
+
|
| 1108 |
+
assert (x**Rational(1, 3)).is_real is None
|
| 1109 |
+
assert (y**Rational(1, 3)).is_real is True
|
| 1110 |
+
|
| 1111 |
+
assert sqrt(-1 - sqrt(2)).is_real is False
|
| 1112 |
+
|
| 1113 |
+
i = Symbol('i', imaginary=True)
|
| 1114 |
+
assert (i**i).is_real is None
|
| 1115 |
+
assert (I**i).is_extended_real is True
|
| 1116 |
+
assert ((-I)**i).is_extended_real is True
|
| 1117 |
+
assert (2**i).is_real is None # (2**(pi/log(2) * I)) is real, 2**I is not
|
| 1118 |
+
assert (2**I).is_real is False
|
| 1119 |
+
assert (2**-I).is_real is False
|
| 1120 |
+
assert (i**2).is_extended_real is True
|
| 1121 |
+
assert (i**3).is_extended_real is False
|
| 1122 |
+
assert (i**x).is_real is None # could be (-I)**(2/3)
|
| 1123 |
+
e = Symbol('e', even=True)
|
| 1124 |
+
o = Symbol('o', odd=True)
|
| 1125 |
+
k = Symbol('k', integer=True)
|
| 1126 |
+
assert (i**e).is_extended_real is True
|
| 1127 |
+
assert (i**o).is_extended_real is False
|
| 1128 |
+
assert (i**k).is_real is None
|
| 1129 |
+
assert (i**(4*k)).is_extended_real is True
|
| 1130 |
+
|
| 1131 |
+
x = Symbol("x", nonnegative=True)
|
| 1132 |
+
y = Symbol("y", nonnegative=True)
|
| 1133 |
+
assert im(x**y).expand(complex=True) is S.Zero
|
| 1134 |
+
assert (x**y).is_real is True
|
| 1135 |
+
i = Symbol('i', imaginary=True)
|
| 1136 |
+
assert (exp(i)**I).is_extended_real is True
|
| 1137 |
+
assert log(exp(i)).is_imaginary is None # i could be 2*pi*I
|
| 1138 |
+
c = Symbol('c', complex=True)
|
| 1139 |
+
assert log(c).is_real is None # c could be 0 or 2, too
|
| 1140 |
+
assert log(exp(c)).is_real is None # log(0), log(E), ...
|
| 1141 |
+
n = Symbol('n', negative=False)
|
| 1142 |
+
assert log(n).is_real is None
|
| 1143 |
+
n = Symbol('n', nonnegative=True)
|
| 1144 |
+
assert log(n).is_real is None
|
| 1145 |
+
|
| 1146 |
+
assert sqrt(-I).is_real is False # issue 7843
|
| 1147 |
+
|
| 1148 |
+
i = Symbol('i', integer=True)
|
| 1149 |
+
assert (1/(i-1)).is_real is None
|
| 1150 |
+
assert (1/(i-1)).is_extended_real is None
|
| 1151 |
+
|
| 1152 |
+
# test issue 20715
|
| 1153 |
+
from sympy.core.parameters import evaluate
|
| 1154 |
+
x = S(-1)
|
| 1155 |
+
with evaluate(False):
|
| 1156 |
+
assert x.is_negative is True
|
| 1157 |
+
|
| 1158 |
+
f = Pow(x, -1)
|
| 1159 |
+
with evaluate(False):
|
| 1160 |
+
assert f.is_imaginary is False
|
| 1161 |
+
|
| 1162 |
+
|
| 1163 |
+
def test_real_Pow():
|
| 1164 |
+
k = Symbol('k', integer=True, nonzero=True)
|
| 1165 |
+
assert (k**(I*pi/log(k))).is_real
|
| 1166 |
+
|
| 1167 |
+
|
| 1168 |
+
def test_Pow_is_finite():
|
| 1169 |
+
xe = Symbol('xe', extended_real=True)
|
| 1170 |
+
xr = Symbol('xr', real=True)
|
| 1171 |
+
p = Symbol('p', positive=True)
|
| 1172 |
+
n = Symbol('n', negative=True)
|
| 1173 |
+
i = Symbol('i', integer=True)
|
| 1174 |
+
|
| 1175 |
+
assert (xe**2).is_finite is None # xe could be oo
|
| 1176 |
+
assert (xr**2).is_finite is True
|
| 1177 |
+
|
| 1178 |
+
assert (xe**xe).is_finite is None
|
| 1179 |
+
assert (xr**xe).is_finite is None
|
| 1180 |
+
assert (xe**xr).is_finite is None
|
| 1181 |
+
# FIXME: The line below should be True rather than None
|
| 1182 |
+
# assert (xr**xr).is_finite is True
|
| 1183 |
+
assert (xr**xr).is_finite is None
|
| 1184 |
+
|
| 1185 |
+
assert (p**xe).is_finite is None
|
| 1186 |
+
assert (p**xr).is_finite is True
|
| 1187 |
+
|
| 1188 |
+
assert (n**xe).is_finite is None
|
| 1189 |
+
assert (n**xr).is_finite is True
|
| 1190 |
+
|
| 1191 |
+
assert (sin(xe)**2).is_finite is True
|
| 1192 |
+
assert (sin(xr)**2).is_finite is True
|
| 1193 |
+
|
| 1194 |
+
assert (sin(xe)**xe).is_finite is None # xe, xr could be -pi
|
| 1195 |
+
assert (sin(xr)**xr).is_finite is None
|
| 1196 |
+
|
| 1197 |
+
# FIXME: Should the line below be True rather than None?
|
| 1198 |
+
assert (sin(xe)**exp(xe)).is_finite is None
|
| 1199 |
+
assert (sin(xr)**exp(xr)).is_finite is True
|
| 1200 |
+
|
| 1201 |
+
assert (1/sin(xe)).is_finite is None # if zero, no, otherwise yes
|
| 1202 |
+
assert (1/sin(xr)).is_finite is None
|
| 1203 |
+
|
| 1204 |
+
assert (1/exp(xe)).is_finite is None # xe could be -oo
|
| 1205 |
+
assert (1/exp(xr)).is_finite is True
|
| 1206 |
+
|
| 1207 |
+
assert (1/S.Pi).is_finite is True
|
| 1208 |
+
|
| 1209 |
+
assert (1/(i-1)).is_finite is None
|
| 1210 |
+
|
| 1211 |
+
|
| 1212 |
+
def test_Pow_is_even_odd():
|
| 1213 |
+
x = Symbol('x')
|
| 1214 |
+
|
| 1215 |
+
k = Symbol('k', even=True)
|
| 1216 |
+
n = Symbol('n', odd=True)
|
| 1217 |
+
m = Symbol('m', integer=True, nonnegative=True)
|
| 1218 |
+
p = Symbol('p', integer=True, positive=True)
|
| 1219 |
+
|
| 1220 |
+
assert ((-1)**n).is_odd
|
| 1221 |
+
assert ((-1)**k).is_odd
|
| 1222 |
+
assert ((-1)**(m - p)).is_odd
|
| 1223 |
+
|
| 1224 |
+
assert (k**2).is_even is True
|
| 1225 |
+
assert (n**2).is_even is False
|
| 1226 |
+
assert (2**k).is_even is None
|
| 1227 |
+
assert (x**2).is_even is None
|
| 1228 |
+
|
| 1229 |
+
assert (k**m).is_even is None
|
| 1230 |
+
assert (n**m).is_even is False
|
| 1231 |
+
|
| 1232 |
+
assert (k**p).is_even is True
|
| 1233 |
+
assert (n**p).is_even is False
|
| 1234 |
+
|
| 1235 |
+
assert (m**k).is_even is None
|
| 1236 |
+
assert (p**k).is_even is None
|
| 1237 |
+
|
| 1238 |
+
assert (m**n).is_even is None
|
| 1239 |
+
assert (p**n).is_even is None
|
| 1240 |
+
|
| 1241 |
+
assert (k**x).is_even is None
|
| 1242 |
+
assert (n**x).is_even is None
|
| 1243 |
+
|
| 1244 |
+
assert (k**2).is_odd is False
|
| 1245 |
+
assert (n**2).is_odd is True
|
| 1246 |
+
assert (3**k).is_odd is None
|
| 1247 |
+
|
| 1248 |
+
assert (k**m).is_odd is None
|
| 1249 |
+
assert (n**m).is_odd is True
|
| 1250 |
+
|
| 1251 |
+
assert (k**p).is_odd is False
|
| 1252 |
+
assert (n**p).is_odd is True
|
| 1253 |
+
|
| 1254 |
+
assert (m**k).is_odd is None
|
| 1255 |
+
assert (p**k).is_odd is None
|
| 1256 |
+
|
| 1257 |
+
assert (m**n).is_odd is None
|
| 1258 |
+
assert (p**n).is_odd is None
|
| 1259 |
+
|
| 1260 |
+
assert (k**x).is_odd is None
|
| 1261 |
+
assert (n**x).is_odd is None
|
| 1262 |
+
|
| 1263 |
+
|
| 1264 |
+
def test_Pow_is_negative_positive():
|
| 1265 |
+
r = Symbol('r', real=True)
|
| 1266 |
+
|
| 1267 |
+
k = Symbol('k', integer=True, positive=True)
|
| 1268 |
+
n = Symbol('n', even=True)
|
| 1269 |
+
m = Symbol('m', odd=True)
|
| 1270 |
+
|
| 1271 |
+
x = Symbol('x')
|
| 1272 |
+
|
| 1273 |
+
assert (2**r).is_positive is True
|
| 1274 |
+
assert ((-2)**r).is_positive is None
|
| 1275 |
+
assert ((-2)**n).is_positive is True
|
| 1276 |
+
assert ((-2)**m).is_positive is False
|
| 1277 |
+
|
| 1278 |
+
assert (k**2).is_positive is True
|
| 1279 |
+
assert (k**(-2)).is_positive is True
|
| 1280 |
+
|
| 1281 |
+
assert (k**r).is_positive is True
|
| 1282 |
+
assert ((-k)**r).is_positive is None
|
| 1283 |
+
assert ((-k)**n).is_positive is True
|
| 1284 |
+
assert ((-k)**m).is_positive is False
|
| 1285 |
+
|
| 1286 |
+
assert (2**r).is_negative is False
|
| 1287 |
+
assert ((-2)**r).is_negative is None
|
| 1288 |
+
assert ((-2)**n).is_negative is False
|
| 1289 |
+
assert ((-2)**m).is_negative is True
|
| 1290 |
+
|
| 1291 |
+
assert (k**2).is_negative is False
|
| 1292 |
+
assert (k**(-2)).is_negative is False
|
| 1293 |
+
|
| 1294 |
+
assert (k**r).is_negative is False
|
| 1295 |
+
assert ((-k)**r).is_negative is None
|
| 1296 |
+
assert ((-k)**n).is_negative is False
|
| 1297 |
+
assert ((-k)**m).is_negative is True
|
| 1298 |
+
|
| 1299 |
+
assert (2**x).is_positive is None
|
| 1300 |
+
assert (2**x).is_negative is None
|
| 1301 |
+
|
| 1302 |
+
|
| 1303 |
+
def test_Pow_is_zero():
|
| 1304 |
+
z = Symbol('z', zero=True)
|
| 1305 |
+
e = z**2
|
| 1306 |
+
assert e.is_zero
|
| 1307 |
+
assert e.is_positive is False
|
| 1308 |
+
assert e.is_negative is False
|
| 1309 |
+
|
| 1310 |
+
assert Pow(0, 0, evaluate=False).is_zero is False
|
| 1311 |
+
assert Pow(0, 3, evaluate=False).is_zero
|
| 1312 |
+
assert Pow(0, oo, evaluate=False).is_zero
|
| 1313 |
+
assert Pow(0, -3, evaluate=False).is_zero is False
|
| 1314 |
+
assert Pow(0, -oo, evaluate=False).is_zero is False
|
| 1315 |
+
assert Pow(2, 2, evaluate=False).is_zero is False
|
| 1316 |
+
|
| 1317 |
+
a = Symbol('a', zero=False)
|
| 1318 |
+
assert Pow(a, 3).is_zero is False # issue 7965
|
| 1319 |
+
|
| 1320 |
+
assert Pow(2, oo, evaluate=False).is_zero is False
|
| 1321 |
+
assert Pow(2, -oo, evaluate=False).is_zero
|
| 1322 |
+
assert Pow(S.Half, oo, evaluate=False).is_zero
|
| 1323 |
+
assert Pow(S.Half, -oo, evaluate=False).is_zero is False
|
| 1324 |
+
|
| 1325 |
+
# All combinations of real/complex base/exponent
|
| 1326 |
+
h = S.Half
|
| 1327 |
+
T = True
|
| 1328 |
+
F = False
|
| 1329 |
+
N = None
|
| 1330 |
+
|
| 1331 |
+
pow_iszero = [
|
| 1332 |
+
['**', 0, h, 1, 2, -h, -1,-2,-2*I,-I/2,I/2,1+I,oo,-oo,zoo],
|
| 1333 |
+
[ 0, F, T, T, T, F, F, F, F, F, F, N, T, F, N],
|
| 1334 |
+
[ h, F, F, F, F, F, F, F, F, F, F, F, T, F, N],
|
| 1335 |
+
[ 1, F, F, F, F, F, F, F, F, F, F, F, F, F, N],
|
| 1336 |
+
[ 2, F, F, F, F, F, F, F, F, F, F, F, F, T, N],
|
| 1337 |
+
[ -h, F, F, F, F, F, F, F, F, F, F, F, T, F, N],
|
| 1338 |
+
[ -1, F, F, F, F, F, F, F, F, F, F, F, F, F, N],
|
| 1339 |
+
[ -2, F, F, F, F, F, F, F, F, F, F, F, F, T, N],
|
| 1340 |
+
[-2*I, F, F, F, F, F, F, F, F, F, F, F, F, T, N],
|
| 1341 |
+
[-I/2, F, F, F, F, F, F, F, F, F, F, F, T, F, N],
|
| 1342 |
+
[ I/2, F, F, F, F, F, F, F, F, F, F, F, T, F, N],
|
| 1343 |
+
[ 1+I, F, F, F, F, F, F, F, F, F, F, F, F, T, N],
|
| 1344 |
+
[ oo, F, F, F, F, T, T, T, F, F, F, F, F, T, N],
|
| 1345 |
+
[ -oo, F, F, F, F, T, T, T, F, F, F, F, F, T, N],
|
| 1346 |
+
[ zoo, F, F, F, F, T, T, T, N, N, N, N, F, T, N]
|
| 1347 |
+
]
|
| 1348 |
+
|
| 1349 |
+
def test_table(table):
|
| 1350 |
+
n = len(table[0])
|
| 1351 |
+
for row in range(1, n):
|
| 1352 |
+
base = table[row][0]
|
| 1353 |
+
for col in range(1, n):
|
| 1354 |
+
exp = table[0][col]
|
| 1355 |
+
is_zero = table[row][col]
|
| 1356 |
+
# The actual test here:
|
| 1357 |
+
assert Pow(base, exp, evaluate=False).is_zero is is_zero
|
| 1358 |
+
|
| 1359 |
+
test_table(pow_iszero)
|
| 1360 |
+
|
| 1361 |
+
# A zero symbol...
|
| 1362 |
+
zo, zo2 = symbols('zo, zo2', zero=True)
|
| 1363 |
+
|
| 1364 |
+
# All combinations of finite symbols
|
| 1365 |
+
zf, zf2 = symbols('zf, zf2', finite=True)
|
| 1366 |
+
wf, wf2 = symbols('wf, wf2', nonzero=True)
|
| 1367 |
+
xf, xf2 = symbols('xf, xf2', real=True)
|
| 1368 |
+
yf, yf2 = symbols('yf, yf2', nonzero=True)
|
| 1369 |
+
af, af2 = symbols('af, af2', positive=True)
|
| 1370 |
+
bf, bf2 = symbols('bf, bf2', nonnegative=True)
|
| 1371 |
+
cf, cf2 = symbols('cf, cf2', negative=True)
|
| 1372 |
+
df, df2 = symbols('df, df2', nonpositive=True)
|
| 1373 |
+
|
| 1374 |
+
# Without finiteness:
|
| 1375 |
+
zi, zi2 = symbols('zi, zi2')
|
| 1376 |
+
wi, wi2 = symbols('wi, wi2', zero=False)
|
| 1377 |
+
xi, xi2 = symbols('xi, xi2', extended_real=True)
|
| 1378 |
+
yi, yi2 = symbols('yi, yi2', zero=False, extended_real=True)
|
| 1379 |
+
ai, ai2 = symbols('ai, ai2', extended_positive=True)
|
| 1380 |
+
bi, bi2 = symbols('bi, bi2', extended_nonnegative=True)
|
| 1381 |
+
ci, ci2 = symbols('ci, ci2', extended_negative=True)
|
| 1382 |
+
di, di2 = symbols('di, di2', extended_nonpositive=True)
|
| 1383 |
+
|
| 1384 |
+
pow_iszero_sym = [
|
| 1385 |
+
['**',zo,wf,yf,af,cf,zf,xf,bf,df,zi,wi,xi,yi,ai,bi,ci,di],
|
| 1386 |
+
[ zo2, F, N, N, T, F, N, N, N, F, N, N, N, N, T, N, F, F],
|
| 1387 |
+
[ wf2, F, F, F, F, F, F, F, F, F, N, N, N, N, N, N, N, N],
|
| 1388 |
+
[ yf2, F, F, F, F, F, F, F, F, F, N, N, N, N, N, N, N, N],
|
| 1389 |
+
[ af2, F, F, F, F, F, F, F, F, F, N, N, N, N, N, N, N, N],
|
| 1390 |
+
[ cf2, F, F, F, F, F, F, F, F, F, N, N, N, N, N, N, N, N],
|
| 1391 |
+
[ zf2, N, N, N, N, F, N, N, N, N, N, N, N, N, N, N, N, N],
|
| 1392 |
+
[ xf2, N, N, N, N, F, N, N, N, N, N, N, N, N, N, N, N, N],
|
| 1393 |
+
[ bf2, N, N, N, N, F, N, N, N, N, N, N, N, N, N, N, N, N],
|
| 1394 |
+
[ df2, N, N, N, N, F, N, N, N, N, N, N, N, N, N, N, N, N],
|
| 1395 |
+
[ zi2, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N],
|
| 1396 |
+
[ wi2, F, N, N, F, N, N, N, F, N, N, N, N, N, N, N, N, N],
|
| 1397 |
+
[ xi2, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N],
|
| 1398 |
+
[ yi2, F, N, N, F, N, N, N, F, N, N, N, N, N, N, N, N, N],
|
| 1399 |
+
[ ai2, F, N, N, F, N, N, N, F, N, N, N, N, N, N, N, N, N],
|
| 1400 |
+
[ bi2, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N],
|
| 1401 |
+
[ ci2, F, N, N, F, N, N, N, F, N, N, N, N, N, N, N, N, N],
|
| 1402 |
+
[ di2, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N]
|
| 1403 |
+
]
|
| 1404 |
+
|
| 1405 |
+
test_table(pow_iszero_sym)
|
| 1406 |
+
|
| 1407 |
+
# In some cases (x**x).is_zero is different from (x**y).is_zero even if y
|
| 1408 |
+
# has the same assumptions as x.
|
| 1409 |
+
assert (zo ** zo).is_zero is False
|
| 1410 |
+
assert (wf ** wf).is_zero is False
|
| 1411 |
+
assert (yf ** yf).is_zero is False
|
| 1412 |
+
assert (af ** af).is_zero is False
|
| 1413 |
+
assert (cf ** cf).is_zero is False
|
| 1414 |
+
assert (zf ** zf).is_zero is None
|
| 1415 |
+
assert (xf ** xf).is_zero is None
|
| 1416 |
+
assert (bf ** bf).is_zero is False # None in table
|
| 1417 |
+
assert (df ** df).is_zero is None
|
| 1418 |
+
assert (zi ** zi).is_zero is None
|
| 1419 |
+
assert (wi ** wi).is_zero is None
|
| 1420 |
+
assert (xi ** xi).is_zero is None
|
| 1421 |
+
assert (yi ** yi).is_zero is None
|
| 1422 |
+
assert (ai ** ai).is_zero is False # None in table
|
| 1423 |
+
assert (bi ** bi).is_zero is False # None in table
|
| 1424 |
+
assert (ci ** ci).is_zero is None
|
| 1425 |
+
assert (di ** di).is_zero is None
|
| 1426 |
+
|
| 1427 |
+
|
| 1428 |
+
def test_Pow_is_nonpositive_nonnegative():
|
| 1429 |
+
x = Symbol('x', real=True)
|
| 1430 |
+
|
| 1431 |
+
k = Symbol('k', integer=True, nonnegative=True)
|
| 1432 |
+
l = Symbol('l', integer=True, positive=True)
|
| 1433 |
+
n = Symbol('n', even=True)
|
| 1434 |
+
m = Symbol('m', odd=True)
|
| 1435 |
+
|
| 1436 |
+
assert (x**(4*k)).is_nonnegative is True
|
| 1437 |
+
assert (2**x).is_nonnegative is True
|
| 1438 |
+
assert ((-2)**x).is_nonnegative is None
|
| 1439 |
+
assert ((-2)**n).is_nonnegative is True
|
| 1440 |
+
assert ((-2)**m).is_nonnegative is False
|
| 1441 |
+
|
| 1442 |
+
assert (k**2).is_nonnegative is True
|
| 1443 |
+
assert (k**(-2)).is_nonnegative is None
|
| 1444 |
+
assert (k**k).is_nonnegative is True
|
| 1445 |
+
|
| 1446 |
+
assert (k**x).is_nonnegative is None # NOTE (0**x).is_real = U
|
| 1447 |
+
assert (l**x).is_nonnegative is True
|
| 1448 |
+
assert (l**x).is_positive is True
|
| 1449 |
+
assert ((-k)**x).is_nonnegative is None
|
| 1450 |
+
|
| 1451 |
+
assert ((-k)**m).is_nonnegative is None
|
| 1452 |
+
|
| 1453 |
+
assert (2**x).is_nonpositive is False
|
| 1454 |
+
assert ((-2)**x).is_nonpositive is None
|
| 1455 |
+
assert ((-2)**n).is_nonpositive is False
|
| 1456 |
+
assert ((-2)**m).is_nonpositive is True
|
| 1457 |
+
|
| 1458 |
+
assert (k**2).is_nonpositive is None
|
| 1459 |
+
assert (k**(-2)).is_nonpositive is None
|
| 1460 |
+
|
| 1461 |
+
assert (k**x).is_nonpositive is None
|
| 1462 |
+
assert ((-k)**x).is_nonpositive is None
|
| 1463 |
+
assert ((-k)**n).is_nonpositive is None
|
| 1464 |
+
|
| 1465 |
+
|
| 1466 |
+
assert (x**2).is_nonnegative is True
|
| 1467 |
+
i = symbols('i', imaginary=True)
|
| 1468 |
+
assert (i**2).is_nonpositive is True
|
| 1469 |
+
assert (i**4).is_nonpositive is False
|
| 1470 |
+
assert (i**3).is_nonpositive is False
|
| 1471 |
+
assert (I**i).is_nonnegative is True
|
| 1472 |
+
assert (exp(I)**i).is_nonnegative is True
|
| 1473 |
+
|
| 1474 |
+
assert ((-l)**n).is_nonnegative is True
|
| 1475 |
+
assert ((-l)**m).is_nonpositive is True
|
| 1476 |
+
assert ((-k)**n).is_nonnegative is None
|
| 1477 |
+
assert ((-k)**m).is_nonpositive is None
|
| 1478 |
+
|
| 1479 |
+
|
| 1480 |
+
def test_Mul_is_imaginary_real():
|
| 1481 |
+
r = Symbol('r', real=True)
|
| 1482 |
+
p = Symbol('p', positive=True)
|
| 1483 |
+
i1 = Symbol('i1', imaginary=True)
|
| 1484 |
+
i2 = Symbol('i2', imaginary=True)
|
| 1485 |
+
x = Symbol('x')
|
| 1486 |
+
|
| 1487 |
+
assert I.is_imaginary is True
|
| 1488 |
+
assert I.is_real is False
|
| 1489 |
+
assert (-I).is_imaginary is True
|
| 1490 |
+
assert (-I).is_real is False
|
| 1491 |
+
assert (3*I).is_imaginary is True
|
| 1492 |
+
assert (3*I).is_real is False
|
| 1493 |
+
assert (I*I).is_imaginary is False
|
| 1494 |
+
assert (I*I).is_real is True
|
| 1495 |
+
|
| 1496 |
+
e = (p + p*I)
|
| 1497 |
+
j = Symbol('j', integer=True, zero=False)
|
| 1498 |
+
assert (e**j).is_real is None
|
| 1499 |
+
assert (e**(2*j)).is_real is None
|
| 1500 |
+
assert (e**j).is_imaginary is None
|
| 1501 |
+
assert (e**(2*j)).is_imaginary is None
|
| 1502 |
+
|
| 1503 |
+
assert (e**-1).is_imaginary is False
|
| 1504 |
+
assert (e**2).is_imaginary
|
| 1505 |
+
assert (e**3).is_imaginary is False
|
| 1506 |
+
assert (e**4).is_imaginary is False
|
| 1507 |
+
assert (e**5).is_imaginary is False
|
| 1508 |
+
assert (e**-1).is_real is False
|
| 1509 |
+
assert (e**2).is_real is False
|
| 1510 |
+
assert (e**3).is_real is False
|
| 1511 |
+
assert (e**4).is_real is True
|
| 1512 |
+
assert (e**5).is_real is False
|
| 1513 |
+
assert (e**3).is_complex
|
| 1514 |
+
|
| 1515 |
+
assert (r*i1).is_imaginary is None
|
| 1516 |
+
assert (r*i1).is_real is None
|
| 1517 |
+
|
| 1518 |
+
assert (x*i1).is_imaginary is None
|
| 1519 |
+
assert (x*i1).is_real is None
|
| 1520 |
+
|
| 1521 |
+
assert (i1*i2).is_imaginary is False
|
| 1522 |
+
assert (i1*i2).is_real is True
|
| 1523 |
+
|
| 1524 |
+
assert (r*i1*i2).is_imaginary is False
|
| 1525 |
+
assert (r*i1*i2).is_real is True
|
| 1526 |
+
|
| 1527 |
+
# Github's issue 5874:
|
| 1528 |
+
nr = Symbol('nr', real=False, complex=True) # e.g. I or 1 + I
|
| 1529 |
+
a = Symbol('a', real=True, nonzero=True)
|
| 1530 |
+
b = Symbol('b', real=True)
|
| 1531 |
+
assert (i1*nr).is_real is None
|
| 1532 |
+
assert (a*nr).is_real is False
|
| 1533 |
+
assert (b*nr).is_real is None
|
| 1534 |
+
|
| 1535 |
+
ni = Symbol('ni', imaginary=False, complex=True) # e.g. 2 or 1 + I
|
| 1536 |
+
a = Symbol('a', real=True, nonzero=True)
|
| 1537 |
+
b = Symbol('b', real=True)
|
| 1538 |
+
assert (i1*ni).is_real is False
|
| 1539 |
+
assert (a*ni).is_real is None
|
| 1540 |
+
assert (b*ni).is_real is None
|
| 1541 |
+
|
| 1542 |
+
|
| 1543 |
+
def test_Mul_hermitian_antihermitian():
|
| 1544 |
+
xz, yz = symbols('xz, yz', zero=True, antihermitian=True)
|
| 1545 |
+
xf, yf = symbols('xf, yf', hermitian=False, antihermitian=False, finite=True)
|
| 1546 |
+
xh, yh = symbols('xh, yh', hermitian=True, antihermitian=False, nonzero=True)
|
| 1547 |
+
xa, ya = symbols('xa, ya', hermitian=False, antihermitian=True, zero=False, finite=True)
|
| 1548 |
+
assert (xz*xh).is_hermitian is True
|
| 1549 |
+
assert (xz*xh).is_antihermitian is True
|
| 1550 |
+
assert (xz*xa).is_hermitian is True
|
| 1551 |
+
assert (xz*xa).is_antihermitian is True
|
| 1552 |
+
assert (xf*yf).is_hermitian is None
|
| 1553 |
+
assert (xf*yf).is_antihermitian is None
|
| 1554 |
+
assert (xh*yh).is_hermitian is True
|
| 1555 |
+
assert (xh*yh).is_antihermitian is False
|
| 1556 |
+
assert (xh*ya).is_hermitian is False
|
| 1557 |
+
assert (xh*ya).is_antihermitian is True
|
| 1558 |
+
assert (xa*ya).is_hermitian is True
|
| 1559 |
+
assert (xa*ya).is_antihermitian is False
|
| 1560 |
+
|
| 1561 |
+
a = Symbol('a', hermitian=True, zero=False)
|
| 1562 |
+
b = Symbol('b', hermitian=True)
|
| 1563 |
+
c = Symbol('c', hermitian=False)
|
| 1564 |
+
d = Symbol('d', antihermitian=True)
|
| 1565 |
+
e1 = Mul(a, b, c, evaluate=False)
|
| 1566 |
+
e2 = Mul(b, a, c, evaluate=False)
|
| 1567 |
+
e3 = Mul(a, b, c, d, evaluate=False)
|
| 1568 |
+
e4 = Mul(b, a, c, d, evaluate=False)
|
| 1569 |
+
e5 = Mul(a, c, evaluate=False)
|
| 1570 |
+
e6 = Mul(a, c, d, evaluate=False)
|
| 1571 |
+
assert e1.is_hermitian is None
|
| 1572 |
+
assert e2.is_hermitian is None
|
| 1573 |
+
assert e1.is_antihermitian is None
|
| 1574 |
+
assert e2.is_antihermitian is None
|
| 1575 |
+
assert e3.is_antihermitian is None
|
| 1576 |
+
assert e4.is_antihermitian is None
|
| 1577 |
+
assert e5.is_antihermitian is None
|
| 1578 |
+
assert e6.is_antihermitian is None
|
| 1579 |
+
|
| 1580 |
+
|
| 1581 |
+
def test_Add_is_comparable():
|
| 1582 |
+
assert (x + y).is_comparable is False
|
| 1583 |
+
assert (x + 1).is_comparable is False
|
| 1584 |
+
assert (Rational(1, 3) - sqrt(8)).is_comparable is True
|
| 1585 |
+
|
| 1586 |
+
|
| 1587 |
+
def test_Mul_is_comparable():
|
| 1588 |
+
assert (x*y).is_comparable is False
|
| 1589 |
+
assert (x*2).is_comparable is False
|
| 1590 |
+
assert (sqrt(2)*Rational(1, 3)).is_comparable is True
|
| 1591 |
+
|
| 1592 |
+
|
| 1593 |
+
def test_Pow_is_comparable():
|
| 1594 |
+
assert (x**y).is_comparable is False
|
| 1595 |
+
assert (x**2).is_comparable is False
|
| 1596 |
+
assert (sqrt(Rational(1, 3))).is_comparable is True
|
| 1597 |
+
|
| 1598 |
+
|
| 1599 |
+
def test_Add_is_positive_2():
|
| 1600 |
+
e = Rational(1, 3) - sqrt(8)
|
| 1601 |
+
assert e.is_positive is False
|
| 1602 |
+
assert e.is_negative is True
|
| 1603 |
+
|
| 1604 |
+
e = pi - 1
|
| 1605 |
+
assert e.is_positive is True
|
| 1606 |
+
assert e.is_negative is False
|
| 1607 |
+
|
| 1608 |
+
|
| 1609 |
+
def test_Add_is_irrational():
|
| 1610 |
+
i = Symbol('i', irrational=True)
|
| 1611 |
+
|
| 1612 |
+
assert i.is_irrational is True
|
| 1613 |
+
assert i.is_rational is False
|
| 1614 |
+
|
| 1615 |
+
assert (i + 1).is_irrational is True
|
| 1616 |
+
assert (i + 1).is_rational is False
|
| 1617 |
+
|
| 1618 |
+
|
| 1619 |
+
def test_Mul_is_irrational():
|
| 1620 |
+
expr = Mul(1, 2, 3, evaluate=False)
|
| 1621 |
+
assert expr.is_irrational is False
|
| 1622 |
+
expr = Mul(1, I, I, evaluate=False)
|
| 1623 |
+
assert expr.is_rational is None # I * I = -1 but *no evaluation allowed*
|
| 1624 |
+
# sqrt(2) * I * I = -sqrt(2) is irrational but
|
| 1625 |
+
# this can't be determined without evaluating the
|
| 1626 |
+
# expression and the eval_is routines shouldn't do that
|
| 1627 |
+
expr = Mul(sqrt(2), I, I, evaluate=False)
|
| 1628 |
+
assert expr.is_irrational is None
|
| 1629 |
+
|
| 1630 |
+
|
| 1631 |
+
def test_issue_3531():
|
| 1632 |
+
# https://github.com/sympy/sympy/issues/3531
|
| 1633 |
+
# https://github.com/sympy/sympy/pull/18116
|
| 1634 |
+
class MightyNumeric(tuple):
|
| 1635 |
+
def __rtruediv__(self, other):
|
| 1636 |
+
return "something"
|
| 1637 |
+
|
| 1638 |
+
assert sympify(1)/MightyNumeric((1, 2)) == "something"
|
| 1639 |
+
|
| 1640 |
+
|
| 1641 |
+
def test_issue_3531b():
|
| 1642 |
+
class Foo:
|
| 1643 |
+
def __init__(self):
|
| 1644 |
+
self.field = 1.0
|
| 1645 |
+
|
| 1646 |
+
def __mul__(self, other):
|
| 1647 |
+
self.field = self.field * other
|
| 1648 |
+
|
| 1649 |
+
def __rmul__(self, other):
|
| 1650 |
+
self.field = other * self.field
|
| 1651 |
+
f = Foo()
|
| 1652 |
+
x = Symbol("x")
|
| 1653 |
+
assert f*x == x*f
|
| 1654 |
+
|
| 1655 |
+
|
| 1656 |
+
def test_bug3():
|
| 1657 |
+
a = Symbol("a")
|
| 1658 |
+
b = Symbol("b", positive=True)
|
| 1659 |
+
e = 2*a + b
|
| 1660 |
+
f = b + 2*a
|
| 1661 |
+
assert e == f
|
| 1662 |
+
|
| 1663 |
+
|
| 1664 |
+
def test_suppressed_evaluation():
|
| 1665 |
+
a = Add(0, 3, 2, evaluate=False)
|
| 1666 |
+
b = Mul(1, 3, 2, evaluate=False)
|
| 1667 |
+
c = Pow(3, 2, evaluate=False)
|
| 1668 |
+
assert a != 6
|
| 1669 |
+
assert a.func is Add
|
| 1670 |
+
assert a.args == (0, 3, 2)
|
| 1671 |
+
assert b != 6
|
| 1672 |
+
assert b.func is Mul
|
| 1673 |
+
assert b.args == (1, 3, 2)
|
| 1674 |
+
assert c != 9
|
| 1675 |
+
assert c.func is Pow
|
| 1676 |
+
assert c.args == (3, 2)
|
| 1677 |
+
|
| 1678 |
+
|
| 1679 |
+
def test_AssocOp_doit():
|
| 1680 |
+
a = Add(x,x, evaluate=False)
|
| 1681 |
+
b = Mul(y,y, evaluate=False)
|
| 1682 |
+
c = Add(b,b, evaluate=False)
|
| 1683 |
+
d = Mul(a,a, evaluate=False)
|
| 1684 |
+
assert c.doit(deep=False).func == Mul
|
| 1685 |
+
assert c.doit(deep=False).args == (2,y,y)
|
| 1686 |
+
assert c.doit().func == Mul
|
| 1687 |
+
assert c.doit().args == (2, Pow(y,2))
|
| 1688 |
+
assert d.doit(deep=False).func == Pow
|
| 1689 |
+
assert d.doit(deep=False).args == (a, 2*S.One)
|
| 1690 |
+
assert d.doit().func == Mul
|
| 1691 |
+
assert d.doit().args == (4*S.One, Pow(x,2))
|
| 1692 |
+
|
| 1693 |
+
|
| 1694 |
+
def test_Add_Mul_Expr_args():
|
| 1695 |
+
nonexpr = [Basic(), Poly(x, x), FiniteSet(x)]
|
| 1696 |
+
for typ in [Add, Mul]:
|
| 1697 |
+
for obj in nonexpr:
|
| 1698 |
+
# The cache can mess with the stacklevel check
|
| 1699 |
+
with warns(SymPyDeprecationWarning, test_stacklevel=False):
|
| 1700 |
+
typ(obj, 1)
|
| 1701 |
+
|
| 1702 |
+
|
| 1703 |
+
def test_Add_as_coeff_mul():
|
| 1704 |
+
# issue 5524. These should all be (1, self)
|
| 1705 |
+
assert (x + 1).as_coeff_mul() == (1, (x + 1,))
|
| 1706 |
+
assert (x + 2).as_coeff_mul() == (1, (x + 2,))
|
| 1707 |
+
assert (x + 3).as_coeff_mul() == (1, (x + 3,))
|
| 1708 |
+
|
| 1709 |
+
assert (x - 1).as_coeff_mul() == (1, (x - 1,))
|
| 1710 |
+
assert (x - 2).as_coeff_mul() == (1, (x - 2,))
|
| 1711 |
+
assert (x - 3).as_coeff_mul() == (1, (x - 3,))
|
| 1712 |
+
|
| 1713 |
+
n = Symbol('n', integer=True)
|
| 1714 |
+
assert (n + 1).as_coeff_mul() == (1, (n + 1,))
|
| 1715 |
+
assert (n + 2).as_coeff_mul() == (1, (n + 2,))
|
| 1716 |
+
assert (n + 3).as_coeff_mul() == (1, (n + 3,))
|
| 1717 |
+
|
| 1718 |
+
assert (n - 1).as_coeff_mul() == (1, (n - 1,))
|
| 1719 |
+
assert (n - 2).as_coeff_mul() == (1, (n - 2,))
|
| 1720 |
+
assert (n - 3).as_coeff_mul() == (1, (n - 3,))
|
| 1721 |
+
|
| 1722 |
+
|
| 1723 |
+
def test_Pow_as_coeff_mul_doesnt_expand():
|
| 1724 |
+
assert exp(x + y).as_coeff_mul() == (1, (exp(x + y),))
|
| 1725 |
+
assert exp(x + exp(x + y)) != exp(x + exp(x)*exp(y))
|
| 1726 |
+
|
| 1727 |
+
def test_issue_24751():
|
| 1728 |
+
expr = Add(-2, -3, evaluate=False)
|
| 1729 |
+
expr1 = Add(-1, expr, evaluate=False)
|
| 1730 |
+
assert int(expr1) == int((-3 - 2) - 1)
|
| 1731 |
+
|
| 1732 |
+
|
| 1733 |
+
def test_issue_3514_18626():
|
| 1734 |
+
assert sqrt(S.Half) * sqrt(6) == 2 * sqrt(3)/2
|
| 1735 |
+
assert S.Half*sqrt(6)*sqrt(2) == sqrt(3)
|
| 1736 |
+
assert sqrt(6)/2*sqrt(2) == sqrt(3)
|
| 1737 |
+
assert sqrt(6)*sqrt(2)/2 == sqrt(3)
|
| 1738 |
+
assert sqrt(8)**Rational(2, 3) == 2
|
| 1739 |
+
|
| 1740 |
+
|
| 1741 |
+
def test_make_args():
|
| 1742 |
+
assert Add.make_args(x) == (x,)
|
| 1743 |
+
assert Mul.make_args(x) == (x,)
|
| 1744 |
+
|
| 1745 |
+
assert Add.make_args(x*y*z) == (x*y*z,)
|
| 1746 |
+
assert Mul.make_args(x*y*z) == (x*y*z).args
|
| 1747 |
+
|
| 1748 |
+
assert Add.make_args(x + y + z) == (x + y + z).args
|
| 1749 |
+
assert Mul.make_args(x + y + z) == (x + y + z,)
|
| 1750 |
+
|
| 1751 |
+
assert Add.make_args((x + y)**z) == ((x + y)**z,)
|
| 1752 |
+
assert Mul.make_args((x + y)**z) == ((x + y)**z,)
|
| 1753 |
+
|
| 1754 |
+
|
| 1755 |
+
def test_issue_5126():
|
| 1756 |
+
assert (-2)**x*(-3)**x != 6**x
|
| 1757 |
+
i = Symbol('i', integer=1)
|
| 1758 |
+
assert (-2)**i*(-3)**i == 6**i
|
| 1759 |
+
|
| 1760 |
+
|
| 1761 |
+
def test_Rational_as_content_primitive():
|
| 1762 |
+
c, p = S.One, S.Zero
|
| 1763 |
+
assert (c*p).as_content_primitive() == (c, p)
|
| 1764 |
+
c, p = S.Half, S.One
|
| 1765 |
+
assert (c*p).as_content_primitive() == (c, p)
|
| 1766 |
+
|
| 1767 |
+
|
| 1768 |
+
def test_Add_as_content_primitive():
|
| 1769 |
+
assert (x + 2).as_content_primitive() == (1, x + 2)
|
| 1770 |
+
|
| 1771 |
+
assert (3*x + 2).as_content_primitive() == (1, 3*x + 2)
|
| 1772 |
+
assert (3*x + 3).as_content_primitive() == (3, x + 1)
|
| 1773 |
+
assert (3*x + 6).as_content_primitive() == (3, x + 2)
|
| 1774 |
+
|
| 1775 |
+
assert (3*x + 2*y).as_content_primitive() == (1, 3*x + 2*y)
|
| 1776 |
+
assert (3*x + 3*y).as_content_primitive() == (3, x + y)
|
| 1777 |
+
assert (3*x + 6*y).as_content_primitive() == (3, x + 2*y)
|
| 1778 |
+
|
| 1779 |
+
assert (3/x + 2*x*y*z**2).as_content_primitive() == (1, 3/x + 2*x*y*z**2)
|
| 1780 |
+
assert (3/x + 3*x*y*z**2).as_content_primitive() == (3, 1/x + x*y*z**2)
|
| 1781 |
+
assert (3/x + 6*x*y*z**2).as_content_primitive() == (3, 1/x + 2*x*y*z**2)
|
| 1782 |
+
|
| 1783 |
+
assert (2*x/3 + 4*y/9).as_content_primitive() == \
|
| 1784 |
+
(Rational(2, 9), 3*x + 2*y)
|
| 1785 |
+
assert (2*x/3 + 2.5*y).as_content_primitive() == \
|
| 1786 |
+
(Rational(1, 3), 2*x + 7.5*y)
|
| 1787 |
+
|
| 1788 |
+
# the coefficient may sort to a position other than 0
|
| 1789 |
+
p = 3 + x + y
|
| 1790 |
+
assert (2*p).expand().as_content_primitive() == (2, p)
|
| 1791 |
+
assert (2.0*p).expand().as_content_primitive() == (1, 2.*p)
|
| 1792 |
+
p *= -1
|
| 1793 |
+
assert (2*p).expand().as_content_primitive() == (2, p)
|
| 1794 |
+
|
| 1795 |
+
|
| 1796 |
+
def test_Mul_as_content_primitive():
|
| 1797 |
+
assert (2*x).as_content_primitive() == (2, x)
|
| 1798 |
+
assert (x*(2 + 2*x)).as_content_primitive() == (2, x*(1 + x))
|
| 1799 |
+
assert (x*(2 + 2*y)*(3*x + 3)**2).as_content_primitive() == \
|
| 1800 |
+
(18, x*(1 + y)*(x + 1)**2)
|
| 1801 |
+
assert ((2 + 2*x)**2*(3 + 6*x) + S.Half).as_content_primitive() == \
|
| 1802 |
+
(S.Half, 24*(x + 1)**2*(2*x + 1) + 1)
|
| 1803 |
+
|
| 1804 |
+
|
| 1805 |
+
def test_Pow_as_content_primitive():
|
| 1806 |
+
assert (x**y).as_content_primitive() == (1, x**y)
|
| 1807 |
+
assert ((2*x + 2)**y).as_content_primitive() == \
|
| 1808 |
+
(1, (Mul(2, (x + 1), evaluate=False))**y)
|
| 1809 |
+
assert ((2*x + 2)**3).as_content_primitive() == (8, (x + 1)**3)
|
| 1810 |
+
|
| 1811 |
+
|
| 1812 |
+
def test_issue_5460():
|
| 1813 |
+
u = Mul(2, (1 + x), evaluate=False)
|
| 1814 |
+
assert (2 + u).args == (2, u)
|
| 1815 |
+
|
| 1816 |
+
|
| 1817 |
+
def test_product_irrational():
|
| 1818 |
+
assert (I*pi).is_irrational is False
|
| 1819 |
+
# The following used to be deduced from the above bug:
|
| 1820 |
+
assert (I*pi).is_positive is False
|
| 1821 |
+
|
| 1822 |
+
|
| 1823 |
+
def test_issue_5919():
|
| 1824 |
+
assert (x/(y*(1 + y))).expand() == x/(y**2 + y)
|
| 1825 |
+
|
| 1826 |
+
|
| 1827 |
+
def test_Mod():
|
| 1828 |
+
assert Mod(x, 1).func is Mod
|
| 1829 |
+
assert pi % pi is S.Zero
|
| 1830 |
+
assert Mod(5, 3) == 2
|
| 1831 |
+
assert Mod(-5, 3) == 1
|
| 1832 |
+
assert Mod(5, -3) == -1
|
| 1833 |
+
assert Mod(-5, -3) == -2
|
| 1834 |
+
assert type(Mod(3.2, 2, evaluate=False)) == Mod
|
| 1835 |
+
assert 5 % x == Mod(5, x)
|
| 1836 |
+
assert x % 5 == Mod(x, 5)
|
| 1837 |
+
assert x % y == Mod(x, y)
|
| 1838 |
+
assert (x % y).subs({x: 5, y: 3}) == 2
|
| 1839 |
+
assert Mod(nan, 1) is nan
|
| 1840 |
+
assert Mod(1, nan) is nan
|
| 1841 |
+
assert Mod(nan, nan) is nan
|
| 1842 |
+
|
| 1843 |
+
assert Mod(0, x) == 0
|
| 1844 |
+
with raises(ZeroDivisionError):
|
| 1845 |
+
Mod(x, 0)
|
| 1846 |
+
|
| 1847 |
+
k = Symbol('k', integer=True)
|
| 1848 |
+
m = Symbol('m', integer=True, positive=True)
|
| 1849 |
+
assert (x**m % x).func is Mod
|
| 1850 |
+
assert (k**(-m) % k).func is Mod
|
| 1851 |
+
assert k**m % k == 0
|
| 1852 |
+
assert (-2*k)**m % k == 0
|
| 1853 |
+
|
| 1854 |
+
# Float handling
|
| 1855 |
+
point3 = Float(3.3) % 1
|
| 1856 |
+
assert (x - 3.3) % 1 == Mod(1.*x + 1 - point3, 1)
|
| 1857 |
+
assert Mod(-3.3, 1) == 1 - point3
|
| 1858 |
+
assert Mod(0.7, 1) == Float(0.7)
|
| 1859 |
+
e = Mod(1.3, 1)
|
| 1860 |
+
assert comp(e, .3) and e.is_Float
|
| 1861 |
+
e = Mod(1.3, .7)
|
| 1862 |
+
assert comp(e, .6) and e.is_Float
|
| 1863 |
+
e = Mod(1.3, Rational(7, 10))
|
| 1864 |
+
assert comp(e, .6) and e.is_Float
|
| 1865 |
+
e = Mod(Rational(13, 10), 0.7)
|
| 1866 |
+
assert comp(e, .6) and e.is_Float
|
| 1867 |
+
e = Mod(Rational(13, 10), Rational(7, 10))
|
| 1868 |
+
assert comp(e, .6) and e.is_Rational
|
| 1869 |
+
|
| 1870 |
+
# check that sign is right
|
| 1871 |
+
r2 = sqrt(2)
|
| 1872 |
+
r3 = sqrt(3)
|
| 1873 |
+
for i in [-r3, -r2, r2, r3]:
|
| 1874 |
+
for j in [-r3, -r2, r2, r3]:
|
| 1875 |
+
assert verify_numerically(i % j, i.n() % j.n())
|
| 1876 |
+
for _x in range(4):
|
| 1877 |
+
for _y in range(9):
|
| 1878 |
+
reps = [(x, _x), (y, _y)]
|
| 1879 |
+
assert Mod(3*x + y, 9).subs(reps) == (3*_x + _y) % 9
|
| 1880 |
+
|
| 1881 |
+
# denesting
|
| 1882 |
+
t = Symbol('t', real=True)
|
| 1883 |
+
assert Mod(Mod(x, t), t) == Mod(x, t)
|
| 1884 |
+
assert Mod(-Mod(x, t), t) == Mod(-x, t)
|
| 1885 |
+
assert Mod(Mod(x, 2*t), t) == Mod(x, t)
|
| 1886 |
+
assert Mod(-Mod(x, 2*t), t) == Mod(-x, t)
|
| 1887 |
+
assert Mod(Mod(x, t), 2*t) == Mod(x, t)
|
| 1888 |
+
assert Mod(-Mod(x, t), -2*t) == -Mod(x, t)
|
| 1889 |
+
for i in [-4, -2, 2, 4]:
|
| 1890 |
+
for j in [-4, -2, 2, 4]:
|
| 1891 |
+
for k in range(4):
|
| 1892 |
+
assert Mod(Mod(x, i), j).subs({x: k}) == (k % i) % j
|
| 1893 |
+
assert Mod(-Mod(x, i), j).subs({x: k}) == -(k % i) % j
|
| 1894 |
+
|
| 1895 |
+
# known difference
|
| 1896 |
+
assert Mod(5*sqrt(2), sqrt(5)) == 5*sqrt(2) - 3*sqrt(5)
|
| 1897 |
+
p = symbols('p', positive=True)
|
| 1898 |
+
assert Mod(2, p + 3) == 2
|
| 1899 |
+
assert Mod(-2, p + 3) == p + 1
|
| 1900 |
+
assert Mod(2, -p - 3) == -p - 1
|
| 1901 |
+
assert Mod(-2, -p - 3) == -2
|
| 1902 |
+
assert Mod(p + 5, p + 3) == 2
|
| 1903 |
+
assert Mod(-p - 5, p + 3) == p + 1
|
| 1904 |
+
assert Mod(p + 5, -p - 3) == -p - 1
|
| 1905 |
+
assert Mod(-p - 5, -p - 3) == -2
|
| 1906 |
+
assert Mod(p + 1, p - 1).func is Mod
|
| 1907 |
+
|
| 1908 |
+
# handling sums
|
| 1909 |
+
assert (x + 3) % 1 == Mod(x, 1)
|
| 1910 |
+
assert (x + 3.0) % 1 == Mod(1.*x, 1)
|
| 1911 |
+
assert (x - S(33)/10) % 1 == Mod(x + S(7)/10, 1)
|
| 1912 |
+
|
| 1913 |
+
a = Mod(.6*x + y, .3*y)
|
| 1914 |
+
b = Mod(0.1*y + 0.6*x, 0.3*y)
|
| 1915 |
+
# Test that a, b are equal, with 1e-14 accuracy in coefficients
|
| 1916 |
+
eps = 1e-14
|
| 1917 |
+
assert abs((a.args[0] - b.args[0]).subs({x: 1, y: 1})) < eps
|
| 1918 |
+
assert abs((a.args[1] - b.args[1]).subs({x: 1, y: 1})) < eps
|
| 1919 |
+
|
| 1920 |
+
assert (x + 1) % x == 1 % x
|
| 1921 |
+
assert (x + y) % x == y % x
|
| 1922 |
+
assert (x + y + 2) % x == (y + 2) % x
|
| 1923 |
+
assert (a + 3*x + 1) % (2*x) == Mod(a + x + 1, 2*x)
|
| 1924 |
+
assert (12*x + 18*y) % (3*x) == 3*Mod(6*y, x)
|
| 1925 |
+
|
| 1926 |
+
# gcd extraction
|
| 1927 |
+
assert (-3*x) % (-2*y) == -Mod(3*x, 2*y)
|
| 1928 |
+
assert (.6*pi) % (.3*x*pi) == 0.3*pi*Mod(2, x)
|
| 1929 |
+
assert (.6*pi) % (.31*x*pi) == pi*Mod(0.6, 0.31*x)
|
| 1930 |
+
assert (6*pi) % (.3*x*pi) == 0.3*pi*Mod(20, x)
|
| 1931 |
+
assert (6*pi) % (.31*x*pi) == pi*Mod(6, 0.31*x)
|
| 1932 |
+
assert (6*pi) % (.42*x*pi) == pi*Mod(6, 0.42*x)
|
| 1933 |
+
assert (12*x) % (2*y) == 2*Mod(6*x, y)
|
| 1934 |
+
assert (12*x) % (3*5*y) == 3*Mod(4*x, 5*y)
|
| 1935 |
+
assert (12*x) % (15*x*y) == 3*x*Mod(4, 5*y)
|
| 1936 |
+
assert (-2*pi) % (3*pi) == pi
|
| 1937 |
+
assert (2*x + 2) % (x + 1) == 0
|
| 1938 |
+
assert (x*(x + 1)) % (x + 1) == (x + 1)*Mod(x, 1)
|
| 1939 |
+
assert Mod(5.0*x, 0.1*y) == 0.1*Mod(50*x, y)
|
| 1940 |
+
i = Symbol('i', integer=True)
|
| 1941 |
+
assert (3*i*x) % (2*i*y) == i*Mod(3*x, 2*y)
|
| 1942 |
+
assert Mod(4*i, 4) == 0
|
| 1943 |
+
|
| 1944 |
+
# issue 8677
|
| 1945 |
+
n = Symbol('n', integer=True, positive=True)
|
| 1946 |
+
assert factorial(n) % n == 0
|
| 1947 |
+
assert factorial(n + 2) % n == 0
|
| 1948 |
+
assert (factorial(n + 4) % (n + 5)).func is Mod
|
| 1949 |
+
|
| 1950 |
+
# Wilson's theorem
|
| 1951 |
+
assert factorial(18042, evaluate=False) % 18043 == 18042
|
| 1952 |
+
p = Symbol('n', prime=True)
|
| 1953 |
+
assert factorial(p - 1) % p == p - 1
|
| 1954 |
+
assert factorial(p - 1) % -p == -1
|
| 1955 |
+
assert (factorial(3, evaluate=False) % 4).doit() == 2
|
| 1956 |
+
n = Symbol('n', composite=True, odd=True)
|
| 1957 |
+
assert factorial(n - 1) % n == 0
|
| 1958 |
+
|
| 1959 |
+
# symbolic with known parity
|
| 1960 |
+
n = Symbol('n', even=True)
|
| 1961 |
+
assert Mod(n, 2) == 0
|
| 1962 |
+
n = Symbol('n', odd=True)
|
| 1963 |
+
assert Mod(n, 2) == 1
|
| 1964 |
+
|
| 1965 |
+
# issue 10963
|
| 1966 |
+
assert (x**6000%400).args[1] == 400
|
| 1967 |
+
|
| 1968 |
+
#issue 13543
|
| 1969 |
+
assert Mod(Mod(x + 1, 2) + 1, 2) == Mod(x, 2)
|
| 1970 |
+
|
| 1971 |
+
x1 = Symbol('x1', integer=True)
|
| 1972 |
+
assert Mod(Mod(x1 + 2, 4)*(x1 + 4), 4) == Mod(x1*(x1 + 2), 4)
|
| 1973 |
+
assert Mod(Mod(x1 + 2, 4)*4, 4) == 0
|
| 1974 |
+
|
| 1975 |
+
# issue 15493
|
| 1976 |
+
i, j = symbols('i j', integer=True, positive=True)
|
| 1977 |
+
assert Mod(3*i, 2) == Mod(i, 2)
|
| 1978 |
+
assert Mod(8*i/j, 4) == 4*Mod(2*i/j, 1)
|
| 1979 |
+
assert Mod(8*i, 4) == 0
|
| 1980 |
+
|
| 1981 |
+
# rewrite
|
| 1982 |
+
assert Mod(x, y).rewrite(floor) == x - y*floor(x/y)
|
| 1983 |
+
assert ((x - Mod(x, y))/y).rewrite(floor) == floor(x/y)
|
| 1984 |
+
|
| 1985 |
+
# issue 21373
|
| 1986 |
+
from sympy.functions.elementary.hyperbolic import sinh
|
| 1987 |
+
from sympy.functions.elementary.piecewise import Piecewise
|
| 1988 |
+
|
| 1989 |
+
x_r, y_r = symbols('x_r y_r', real=True)
|
| 1990 |
+
assert (Piecewise((x_r, y_r > x_r), (y_r, True)) / z) % 1
|
| 1991 |
+
expr = exp(sinh(Piecewise((x_r, y_r > x_r), (y_r, True)) / z))
|
| 1992 |
+
expr.subs({1: 1.0})
|
| 1993 |
+
sinh(Piecewise((x_r, y_r > x_r), (y_r, True)) * z ** -1.0).is_zero
|
| 1994 |
+
|
| 1995 |
+
# issue 24215
|
| 1996 |
+
from sympy.abc import phi
|
| 1997 |
+
assert Mod(4.0*Mod(phi, 1) , 2) == 2.0*(Mod(2*(Mod(phi, 1)), 1))
|
| 1998 |
+
|
| 1999 |
+
xi = symbols('x', integer=True)
|
| 2000 |
+
assert unchanged(Mod, xi, 2)
|
| 2001 |
+
assert Mod(3*xi, 2) == Mod(xi, 2)
|
| 2002 |
+
assert unchanged(Mod, 3*x, 2)
|
| 2003 |
+
|
| 2004 |
+
|
| 2005 |
+
def test_Mod_Pow():
|
| 2006 |
+
# modular exponentiation
|
| 2007 |
+
assert isinstance(Mod(Pow(2, 2, evaluate=False), 3), Integer)
|
| 2008 |
+
|
| 2009 |
+
assert Mod(Pow(4, 13, evaluate=False), 497) == Mod(Pow(4, 13), 497)
|
| 2010 |
+
assert Mod(Pow(2, 10000000000, evaluate=False), 3) == 1
|
| 2011 |
+
assert Mod(Pow(32131231232, 9**10**6, evaluate=False),10**12) == \
|
| 2012 |
+
pow(32131231232,9**10**6,10**12)
|
| 2013 |
+
assert Mod(Pow(33284959323, 123**999, evaluate=False),11**13) == \
|
| 2014 |
+
pow(33284959323,123**999,11**13)
|
| 2015 |
+
assert Mod(Pow(78789849597, 333**555, evaluate=False),12**9) == \
|
| 2016 |
+
pow(78789849597,333**555,12**9)
|
| 2017 |
+
|
| 2018 |
+
# modular nested exponentiation
|
| 2019 |
+
expr = Pow(2, 2, evaluate=False)
|
| 2020 |
+
expr = Pow(2, expr, evaluate=False)
|
| 2021 |
+
assert Mod(expr, 3**10) == 16
|
| 2022 |
+
expr = Pow(2, expr, evaluate=False)
|
| 2023 |
+
assert Mod(expr, 3**10) == 6487
|
| 2024 |
+
expr = Pow(2, expr, evaluate=False)
|
| 2025 |
+
assert Mod(expr, 3**10) == 32191
|
| 2026 |
+
expr = Pow(2, expr, evaluate=False)
|
| 2027 |
+
assert Mod(expr, 3**10) == 18016
|
| 2028 |
+
expr = Pow(2, expr, evaluate=False)
|
| 2029 |
+
assert Mod(expr, 3**10) == 5137
|
| 2030 |
+
|
| 2031 |
+
expr = Pow(2, 2, evaluate=False)
|
| 2032 |
+
expr = Pow(expr, 2, evaluate=False)
|
| 2033 |
+
assert Mod(expr, 3**10) == 16
|
| 2034 |
+
expr = Pow(expr, 2, evaluate=False)
|
| 2035 |
+
assert Mod(expr, 3**10) == 256
|
| 2036 |
+
expr = Pow(expr, 2, evaluate=False)
|
| 2037 |
+
assert Mod(expr, 3**10) == 6487
|
| 2038 |
+
expr = Pow(expr, 2, evaluate=False)
|
| 2039 |
+
assert Mod(expr, 3**10) == 38281
|
| 2040 |
+
expr = Pow(expr, 2, evaluate=False)
|
| 2041 |
+
assert Mod(expr, 3**10) == 15928
|
| 2042 |
+
|
| 2043 |
+
expr = Pow(2, 2, evaluate=False)
|
| 2044 |
+
expr = Pow(expr, expr, evaluate=False)
|
| 2045 |
+
assert Mod(expr, 3**10) == 256
|
| 2046 |
+
expr = Pow(expr, expr, evaluate=False)
|
| 2047 |
+
assert Mod(expr, 3**10) == 9229
|
| 2048 |
+
expr = Pow(expr, expr, evaluate=False)
|
| 2049 |
+
assert Mod(expr, 3**10) == 25708
|
| 2050 |
+
expr = Pow(expr, expr, evaluate=False)
|
| 2051 |
+
assert Mod(expr, 3**10) == 26608
|
| 2052 |
+
expr = Pow(expr, expr, evaluate=False)
|
| 2053 |
+
# XXX This used to fail in a nondeterministic way because of overflow
|
| 2054 |
+
# error.
|
| 2055 |
+
assert Mod(expr, 3**10) == 1966
|
| 2056 |
+
|
| 2057 |
+
|
| 2058 |
+
def test_Mod_is_integer():
|
| 2059 |
+
p = Symbol('p', integer=True)
|
| 2060 |
+
q1 = Symbol('q1', integer=True)
|
| 2061 |
+
q2 = Symbol('q2', integer=True, nonzero=True)
|
| 2062 |
+
assert Mod(x, y).is_integer is None
|
| 2063 |
+
assert Mod(p, q1).is_integer is None
|
| 2064 |
+
assert Mod(x, q2).is_integer is None
|
| 2065 |
+
assert Mod(p, q2).is_integer
|
| 2066 |
+
|
| 2067 |
+
|
| 2068 |
+
def test_Mod_is_nonposneg():
|
| 2069 |
+
n = Symbol('n', integer=True)
|
| 2070 |
+
k = Symbol('k', integer=True, positive=True)
|
| 2071 |
+
assert (n%3).is_nonnegative
|
| 2072 |
+
assert Mod(n, -3).is_nonpositive
|
| 2073 |
+
assert Mod(n, k).is_nonnegative
|
| 2074 |
+
assert Mod(n, -k).is_nonpositive
|
| 2075 |
+
assert Mod(k, n).is_nonnegative is None
|
| 2076 |
+
|
| 2077 |
+
|
| 2078 |
+
def test_issue_6001():
|
| 2079 |
+
A = Symbol("A", commutative=False)
|
| 2080 |
+
eq = A + A**2
|
| 2081 |
+
# it doesn't matter whether it's True or False; they should
|
| 2082 |
+
# just all be the same
|
| 2083 |
+
assert (
|
| 2084 |
+
eq.is_commutative ==
|
| 2085 |
+
(eq + 1).is_commutative ==
|
| 2086 |
+
(A + 1).is_commutative)
|
| 2087 |
+
|
| 2088 |
+
B = Symbol("B", commutative=False)
|
| 2089 |
+
# Although commutative terms could cancel we return True
|
| 2090 |
+
# meaning "there are non-commutative symbols; aftersubstitution
|
| 2091 |
+
# that definition can change, e.g. (A*B).subs(B,A**-1) -> 1
|
| 2092 |
+
assert (sqrt(2)*A).is_commutative is False
|
| 2093 |
+
assert (sqrt(2)*A*B).is_commutative is False
|
| 2094 |
+
|
| 2095 |
+
|
| 2096 |
+
def test_polar():
|
| 2097 |
+
from sympy.functions.elementary.complexes import polar_lift
|
| 2098 |
+
p = Symbol('p', polar=True)
|
| 2099 |
+
x = Symbol('x')
|
| 2100 |
+
assert p.is_polar
|
| 2101 |
+
assert x.is_polar is None
|
| 2102 |
+
assert S.One.is_polar is None
|
| 2103 |
+
assert (p**x).is_polar is True
|
| 2104 |
+
assert (x**p).is_polar is None
|
| 2105 |
+
assert ((2*p)**x).is_polar is True
|
| 2106 |
+
assert (2*p).is_polar is True
|
| 2107 |
+
assert (-2*p).is_polar is not True
|
| 2108 |
+
assert (polar_lift(-2)*p).is_polar is True
|
| 2109 |
+
|
| 2110 |
+
q = Symbol('q', polar=True)
|
| 2111 |
+
assert (p*q)**2 == p**2 * q**2
|
| 2112 |
+
assert (2*q)**2 == 4 * q**2
|
| 2113 |
+
assert ((p*q)**x).expand() == p**x * q**x
|
| 2114 |
+
|
| 2115 |
+
|
| 2116 |
+
def test_issue_6040():
|
| 2117 |
+
a, b = Pow(1, 2, evaluate=False), S.One
|
| 2118 |
+
assert a != b
|
| 2119 |
+
assert b != a
|
| 2120 |
+
assert not (a == b)
|
| 2121 |
+
assert not (b == a)
|
| 2122 |
+
|
| 2123 |
+
|
| 2124 |
+
def test_issue_6082():
|
| 2125 |
+
# Comparison is symmetric
|
| 2126 |
+
assert Basic.compare(Max(x, 1), Max(x, 2)) == \
|
| 2127 |
+
- Basic.compare(Max(x, 2), Max(x, 1))
|
| 2128 |
+
# Equal expressions compare equal
|
| 2129 |
+
assert Basic.compare(Max(x, 1), Max(x, 1)) == 0
|
| 2130 |
+
# Basic subtypes (such as Max) compare different than standard types
|
| 2131 |
+
assert Basic.compare(Max(1, x), frozenset((1, x))) != 0
|
| 2132 |
+
|
| 2133 |
+
|
| 2134 |
+
def test_issue_6077():
|
| 2135 |
+
assert x**2.0/x == x**1.0
|
| 2136 |
+
assert x/x**2.0 == x**-1.0
|
| 2137 |
+
assert x*x**2.0 == x**3.0
|
| 2138 |
+
assert x**1.5*x**2.5 == x**4.0
|
| 2139 |
+
|
| 2140 |
+
assert 2**(2.0*x)/2**x == 2**(1.0*x)
|
| 2141 |
+
assert 2**x/2**(2.0*x) == 2**(-1.0*x)
|
| 2142 |
+
assert 2**x*2**(2.0*x) == 2**(3.0*x)
|
| 2143 |
+
assert 2**(1.5*x)*2**(2.5*x) == 2**(4.0*x)
|
| 2144 |
+
|
| 2145 |
+
|
| 2146 |
+
def test_mul_flatten_oo():
|
| 2147 |
+
p = symbols('p', positive=True)
|
| 2148 |
+
n, m = symbols('n,m', negative=True)
|
| 2149 |
+
x_im = symbols('x_im', imaginary=True)
|
| 2150 |
+
assert n*oo is -oo
|
| 2151 |
+
assert n*m*oo is oo
|
| 2152 |
+
assert p*oo is oo
|
| 2153 |
+
assert x_im*oo != I*oo # i could be +/- 3*I -> +/-oo
|
| 2154 |
+
|
| 2155 |
+
|
| 2156 |
+
def test_add_flatten():
|
| 2157 |
+
# see https://github.com/sympy/sympy/issues/2633#issuecomment-29545524
|
| 2158 |
+
a = oo + I*oo
|
| 2159 |
+
b = oo - I*oo
|
| 2160 |
+
assert a + b is nan
|
| 2161 |
+
assert a - b is nan
|
| 2162 |
+
# FIXME: This evaluates as:
|
| 2163 |
+
# >>> 1/a
|
| 2164 |
+
# 0*(oo + oo*I)
|
| 2165 |
+
# which should not simplify to 0. Should be fixed in Pow.eval
|
| 2166 |
+
#assert (1/a).simplify() == (1/b).simplify() == 0
|
| 2167 |
+
|
| 2168 |
+
a = Pow(2, 3, evaluate=False)
|
| 2169 |
+
assert a + a == 16
|
| 2170 |
+
|
| 2171 |
+
|
| 2172 |
+
def test_issue_5160_6087_6089_6090():
|
| 2173 |
+
# issue 6087
|
| 2174 |
+
assert ((-2*x*y**y)**3.2).n(2) == (2**3.2*(-x*y**y)**3.2).n(2)
|
| 2175 |
+
# issue 6089
|
| 2176 |
+
A, B, C = symbols('A,B,C', commutative=False)
|
| 2177 |
+
assert (2.*B*C)**3 == 8.0*(B*C)**3
|
| 2178 |
+
assert (-2.*B*C)**3 == -8.0*(B*C)**3
|
| 2179 |
+
assert (-2*B*C)**2 == 4*(B*C)**2
|
| 2180 |
+
# issue 5160
|
| 2181 |
+
assert sqrt(-1.0*x) == 1.0*sqrt(-x)
|
| 2182 |
+
assert sqrt(1.0*x) == 1.0*sqrt(x)
|
| 2183 |
+
# issue 6090
|
| 2184 |
+
assert (-2*x*y*A*B)**2 == 4*x**2*y**2*(A*B)**2
|
| 2185 |
+
|
| 2186 |
+
|
| 2187 |
+
def test_float_int_round():
|
| 2188 |
+
assert int(float(sqrt(10))) == int(sqrt(10))
|
| 2189 |
+
assert int(pi**1000) % 10 == 2
|
| 2190 |
+
assert int(Float('1.123456789012345678901234567890e20', '')) == \
|
| 2191 |
+
int(112345678901234567890)
|
| 2192 |
+
assert int(Float('1.123456789012345678901234567890e25', '')) == \
|
| 2193 |
+
int(11234567890123456789012345)
|
| 2194 |
+
# decimal forces float so it's not an exact integer ending in 000000
|
| 2195 |
+
assert int(Float('1.123456789012345678901234567890e35', '')) == \
|
| 2196 |
+
112345678901234567890123456789000192
|
| 2197 |
+
assert int(Float('123456789012345678901234567890e5', '')) == \
|
| 2198 |
+
12345678901234567890123456789000000
|
| 2199 |
+
assert Integer(Float('1.123456789012345678901234567890e20', '')) == \
|
| 2200 |
+
112345678901234567890
|
| 2201 |
+
assert Integer(Float('1.123456789012345678901234567890e25', '')) == \
|
| 2202 |
+
11234567890123456789012345
|
| 2203 |
+
# decimal forces float so it's not an exact integer ending in 000000
|
| 2204 |
+
assert Integer(Float('1.123456789012345678901234567890e35', '')) == \
|
| 2205 |
+
112345678901234567890123456789000192
|
| 2206 |
+
assert Integer(Float('123456789012345678901234567890e5', '')) == \
|
| 2207 |
+
12345678901234567890123456789000000
|
| 2208 |
+
assert same_and_same_prec(Float('123000e-2',''), Float('1230.00', ''))
|
| 2209 |
+
assert same_and_same_prec(Float('123000e2',''), Float('12300000', ''))
|
| 2210 |
+
|
| 2211 |
+
assert int(1 + Rational('.9999999999999999999999999')) == 1
|
| 2212 |
+
assert int(pi/1e20) == 0
|
| 2213 |
+
assert int(1 + pi/1e20) == 1
|
| 2214 |
+
assert int(Add(1.2, -2, evaluate=False)) == int(1.2 - 2)
|
| 2215 |
+
assert int(Add(1.2, +2, evaluate=False)) == int(1.2 + 2)
|
| 2216 |
+
assert int(Add(1 + Float('.99999999999999999', ''), evaluate=False)) == 1
|
| 2217 |
+
raises(TypeError, lambda: float(x))
|
| 2218 |
+
raises(TypeError, lambda: float(sqrt(-1)))
|
| 2219 |
+
|
| 2220 |
+
assert int(12345678901234567890 + cos(1)**2 + sin(1)**2) == \
|
| 2221 |
+
12345678901234567891
|
| 2222 |
+
|
| 2223 |
+
|
| 2224 |
+
def test_issue_6611a():
|
| 2225 |
+
assert Mul.flatten([3**Rational(1, 3),
|
| 2226 |
+
Pow(-Rational(1, 9), Rational(2, 3), evaluate=False)]) == \
|
| 2227 |
+
([Rational(1, 3), (-1)**Rational(2, 3)], [], None)
|
| 2228 |
+
|
| 2229 |
+
|
| 2230 |
+
def test_denest_add_mul():
|
| 2231 |
+
# when working with evaluated expressions make sure they denest
|
| 2232 |
+
eq = x + 1
|
| 2233 |
+
eq = Add(eq, 2, evaluate=False)
|
| 2234 |
+
eq = Add(eq, 2, evaluate=False)
|
| 2235 |
+
assert Add(*eq.args) == x + 5
|
| 2236 |
+
eq = x*2
|
| 2237 |
+
eq = Mul(eq, 2, evaluate=False)
|
| 2238 |
+
eq = Mul(eq, 2, evaluate=False)
|
| 2239 |
+
assert Mul(*eq.args) == 8*x
|
| 2240 |
+
# but don't let them denest unnecessarily
|
| 2241 |
+
eq = Mul(-2, x - 2, evaluate=False)
|
| 2242 |
+
assert 2*eq == Mul(-4, x - 2, evaluate=False)
|
| 2243 |
+
assert -eq == Mul(2, x - 2, evaluate=False)
|
| 2244 |
+
|
| 2245 |
+
|
| 2246 |
+
def test_mul_coeff():
|
| 2247 |
+
# It is important that all Numbers be removed from the seq;
|
| 2248 |
+
# This can be tricky when powers combine to produce those numbers
|
| 2249 |
+
p = exp(I*pi/3)
|
| 2250 |
+
assert p**2*x*p*y*p*x*p**2 == x**2*y
|
| 2251 |
+
|
| 2252 |
+
|
| 2253 |
+
def test_mul_zero_detection():
|
| 2254 |
+
nz = Dummy(real=True, zero=False)
|
| 2255 |
+
r = Dummy(extended_real=True)
|
| 2256 |
+
c = Dummy(real=False, complex=True)
|
| 2257 |
+
c2 = Dummy(real=False, complex=True)
|
| 2258 |
+
i = Dummy(imaginary=True)
|
| 2259 |
+
e = nz*r*c
|
| 2260 |
+
assert e.is_imaginary is None
|
| 2261 |
+
assert e.is_extended_real is None
|
| 2262 |
+
e = nz*c
|
| 2263 |
+
assert e.is_imaginary is None
|
| 2264 |
+
assert e.is_extended_real is False
|
| 2265 |
+
e = nz*i*c
|
| 2266 |
+
assert e.is_imaginary is False
|
| 2267 |
+
assert e.is_extended_real is None
|
| 2268 |
+
# check for more than one complex; it is important to use
|
| 2269 |
+
# uniquely named Symbols to ensure that two factors appear
|
| 2270 |
+
# e.g. if the symbols have the same name they just become
|
| 2271 |
+
# a single factor, a power.
|
| 2272 |
+
e = nz*i*c*c2
|
| 2273 |
+
assert e.is_imaginary is None
|
| 2274 |
+
assert e.is_extended_real is None
|
| 2275 |
+
|
| 2276 |
+
# _eval_is_extended_real and _eval_is_zero both employ trapping of the
|
| 2277 |
+
# zero value so args should be tested in both directions and
|
| 2278 |
+
# TO AVOID GETTING THE CACHED RESULT, Dummy MUST BE USED
|
| 2279 |
+
|
| 2280 |
+
# real is unknown
|
| 2281 |
+
def test(z, b, e):
|
| 2282 |
+
if z.is_zero and b.is_finite:
|
| 2283 |
+
assert e.is_extended_real and e.is_zero
|
| 2284 |
+
else:
|
| 2285 |
+
assert e.is_extended_real is None
|
| 2286 |
+
if b.is_finite:
|
| 2287 |
+
if z.is_zero:
|
| 2288 |
+
assert e.is_zero
|
| 2289 |
+
else:
|
| 2290 |
+
assert e.is_zero is None
|
| 2291 |
+
elif b.is_finite is False:
|
| 2292 |
+
if z.is_zero is None:
|
| 2293 |
+
assert e.is_zero is None
|
| 2294 |
+
else:
|
| 2295 |
+
assert e.is_zero is False
|
| 2296 |
+
|
| 2297 |
+
|
| 2298 |
+
for iz, ib in product(*[[True, False, None]]*2):
|
| 2299 |
+
z = Dummy('z', nonzero=iz)
|
| 2300 |
+
b = Dummy('f', finite=ib)
|
| 2301 |
+
e = Mul(z, b, evaluate=False)
|
| 2302 |
+
test(z, b, e)
|
| 2303 |
+
z = Dummy('nz', nonzero=iz)
|
| 2304 |
+
b = Dummy('f', finite=ib)
|
| 2305 |
+
e = Mul(b, z, evaluate=False)
|
| 2306 |
+
test(z, b, e)
|
| 2307 |
+
|
| 2308 |
+
# real is True
|
| 2309 |
+
def test(z, b, e):
|
| 2310 |
+
if z.is_zero and not b.is_finite:
|
| 2311 |
+
assert e.is_extended_real is None
|
| 2312 |
+
else:
|
| 2313 |
+
assert e.is_extended_real is True
|
| 2314 |
+
|
| 2315 |
+
for iz, ib in product(*[[True, False, None]]*2):
|
| 2316 |
+
z = Dummy('z', nonzero=iz, extended_real=True)
|
| 2317 |
+
b = Dummy('b', finite=ib, extended_real=True)
|
| 2318 |
+
e = Mul(z, b, evaluate=False)
|
| 2319 |
+
test(z, b, e)
|
| 2320 |
+
z = Dummy('z', nonzero=iz, extended_real=True)
|
| 2321 |
+
b = Dummy('b', finite=ib, extended_real=True)
|
| 2322 |
+
e = Mul(b, z, evaluate=False)
|
| 2323 |
+
test(z, b, e)
|
| 2324 |
+
|
| 2325 |
+
|
| 2326 |
+
def test_Mul_with_zero_infinite():
|
| 2327 |
+
zer = Dummy(zero=True)
|
| 2328 |
+
inf = Dummy(finite=False)
|
| 2329 |
+
|
| 2330 |
+
e = Mul(zer, inf, evaluate=False)
|
| 2331 |
+
assert e.is_extended_positive is None
|
| 2332 |
+
assert e.is_hermitian is None
|
| 2333 |
+
|
| 2334 |
+
e = Mul(inf, zer, evaluate=False)
|
| 2335 |
+
assert e.is_extended_positive is None
|
| 2336 |
+
assert e.is_hermitian is None
|
| 2337 |
+
|
| 2338 |
+
|
| 2339 |
+
def test_Mul_does_not_cancel_infinities():
|
| 2340 |
+
a, b = symbols('a b')
|
| 2341 |
+
assert ((zoo + 3*a)/(3*a + zoo)) is nan
|
| 2342 |
+
assert ((b - oo)/(b - oo)) is nan
|
| 2343 |
+
# issue 13904
|
| 2344 |
+
expr = (1/(a+b) + 1/(a-b))/(1/(a+b) - 1/(a-b))
|
| 2345 |
+
assert expr.subs(b, a) is nan
|
| 2346 |
+
|
| 2347 |
+
|
| 2348 |
+
def test_Mul_does_not_distribute_infinity():
|
| 2349 |
+
a, b = symbols('a b')
|
| 2350 |
+
assert ((1 + I)*oo).is_Mul
|
| 2351 |
+
assert ((a + b)*(-oo)).is_Mul
|
| 2352 |
+
assert ((a + 1)*zoo).is_Mul
|
| 2353 |
+
assert ((1 + I)*oo).is_finite is False
|
| 2354 |
+
z = (1 + I)*oo
|
| 2355 |
+
assert ((1 - I)*z).expand() is oo
|
| 2356 |
+
|
| 2357 |
+
|
| 2358 |
+
def test_issue_8247_8354():
|
| 2359 |
+
from sympy.functions.elementary.trigonometric import tan
|
| 2360 |
+
z = sqrt(1 + sqrt(3)) + sqrt(3 + 3*sqrt(3)) - sqrt(10 + 6*sqrt(3))
|
| 2361 |
+
assert z.is_positive is False # it's 0
|
| 2362 |
+
z = S('''-2**(1/3)*(3*sqrt(93) + 29)**2 - 4*(3*sqrt(93) + 29)**(4/3) +
|
| 2363 |
+
12*sqrt(93)*(3*sqrt(93) + 29)**(1/3) + 116*(3*sqrt(93) + 29)**(1/3) +
|
| 2364 |
+
174*2**(1/3)*sqrt(93) + 1678*2**(1/3)''')
|
| 2365 |
+
assert z.is_positive is False # it's 0
|
| 2366 |
+
z = 2*(-3*tan(19*pi/90) + sqrt(3))*cos(11*pi/90)*cos(19*pi/90) - \
|
| 2367 |
+
sqrt(3)*(-3 + 4*cos(19*pi/90)**2)
|
| 2368 |
+
assert z.is_positive is not True # it's zero and it shouldn't hang
|
| 2369 |
+
z = S('''9*(3*sqrt(93) + 29)**(2/3)*((3*sqrt(93) +
|
| 2370 |
+
29)**(1/3)*(-2**(2/3)*(3*sqrt(93) + 29)**(1/3) - 2) - 2*2**(1/3))**3 +
|
| 2371 |
+
72*(3*sqrt(93) + 29)**(2/3)*(81*sqrt(93) + 783) + (162*sqrt(93) +
|
| 2372 |
+
1566)*((3*sqrt(93) + 29)**(1/3)*(-2**(2/3)*(3*sqrt(93) + 29)**(1/3) -
|
| 2373 |
+
2) - 2*2**(1/3))**2''')
|
| 2374 |
+
assert z.is_positive is False # it's 0 (and a single _mexpand isn't enough)
|
| 2375 |
+
|
| 2376 |
+
|
| 2377 |
+
def test_Add_is_zero():
|
| 2378 |
+
x, y = symbols('x y', zero=True)
|
| 2379 |
+
assert (x + y).is_zero
|
| 2380 |
+
|
| 2381 |
+
# Issue 15873
|
| 2382 |
+
e = -2*I + (1 + I)**2
|
| 2383 |
+
assert e.is_zero is None
|
| 2384 |
+
|
| 2385 |
+
|
| 2386 |
+
def test_issue_14392():
|
| 2387 |
+
assert (sin(zoo)**2).as_real_imag() == (nan, nan)
|
| 2388 |
+
|
| 2389 |
+
|
| 2390 |
+
def test_divmod():
|
| 2391 |
+
assert divmod(x, y) == (x//y, x % y)
|
| 2392 |
+
assert divmod(x, 3) == (x//3, x % 3)
|
| 2393 |
+
assert divmod(3, x) == (3//x, 3 % x)
|
| 2394 |
+
|
| 2395 |
+
|
| 2396 |
+
def test__neg__():
|
| 2397 |
+
assert -(x*y) == -x*y
|
| 2398 |
+
assert -(-x*y) == x*y
|
| 2399 |
+
assert -(1.*x) == -1.*x
|
| 2400 |
+
assert -(-1.*x) == 1.*x
|
| 2401 |
+
assert -(2.*x) == -2.*x
|
| 2402 |
+
assert -(-2.*x) == 2.*x
|
| 2403 |
+
with distribute(False):
|
| 2404 |
+
eq = -(x + y)
|
| 2405 |
+
assert eq.is_Mul and eq.args == (-1, x + y)
|
| 2406 |
+
with evaluate(False):
|
| 2407 |
+
eq = -(x + y)
|
| 2408 |
+
assert eq.is_Mul and eq.args == (-1, x + y)
|
| 2409 |
+
|
| 2410 |
+
|
| 2411 |
+
def test_issue_18507():
|
| 2412 |
+
assert Mul(zoo, zoo, 0) is nan
|
| 2413 |
+
|
| 2414 |
+
|
| 2415 |
+
def test_issue_17130():
|
| 2416 |
+
e = Add(b, -b, I, -I, evaluate=False)
|
| 2417 |
+
assert e.is_zero is None # ideally this would be True
|
| 2418 |
+
|
| 2419 |
+
|
| 2420 |
+
def test_issue_21034():
|
| 2421 |
+
e = -I*log((re(asin(5)) + I*im(asin(5)))/sqrt(re(asin(5))**2 + im(asin(5))**2))/pi
|
| 2422 |
+
assert e.round(2)
|
| 2423 |
+
|
| 2424 |
+
|
| 2425 |
+
def test_issue_22021():
|
| 2426 |
+
from sympy.calculus.accumulationbounds import AccumBounds
|
| 2427 |
+
# these objects are special cases in Mul
|
| 2428 |
+
from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensor_heads
|
| 2429 |
+
L = TensorIndexType("L")
|
| 2430 |
+
i = tensor_indices("i", L)
|
| 2431 |
+
A, B = tensor_heads("A B", [L])
|
| 2432 |
+
e = A(i) + B(i)
|
| 2433 |
+
assert -e == -1*e
|
| 2434 |
+
e = zoo + x
|
| 2435 |
+
assert -e == -1*e
|
| 2436 |
+
a = AccumBounds(1, 2)
|
| 2437 |
+
e = a + x
|
| 2438 |
+
assert -e == -1*e
|
| 2439 |
+
for args in permutations((zoo, a, x)):
|
| 2440 |
+
e = Add(*args, evaluate=False)
|
| 2441 |
+
assert -e == -1*e
|
| 2442 |
+
assert 2*Add(1, x, x, evaluate=False) == 4*x + 2
|
| 2443 |
+
|
| 2444 |
+
|
| 2445 |
+
def test_issue_22244():
|
| 2446 |
+
assert -(zoo*x) == zoo*x
|
| 2447 |
+
|
| 2448 |
+
|
| 2449 |
+
def test_issue_22453():
|
| 2450 |
+
from sympy.utilities.iterables import cartes
|
| 2451 |
+
e = Symbol('e', extended_positive=True)
|
| 2452 |
+
for a, b in cartes(*[[oo, -oo, 3]]*2):
|
| 2453 |
+
if a == b == 3:
|
| 2454 |
+
continue
|
| 2455 |
+
i = a + I*b
|
| 2456 |
+
assert i**(1 + e) is S.ComplexInfinity
|
| 2457 |
+
assert i**-e is S.Zero
|
| 2458 |
+
assert unchanged(Pow, i, e)
|
| 2459 |
+
assert 1/(oo + I*oo) is S.Zero
|
| 2460 |
+
r, i = [Dummy(infinite=True, extended_real=True) for _ in range(2)]
|
| 2461 |
+
assert 1/(r + I*i) is S.Zero
|
| 2462 |
+
assert 1/(3 + I*i) is S.Zero
|
| 2463 |
+
assert 1/(r + I*3) is S.Zero
|
| 2464 |
+
|
| 2465 |
+
|
| 2466 |
+
def test_issue_22613():
|
| 2467 |
+
assert (0**(x - 2)).as_content_primitive() == (1, 0**(x - 2))
|
| 2468 |
+
assert (0**(x + 2)).as_content_primitive() == (1, 0**(x + 2))
|
| 2469 |
+
|
| 2470 |
+
|
| 2471 |
+
def test_issue_25176():
|
| 2472 |
+
assert sqrt(-4*3**(S(3)/4)*I/3) == 2*3**(S(7)/8)*sqrt(-I)/3
|