applied-ai-018 commited on
Commit
9e8f256
·
verified ·
1 Parent(s): efb0ef9

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. ckpts/universal/global_step80/zero/12.mlp.dense_h_to_4h_swiglu.weight/exp_avg.pt +3 -0
  2. ckpts/universal/global_step80/zero/12.mlp.dense_h_to_4h_swiglu.weight/exp_avg_sq.pt +3 -0
  3. ckpts/universal/global_step80/zero/12.mlp.dense_h_to_4h_swiglu.weight/fp32.pt +3 -0
  4. ckpts/universal/global_step80/zero/23.attention.dense.weight/exp_avg.pt +3 -0
  5. ckpts/universal/global_step80/zero/23.attention.dense.weight/exp_avg_sq.pt +3 -0
  6. ckpts/universal/global_step80/zero/6.mlp.dense_4h_to_h.weight/exp_avg.pt +3 -0
  7. ckpts/universal/global_step80/zero/6.mlp.dense_4h_to_h.weight/exp_avg_sq.pt +3 -0
  8. ckpts/universal/global_step80/zero/6.mlp.dense_4h_to_h.weight/fp32.pt +3 -0
  9. ckpts/universal/global_step80/zero/6.mlp.dense_h_to_4h.weight/exp_avg_sq.pt +3 -0
  10. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/densetools.cpython-310.pyc +0 -0
  11. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/domainmatrix.cpython-310.pyc +0 -0
  12. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/euclidtools.cpython-310.pyc +0 -0
  13. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/factortools.cpython-310.pyc +0 -0
  14. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/fglmtools.cpython-310.pyc +0 -0
  15. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/fields.cpython-310.pyc +0 -0
  16. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/galoistools.cpython-310.pyc +0 -0
  17. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/groebnertools.cpython-310.pyc +0 -0
  18. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/monomials.cpython-310.pyc +0 -0
  19. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/multivariate_resultants.cpython-310.pyc +0 -0
  20. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/orthopolys.cpython-310.pyc +0 -0
  21. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/polyclasses.cpython-310.pyc +0 -0
  22. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/polyoptions.cpython-310.pyc +0 -0
  23. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/polyquinticconst.cpython-310.pyc +0 -0
  24. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/polyroots.cpython-310.pyc +0 -0
  25. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/polytools.cpython-310.pyc +0 -0
  26. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/ring_series.cpython-310.pyc +0 -0
  27. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/rootisolation.cpython-310.pyc +0 -0
  28. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/rootoftools.cpython-310.pyc +0 -0
  29. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/solvers.cpython-310.pyc +0 -0
  30. venv/lib/python3.10/site-packages/sympy/polys/__pycache__/sqfreetools.cpython-310.pyc +0 -0
  31. venv/lib/python3.10/site-packages/sympy/polys/domains/__pycache__/__init__.cpython-310.pyc +0 -0
  32. venv/lib/python3.10/site-packages/sympy/polys/domains/__pycache__/algebraicfield.cpython-310.pyc +0 -0
  33. venv/lib/python3.10/site-packages/sympy/polys/domains/__pycache__/domain.cpython-310.pyc +0 -0
  34. venv/lib/python3.10/site-packages/sympy/polys/domains/__pycache__/gaussiandomains.cpython-310.pyc +0 -0
  35. venv/lib/python3.10/site-packages/sympy/polys/domains/__pycache__/polynomialring.cpython-310.pyc +0 -0
  36. venv/lib/python3.10/site-packages/sympy/polys/domains/__pycache__/pythonrational.cpython-310.pyc +0 -0
  37. venv/lib/python3.10/site-packages/sympy/polys/domains/__pycache__/quotientring.cpython-310.pyc +0 -0
  38. venv/lib/python3.10/site-packages/sympy/polys/domains/__pycache__/rationalfield.cpython-310.pyc +0 -0
  39. venv/lib/python3.10/site-packages/sympy/polys/domains/tests/test_domains.py +1270 -0
  40. venv/lib/python3.10/site-packages/sympy/polys/domains/tests/test_quotientring.py +52 -0
  41. venv/lib/python3.10/site-packages/sympy/polys/matrices/__init__.py +15 -0
  42. venv/lib/python3.10/site-packages/sympy/polys/matrices/__pycache__/__init__.cpython-310.pyc +0 -0
  43. venv/lib/python3.10/site-packages/sympy/polys/matrices/__pycache__/_typing.cpython-310.pyc +0 -0
  44. venv/lib/python3.10/site-packages/sympy/polys/matrices/__pycache__/ddm.cpython-310.pyc +0 -0
  45. venv/lib/python3.10/site-packages/sympy/polys/matrices/__pycache__/dense.cpython-310.pyc +0 -0
  46. venv/lib/python3.10/site-packages/sympy/polys/matrices/__pycache__/domainmatrix.cpython-310.pyc +0 -0
  47. venv/lib/python3.10/site-packages/sympy/polys/matrices/__pycache__/domainscalar.cpython-310.pyc +0 -0
  48. venv/lib/python3.10/site-packages/sympy/polys/matrices/__pycache__/eigen.cpython-310.pyc +0 -0
  49. venv/lib/python3.10/site-packages/sympy/polys/matrices/__pycache__/exceptions.cpython-310.pyc +0 -0
  50. venv/lib/python3.10/site-packages/sympy/polys/matrices/__pycache__/linsolve.cpython-310.pyc +0 -0
ckpts/universal/global_step80/zero/12.mlp.dense_h_to_4h_swiglu.weight/exp_avg.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a79c26837e5e1261bb8df5f53463bca0955fe1cbc767306114215d135deb4265
3
+ size 33555612
ckpts/universal/global_step80/zero/12.mlp.dense_h_to_4h_swiglu.weight/exp_avg_sq.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:945610025c9bd8455ff2af170585cbd5081a9105c2fc68a9aff6dfd9d5b05edb
3
+ size 33555627
ckpts/universal/global_step80/zero/12.mlp.dense_h_to_4h_swiglu.weight/fp32.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1ef41b1c3339126dc370ebbd5ed7ad118c5703680f21b886bef02c0218d2462b
3
+ size 33555533
ckpts/universal/global_step80/zero/23.attention.dense.weight/exp_avg.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b954caf5c36821e0a54a0b1b7fad4fd058494fa54b382d80859cb3261b9e258e
3
+ size 16778396
ckpts/universal/global_step80/zero/23.attention.dense.weight/exp_avg_sq.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9e768a62dc459a94256304a9d1359f93dda912be3d366faabe653958d76e949c
3
+ size 16778411
ckpts/universal/global_step80/zero/6.mlp.dense_4h_to_h.weight/exp_avg.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:37e66bc6b72bd770b0e41e08bbce4eca34577ee11ca51e39c03f105876542248
3
+ size 33555612
ckpts/universal/global_step80/zero/6.mlp.dense_4h_to_h.weight/exp_avg_sq.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e2cb6d3a787f0a7ad6e85e4762e6e4b24f07a1f692a4944aec56fcdb476b5b00
3
+ size 33555627
ckpts/universal/global_step80/zero/6.mlp.dense_4h_to_h.weight/fp32.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4835f3a8bfd698242f3933033f5064cd06c6e678f73c4ed9c0b832c2c9496255
3
+ size 33555533
ckpts/universal/global_step80/zero/6.mlp.dense_h_to_4h.weight/exp_avg_sq.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:daf06bb8e3b1f13cac3f6bcb5737a0f75d79b6b42fb73a599fd8d1b6526a0a51
3
+ size 33555627
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/densetools.cpython-310.pyc ADDED
Binary file (26.9 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/domainmatrix.cpython-310.pyc ADDED
Binary file (507 Bytes). View file
 
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/euclidtools.cpython-310.pyc ADDED
Binary file (37.2 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/factortools.cpython-310.pyc ADDED
Binary file (33.3 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/fglmtools.cpython-310.pyc ADDED
Binary file (6.94 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/fields.cpython-310.pyc ADDED
Binary file (18.8 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/galoistools.cpython-310.pyc ADDED
Binary file (53.4 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/groebnertools.cpython-310.pyc ADDED
Binary file (22.7 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/monomials.cpython-310.pyc ADDED
Binary file (19.9 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/multivariate_resultants.cpython-310.pyc ADDED
Binary file (17.4 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/orthopolys.cpython-310.pyc ADDED
Binary file (8.96 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/polyclasses.cpython-310.pyc ADDED
Binary file (55.1 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/polyoptions.cpython-310.pyc ADDED
Binary file (21.4 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/polyquinticconst.cpython-310.pyc ADDED
Binary file (132 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/polyroots.cpython-310.pyc ADDED
Binary file (31 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/polytools.cpython-310.pyc ADDED
Binary file (176 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/ring_series.cpython-310.pyc ADDED
Binary file (47.9 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/rootisolation.cpython-310.pyc ADDED
Binary file (51.2 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/rootoftools.cpython-310.pyc ADDED
Binary file (34.3 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/solvers.cpython-310.pyc ADDED
Binary file (13.9 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/__pycache__/sqfreetools.cpython-310.pyc ADDED
Binary file (11.1 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/domains/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (1.7 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/domains/__pycache__/algebraicfield.cpython-310.pyc ADDED
Binary file (23 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/domains/__pycache__/domain.cpython-310.pyc ADDED
Binary file (35.8 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/domains/__pycache__/gaussiandomains.cpython-310.pyc ADDED
Binary file (20.4 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/domains/__pycache__/polynomialring.cpython-310.pyc ADDED
Binary file (7.91 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/domains/__pycache__/pythonrational.cpython-310.pyc ADDED
Binary file (802 Bytes). View file
 
venv/lib/python3.10/site-packages/sympy/polys/domains/__pycache__/quotientring.cpython-310.pyc ADDED
Binary file (7.29 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/domains/__pycache__/rationalfield.cpython-310.pyc ADDED
Binary file (6.28 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/domains/tests/test_domains.py ADDED
@@ -0,0 +1,1270 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tests for classes defining properties of ground domains, e.g. ZZ, QQ, ZZ[x] ... """
2
+
3
+ from sympy.core.numbers import (AlgebraicNumber, E, Float, I, Integer,
4
+ Rational, oo, pi, _illegal)
5
+ from sympy.core.singleton import S
6
+ from sympy.functions.elementary.exponential import exp
7
+ from sympy.functions.elementary.miscellaneous import sqrt
8
+ from sympy.functions.elementary.trigonometric import sin
9
+ from sympy.polys.polytools import Poly
10
+ from sympy.abc import x, y, z
11
+
12
+ from sympy.external.gmpy import HAS_GMPY
13
+
14
+ from sympy.polys.domains import (ZZ, QQ, RR, CC, FF, GF, EX, EXRAW, ZZ_gmpy,
15
+ ZZ_python, QQ_gmpy, QQ_python)
16
+ from sympy.polys.domains.algebraicfield import AlgebraicField
17
+ from sympy.polys.domains.gaussiandomains import ZZ_I, QQ_I
18
+ from sympy.polys.domains.polynomialring import PolynomialRing
19
+ from sympy.polys.domains.realfield import RealField
20
+
21
+ from sympy.polys.numberfields.subfield import field_isomorphism
22
+ from sympy.polys.rings import ring
23
+ from sympy.polys.specialpolys import cyclotomic_poly
24
+ from sympy.polys.fields import field
25
+
26
+ from sympy.polys.agca.extensions import FiniteExtension
27
+
28
+ from sympy.polys.polyerrors import (
29
+ UnificationFailed,
30
+ GeneratorsError,
31
+ CoercionFailed,
32
+ NotInvertible,
33
+ DomainError)
34
+
35
+ from sympy.testing.pytest import raises
36
+
37
+ from itertools import product
38
+
39
+ ALG = QQ.algebraic_field(sqrt(2), sqrt(3))
40
+
41
+ def unify(K0, K1):
42
+ return K0.unify(K1)
43
+
44
+ def test_Domain_unify():
45
+ F3 = GF(3)
46
+
47
+ assert unify(F3, F3) == F3
48
+ assert unify(F3, ZZ) == ZZ
49
+ assert unify(F3, QQ) == QQ
50
+ assert unify(F3, ALG) == ALG
51
+ assert unify(F3, RR) == RR
52
+ assert unify(F3, CC) == CC
53
+ assert unify(F3, ZZ[x]) == ZZ[x]
54
+ assert unify(F3, ZZ.frac_field(x)) == ZZ.frac_field(x)
55
+ assert unify(F3, EX) == EX
56
+
57
+ assert unify(ZZ, F3) == ZZ
58
+ assert unify(ZZ, ZZ) == ZZ
59
+ assert unify(ZZ, QQ) == QQ
60
+ assert unify(ZZ, ALG) == ALG
61
+ assert unify(ZZ, RR) == RR
62
+ assert unify(ZZ, CC) == CC
63
+ assert unify(ZZ, ZZ[x]) == ZZ[x]
64
+ assert unify(ZZ, ZZ.frac_field(x)) == ZZ.frac_field(x)
65
+ assert unify(ZZ, EX) == EX
66
+
67
+ assert unify(QQ, F3) == QQ
68
+ assert unify(QQ, ZZ) == QQ
69
+ assert unify(QQ, QQ) == QQ
70
+ assert unify(QQ, ALG) == ALG
71
+ assert unify(QQ, RR) == RR
72
+ assert unify(QQ, CC) == CC
73
+ assert unify(QQ, ZZ[x]) == QQ[x]
74
+ assert unify(QQ, ZZ.frac_field(x)) == QQ.frac_field(x)
75
+ assert unify(QQ, EX) == EX
76
+
77
+ assert unify(ZZ_I, F3) == ZZ_I
78
+ assert unify(ZZ_I, ZZ) == ZZ_I
79
+ assert unify(ZZ_I, ZZ_I) == ZZ_I
80
+ assert unify(ZZ_I, QQ) == QQ_I
81
+ assert unify(ZZ_I, ALG) == QQ.algebraic_field(I, sqrt(2), sqrt(3))
82
+ assert unify(ZZ_I, RR) == CC
83
+ assert unify(ZZ_I, CC) == CC
84
+ assert unify(ZZ_I, ZZ[x]) == ZZ_I[x]
85
+ assert unify(ZZ_I, ZZ_I[x]) == ZZ_I[x]
86
+ assert unify(ZZ_I, ZZ.frac_field(x)) == ZZ_I.frac_field(x)
87
+ assert unify(ZZ_I, ZZ_I.frac_field(x)) == ZZ_I.frac_field(x)
88
+ assert unify(ZZ_I, EX) == EX
89
+
90
+ assert unify(QQ_I, F3) == QQ_I
91
+ assert unify(QQ_I, ZZ) == QQ_I
92
+ assert unify(QQ_I, ZZ_I) == QQ_I
93
+ assert unify(QQ_I, QQ) == QQ_I
94
+ assert unify(QQ_I, ALG) == QQ.algebraic_field(I, sqrt(2), sqrt(3))
95
+ assert unify(QQ_I, RR) == CC
96
+ assert unify(QQ_I, CC) == CC
97
+ assert unify(QQ_I, ZZ[x]) == QQ_I[x]
98
+ assert unify(QQ_I, ZZ_I[x]) == QQ_I[x]
99
+ assert unify(QQ_I, QQ[x]) == QQ_I[x]
100
+ assert unify(QQ_I, QQ_I[x]) == QQ_I[x]
101
+ assert unify(QQ_I, ZZ.frac_field(x)) == QQ_I.frac_field(x)
102
+ assert unify(QQ_I, ZZ_I.frac_field(x)) == QQ_I.frac_field(x)
103
+ assert unify(QQ_I, QQ.frac_field(x)) == QQ_I.frac_field(x)
104
+ assert unify(QQ_I, QQ_I.frac_field(x)) == QQ_I.frac_field(x)
105
+ assert unify(QQ_I, EX) == EX
106
+
107
+ assert unify(RR, F3) == RR
108
+ assert unify(RR, ZZ) == RR
109
+ assert unify(RR, QQ) == RR
110
+ assert unify(RR, ALG) == RR
111
+ assert unify(RR, RR) == RR
112
+ assert unify(RR, CC) == CC
113
+ assert unify(RR, ZZ[x]) == RR[x]
114
+ assert unify(RR, ZZ.frac_field(x)) == RR.frac_field(x)
115
+ assert unify(RR, EX) == EX
116
+ assert RR[x].unify(ZZ.frac_field(y)) == RR.frac_field(x, y)
117
+
118
+ assert unify(CC, F3) == CC
119
+ assert unify(CC, ZZ) == CC
120
+ assert unify(CC, QQ) == CC
121
+ assert unify(CC, ALG) == CC
122
+ assert unify(CC, RR) == CC
123
+ assert unify(CC, CC) == CC
124
+ assert unify(CC, ZZ[x]) == CC[x]
125
+ assert unify(CC, ZZ.frac_field(x)) == CC.frac_field(x)
126
+ assert unify(CC, EX) == EX
127
+
128
+ assert unify(ZZ[x], F3) == ZZ[x]
129
+ assert unify(ZZ[x], ZZ) == ZZ[x]
130
+ assert unify(ZZ[x], QQ) == QQ[x]
131
+ assert unify(ZZ[x], ALG) == ALG[x]
132
+ assert unify(ZZ[x], RR) == RR[x]
133
+ assert unify(ZZ[x], CC) == CC[x]
134
+ assert unify(ZZ[x], ZZ[x]) == ZZ[x]
135
+ assert unify(ZZ[x], ZZ.frac_field(x)) == ZZ.frac_field(x)
136
+ assert unify(ZZ[x], EX) == EX
137
+
138
+ assert unify(ZZ.frac_field(x), F3) == ZZ.frac_field(x)
139
+ assert unify(ZZ.frac_field(x), ZZ) == ZZ.frac_field(x)
140
+ assert unify(ZZ.frac_field(x), QQ) == QQ.frac_field(x)
141
+ assert unify(ZZ.frac_field(x), ALG) == ALG.frac_field(x)
142
+ assert unify(ZZ.frac_field(x), RR) == RR.frac_field(x)
143
+ assert unify(ZZ.frac_field(x), CC) == CC.frac_field(x)
144
+ assert unify(ZZ.frac_field(x), ZZ[x]) == ZZ.frac_field(x)
145
+ assert unify(ZZ.frac_field(x), ZZ.frac_field(x)) == ZZ.frac_field(x)
146
+ assert unify(ZZ.frac_field(x), EX) == EX
147
+
148
+ assert unify(EX, F3) == EX
149
+ assert unify(EX, ZZ) == EX
150
+ assert unify(EX, QQ) == EX
151
+ assert unify(EX, ALG) == EX
152
+ assert unify(EX, RR) == EX
153
+ assert unify(EX, CC) == EX
154
+ assert unify(EX, ZZ[x]) == EX
155
+ assert unify(EX, ZZ.frac_field(x)) == EX
156
+ assert unify(EX, EX) == EX
157
+
158
+ def test_Domain_unify_composite():
159
+ assert unify(ZZ.poly_ring(x), ZZ) == ZZ.poly_ring(x)
160
+ assert unify(ZZ.poly_ring(x), QQ) == QQ.poly_ring(x)
161
+ assert unify(QQ.poly_ring(x), ZZ) == QQ.poly_ring(x)
162
+ assert unify(QQ.poly_ring(x), QQ) == QQ.poly_ring(x)
163
+
164
+ assert unify(ZZ, ZZ.poly_ring(x)) == ZZ.poly_ring(x)
165
+ assert unify(QQ, ZZ.poly_ring(x)) == QQ.poly_ring(x)
166
+ assert unify(ZZ, QQ.poly_ring(x)) == QQ.poly_ring(x)
167
+ assert unify(QQ, QQ.poly_ring(x)) == QQ.poly_ring(x)
168
+
169
+ assert unify(ZZ.poly_ring(x, y), ZZ) == ZZ.poly_ring(x, y)
170
+ assert unify(ZZ.poly_ring(x, y), QQ) == QQ.poly_ring(x, y)
171
+ assert unify(QQ.poly_ring(x, y), ZZ) == QQ.poly_ring(x, y)
172
+ assert unify(QQ.poly_ring(x, y), QQ) == QQ.poly_ring(x, y)
173
+
174
+ assert unify(ZZ, ZZ.poly_ring(x, y)) == ZZ.poly_ring(x, y)
175
+ assert unify(QQ, ZZ.poly_ring(x, y)) == QQ.poly_ring(x, y)
176
+ assert unify(ZZ, QQ.poly_ring(x, y)) == QQ.poly_ring(x, y)
177
+ assert unify(QQ, QQ.poly_ring(x, y)) == QQ.poly_ring(x, y)
178
+
179
+ assert unify(ZZ.frac_field(x), ZZ) == ZZ.frac_field(x)
180
+ assert unify(ZZ.frac_field(x), QQ) == QQ.frac_field(x)
181
+ assert unify(QQ.frac_field(x), ZZ) == QQ.frac_field(x)
182
+ assert unify(QQ.frac_field(x), QQ) == QQ.frac_field(x)
183
+
184
+ assert unify(ZZ, ZZ.frac_field(x)) == ZZ.frac_field(x)
185
+ assert unify(QQ, ZZ.frac_field(x)) == QQ.frac_field(x)
186
+ assert unify(ZZ, QQ.frac_field(x)) == QQ.frac_field(x)
187
+ assert unify(QQ, QQ.frac_field(x)) == QQ.frac_field(x)
188
+
189
+ assert unify(ZZ.frac_field(x, y), ZZ) == ZZ.frac_field(x, y)
190
+ assert unify(ZZ.frac_field(x, y), QQ) == QQ.frac_field(x, y)
191
+ assert unify(QQ.frac_field(x, y), ZZ) == QQ.frac_field(x, y)
192
+ assert unify(QQ.frac_field(x, y), QQ) == QQ.frac_field(x, y)
193
+
194
+ assert unify(ZZ, ZZ.frac_field(x, y)) == ZZ.frac_field(x, y)
195
+ assert unify(QQ, ZZ.frac_field(x, y)) == QQ.frac_field(x, y)
196
+ assert unify(ZZ, QQ.frac_field(x, y)) == QQ.frac_field(x, y)
197
+ assert unify(QQ, QQ.frac_field(x, y)) == QQ.frac_field(x, y)
198
+
199
+ assert unify(ZZ.poly_ring(x), ZZ.poly_ring(x)) == ZZ.poly_ring(x)
200
+ assert unify(ZZ.poly_ring(x), QQ.poly_ring(x)) == QQ.poly_ring(x)
201
+ assert unify(QQ.poly_ring(x), ZZ.poly_ring(x)) == QQ.poly_ring(x)
202
+ assert unify(QQ.poly_ring(x), QQ.poly_ring(x)) == QQ.poly_ring(x)
203
+
204
+ assert unify(ZZ.poly_ring(x, y), ZZ.poly_ring(x)) == ZZ.poly_ring(x, y)
205
+ assert unify(ZZ.poly_ring(x, y), QQ.poly_ring(x)) == QQ.poly_ring(x, y)
206
+ assert unify(QQ.poly_ring(x, y), ZZ.poly_ring(x)) == QQ.poly_ring(x, y)
207
+ assert unify(QQ.poly_ring(x, y), QQ.poly_ring(x)) == QQ.poly_ring(x, y)
208
+
209
+ assert unify(ZZ.poly_ring(x), ZZ.poly_ring(x, y)) == ZZ.poly_ring(x, y)
210
+ assert unify(ZZ.poly_ring(x), QQ.poly_ring(x, y)) == QQ.poly_ring(x, y)
211
+ assert unify(QQ.poly_ring(x), ZZ.poly_ring(x, y)) == QQ.poly_ring(x, y)
212
+ assert unify(QQ.poly_ring(x), QQ.poly_ring(x, y)) == QQ.poly_ring(x, y)
213
+
214
+ assert unify(ZZ.poly_ring(x, y), ZZ.poly_ring(x, z)) == ZZ.poly_ring(x, y, z)
215
+ assert unify(ZZ.poly_ring(x, y), QQ.poly_ring(x, z)) == QQ.poly_ring(x, y, z)
216
+ assert unify(QQ.poly_ring(x, y), ZZ.poly_ring(x, z)) == QQ.poly_ring(x, y, z)
217
+ assert unify(QQ.poly_ring(x, y), QQ.poly_ring(x, z)) == QQ.poly_ring(x, y, z)
218
+
219
+ assert unify(ZZ.frac_field(x), ZZ.frac_field(x)) == ZZ.frac_field(x)
220
+ assert unify(ZZ.frac_field(x), QQ.frac_field(x)) == QQ.frac_field(x)
221
+ assert unify(QQ.frac_field(x), ZZ.frac_field(x)) == QQ.frac_field(x)
222
+ assert unify(QQ.frac_field(x), QQ.frac_field(x)) == QQ.frac_field(x)
223
+
224
+ assert unify(ZZ.frac_field(x, y), ZZ.frac_field(x)) == ZZ.frac_field(x, y)
225
+ assert unify(ZZ.frac_field(x, y), QQ.frac_field(x)) == QQ.frac_field(x, y)
226
+ assert unify(QQ.frac_field(x, y), ZZ.frac_field(x)) == QQ.frac_field(x, y)
227
+ assert unify(QQ.frac_field(x, y), QQ.frac_field(x)) == QQ.frac_field(x, y)
228
+
229
+ assert unify(ZZ.frac_field(x), ZZ.frac_field(x, y)) == ZZ.frac_field(x, y)
230
+ assert unify(ZZ.frac_field(x), QQ.frac_field(x, y)) == QQ.frac_field(x, y)
231
+ assert unify(QQ.frac_field(x), ZZ.frac_field(x, y)) == QQ.frac_field(x, y)
232
+ assert unify(QQ.frac_field(x), QQ.frac_field(x, y)) == QQ.frac_field(x, y)
233
+
234
+ assert unify(ZZ.frac_field(x, y), ZZ.frac_field(x, z)) == ZZ.frac_field(x, y, z)
235
+ assert unify(ZZ.frac_field(x, y), QQ.frac_field(x, z)) == QQ.frac_field(x, y, z)
236
+ assert unify(QQ.frac_field(x, y), ZZ.frac_field(x, z)) == QQ.frac_field(x, y, z)
237
+ assert unify(QQ.frac_field(x, y), QQ.frac_field(x, z)) == QQ.frac_field(x, y, z)
238
+
239
+ assert unify(ZZ.poly_ring(x), ZZ.frac_field(x)) == ZZ.frac_field(x)
240
+ assert unify(ZZ.poly_ring(x), QQ.frac_field(x)) == ZZ.frac_field(x)
241
+ assert unify(QQ.poly_ring(x), ZZ.frac_field(x)) == ZZ.frac_field(x)
242
+ assert unify(QQ.poly_ring(x), QQ.frac_field(x)) == QQ.frac_field(x)
243
+
244
+ assert unify(ZZ.poly_ring(x, y), ZZ.frac_field(x)) == ZZ.frac_field(x, y)
245
+ assert unify(ZZ.poly_ring(x, y), QQ.frac_field(x)) == ZZ.frac_field(x, y)
246
+ assert unify(QQ.poly_ring(x, y), ZZ.frac_field(x)) == ZZ.frac_field(x, y)
247
+ assert unify(QQ.poly_ring(x, y), QQ.frac_field(x)) == QQ.frac_field(x, y)
248
+
249
+ assert unify(ZZ.poly_ring(x), ZZ.frac_field(x, y)) == ZZ.frac_field(x, y)
250
+ assert unify(ZZ.poly_ring(x), QQ.frac_field(x, y)) == ZZ.frac_field(x, y)
251
+ assert unify(QQ.poly_ring(x), ZZ.frac_field(x, y)) == ZZ.frac_field(x, y)
252
+ assert unify(QQ.poly_ring(x), QQ.frac_field(x, y)) == QQ.frac_field(x, y)
253
+
254
+ assert unify(ZZ.poly_ring(x, y), ZZ.frac_field(x, z)) == ZZ.frac_field(x, y, z)
255
+ assert unify(ZZ.poly_ring(x, y), QQ.frac_field(x, z)) == ZZ.frac_field(x, y, z)
256
+ assert unify(QQ.poly_ring(x, y), ZZ.frac_field(x, z)) == ZZ.frac_field(x, y, z)
257
+ assert unify(QQ.poly_ring(x, y), QQ.frac_field(x, z)) == QQ.frac_field(x, y, z)
258
+
259
+ assert unify(ZZ.frac_field(x), ZZ.poly_ring(x)) == ZZ.frac_field(x)
260
+ assert unify(ZZ.frac_field(x), QQ.poly_ring(x)) == ZZ.frac_field(x)
261
+ assert unify(QQ.frac_field(x), ZZ.poly_ring(x)) == ZZ.frac_field(x)
262
+ assert unify(QQ.frac_field(x), QQ.poly_ring(x)) == QQ.frac_field(x)
263
+
264
+ assert unify(ZZ.frac_field(x, y), ZZ.poly_ring(x)) == ZZ.frac_field(x, y)
265
+ assert unify(ZZ.frac_field(x, y), QQ.poly_ring(x)) == ZZ.frac_field(x, y)
266
+ assert unify(QQ.frac_field(x, y), ZZ.poly_ring(x)) == ZZ.frac_field(x, y)
267
+ assert unify(QQ.frac_field(x, y), QQ.poly_ring(x)) == QQ.frac_field(x, y)
268
+
269
+ assert unify(ZZ.frac_field(x), ZZ.poly_ring(x, y)) == ZZ.frac_field(x, y)
270
+ assert unify(ZZ.frac_field(x), QQ.poly_ring(x, y)) == ZZ.frac_field(x, y)
271
+ assert unify(QQ.frac_field(x), ZZ.poly_ring(x, y)) == ZZ.frac_field(x, y)
272
+ assert unify(QQ.frac_field(x), QQ.poly_ring(x, y)) == QQ.frac_field(x, y)
273
+
274
+ assert unify(ZZ.frac_field(x, y), ZZ.poly_ring(x, z)) == ZZ.frac_field(x, y, z)
275
+ assert unify(ZZ.frac_field(x, y), QQ.poly_ring(x, z)) == ZZ.frac_field(x, y, z)
276
+ assert unify(QQ.frac_field(x, y), ZZ.poly_ring(x, z)) == ZZ.frac_field(x, y, z)
277
+ assert unify(QQ.frac_field(x, y), QQ.poly_ring(x, z)) == QQ.frac_field(x, y, z)
278
+
279
+ def test_Domain_unify_algebraic():
280
+ sqrt5 = QQ.algebraic_field(sqrt(5))
281
+ sqrt7 = QQ.algebraic_field(sqrt(7))
282
+ sqrt57 = QQ.algebraic_field(sqrt(5), sqrt(7))
283
+
284
+ assert sqrt5.unify(sqrt7) == sqrt57
285
+
286
+ assert sqrt5.unify(sqrt5[x, y]) == sqrt5[x, y]
287
+ assert sqrt5[x, y].unify(sqrt5) == sqrt5[x, y]
288
+
289
+ assert sqrt5.unify(sqrt5.frac_field(x, y)) == sqrt5.frac_field(x, y)
290
+ assert sqrt5.frac_field(x, y).unify(sqrt5) == sqrt5.frac_field(x, y)
291
+
292
+ assert sqrt5.unify(sqrt7[x, y]) == sqrt57[x, y]
293
+ assert sqrt5[x, y].unify(sqrt7) == sqrt57[x, y]
294
+
295
+ assert sqrt5.unify(sqrt7.frac_field(x, y)) == sqrt57.frac_field(x, y)
296
+ assert sqrt5.frac_field(x, y).unify(sqrt7) == sqrt57.frac_field(x, y)
297
+
298
+ def test_Domain_unify_FiniteExtension():
299
+ KxZZ = FiniteExtension(Poly(x**2 - 2, x, domain=ZZ))
300
+ KxQQ = FiniteExtension(Poly(x**2 - 2, x, domain=QQ))
301
+ KxZZy = FiniteExtension(Poly(x**2 - 2, x, domain=ZZ[y]))
302
+ KxQQy = FiniteExtension(Poly(x**2 - 2, x, domain=QQ[y]))
303
+
304
+ assert KxZZ.unify(KxZZ) == KxZZ
305
+ assert KxQQ.unify(KxQQ) == KxQQ
306
+ assert KxZZy.unify(KxZZy) == KxZZy
307
+ assert KxQQy.unify(KxQQy) == KxQQy
308
+
309
+ assert KxZZ.unify(ZZ) == KxZZ
310
+ assert KxZZ.unify(QQ) == KxQQ
311
+ assert KxQQ.unify(ZZ) == KxQQ
312
+ assert KxQQ.unify(QQ) == KxQQ
313
+
314
+ assert KxZZ.unify(ZZ[y]) == KxZZy
315
+ assert KxZZ.unify(QQ[y]) == KxQQy
316
+ assert KxQQ.unify(ZZ[y]) == KxQQy
317
+ assert KxQQ.unify(QQ[y]) == KxQQy
318
+
319
+ assert KxZZy.unify(ZZ) == KxZZy
320
+ assert KxZZy.unify(QQ) == KxQQy
321
+ assert KxQQy.unify(ZZ) == KxQQy
322
+ assert KxQQy.unify(QQ) == KxQQy
323
+
324
+ assert KxZZy.unify(ZZ[y]) == KxZZy
325
+ assert KxZZy.unify(QQ[y]) == KxQQy
326
+ assert KxQQy.unify(ZZ[y]) == KxQQy
327
+ assert KxQQy.unify(QQ[y]) == KxQQy
328
+
329
+ K = FiniteExtension(Poly(x**2 - 2, x, domain=ZZ[y]))
330
+ assert K.unify(ZZ) == K
331
+ assert K.unify(ZZ[x]) == K
332
+ assert K.unify(ZZ[y]) == K
333
+ assert K.unify(ZZ[x, y]) == K
334
+
335
+ Kz = FiniteExtension(Poly(x**2 - 2, x, domain=ZZ[y, z]))
336
+ assert K.unify(ZZ[z]) == Kz
337
+ assert K.unify(ZZ[x, z]) == Kz
338
+ assert K.unify(ZZ[y, z]) == Kz
339
+ assert K.unify(ZZ[x, y, z]) == Kz
340
+
341
+ Kx = FiniteExtension(Poly(x**2 - 2, x, domain=ZZ))
342
+ Ky = FiniteExtension(Poly(y**2 - 2, y, domain=ZZ))
343
+ Kxy = FiniteExtension(Poly(y**2 - 2, y, domain=Kx))
344
+ assert Kx.unify(Kx) == Kx
345
+ assert Ky.unify(Ky) == Ky
346
+ assert Kx.unify(Ky) == Kxy
347
+ assert Ky.unify(Kx) == Kxy
348
+
349
+ def test_Domain_unify_with_symbols():
350
+ raises(UnificationFailed, lambda: ZZ[x, y].unify_with_symbols(ZZ, (y, z)))
351
+ raises(UnificationFailed, lambda: ZZ.unify_with_symbols(ZZ[x, y], (y, z)))
352
+
353
+ def test_Domain__contains__():
354
+ assert (0 in EX) is True
355
+ assert (0 in ZZ) is True
356
+ assert (0 in QQ) is True
357
+ assert (0 in RR) is True
358
+ assert (0 in CC) is True
359
+ assert (0 in ALG) is True
360
+ assert (0 in ZZ[x, y]) is True
361
+ assert (0 in QQ[x, y]) is True
362
+ assert (0 in RR[x, y]) is True
363
+
364
+ assert (-7 in EX) is True
365
+ assert (-7 in ZZ) is True
366
+ assert (-7 in QQ) is True
367
+ assert (-7 in RR) is True
368
+ assert (-7 in CC) is True
369
+ assert (-7 in ALG) is True
370
+ assert (-7 in ZZ[x, y]) is True
371
+ assert (-7 in QQ[x, y]) is True
372
+ assert (-7 in RR[x, y]) is True
373
+
374
+ assert (17 in EX) is True
375
+ assert (17 in ZZ) is True
376
+ assert (17 in QQ) is True
377
+ assert (17 in RR) is True
378
+ assert (17 in CC) is True
379
+ assert (17 in ALG) is True
380
+ assert (17 in ZZ[x, y]) is True
381
+ assert (17 in QQ[x, y]) is True
382
+ assert (17 in RR[x, y]) is True
383
+
384
+ assert (Rational(-1, 7) in EX) is True
385
+ assert (Rational(-1, 7) in ZZ) is False
386
+ assert (Rational(-1, 7) in QQ) is True
387
+ assert (Rational(-1, 7) in RR) is True
388
+ assert (Rational(-1, 7) in CC) is True
389
+ assert (Rational(-1, 7) in ALG) is True
390
+ assert (Rational(-1, 7) in ZZ[x, y]) is False
391
+ assert (Rational(-1, 7) in QQ[x, y]) is True
392
+ assert (Rational(-1, 7) in RR[x, y]) is True
393
+
394
+ assert (Rational(3, 5) in EX) is True
395
+ assert (Rational(3, 5) in ZZ) is False
396
+ assert (Rational(3, 5) in QQ) is True
397
+ assert (Rational(3, 5) in RR) is True
398
+ assert (Rational(3, 5) in CC) is True
399
+ assert (Rational(3, 5) in ALG) is True
400
+ assert (Rational(3, 5) in ZZ[x, y]) is False
401
+ assert (Rational(3, 5) in QQ[x, y]) is True
402
+ assert (Rational(3, 5) in RR[x, y]) is True
403
+
404
+ assert (3.0 in EX) is True
405
+ assert (3.0 in ZZ) is True
406
+ assert (3.0 in QQ) is True
407
+ assert (3.0 in RR) is True
408
+ assert (3.0 in CC) is True
409
+ assert (3.0 in ALG) is True
410
+ assert (3.0 in ZZ[x, y]) is True
411
+ assert (3.0 in QQ[x, y]) is True
412
+ assert (3.0 in RR[x, y]) is True
413
+
414
+ assert (3.14 in EX) is True
415
+ assert (3.14 in ZZ) is False
416
+ assert (3.14 in QQ) is True
417
+ assert (3.14 in RR) is True
418
+ assert (3.14 in CC) is True
419
+ assert (3.14 in ALG) is True
420
+ assert (3.14 in ZZ[x, y]) is False
421
+ assert (3.14 in QQ[x, y]) is True
422
+ assert (3.14 in RR[x, y]) is True
423
+
424
+ assert (oo in ALG) is False
425
+ assert (oo in ZZ[x, y]) is False
426
+ assert (oo in QQ[x, y]) is False
427
+
428
+ assert (-oo in ZZ) is False
429
+ assert (-oo in QQ) is False
430
+ assert (-oo in ALG) is False
431
+ assert (-oo in ZZ[x, y]) is False
432
+ assert (-oo in QQ[x, y]) is False
433
+
434
+ assert (sqrt(7) in EX) is True
435
+ assert (sqrt(7) in ZZ) is False
436
+ assert (sqrt(7) in QQ) is False
437
+ assert (sqrt(7) in RR) is True
438
+ assert (sqrt(7) in CC) is True
439
+ assert (sqrt(7) in ALG) is False
440
+ assert (sqrt(7) in ZZ[x, y]) is False
441
+ assert (sqrt(7) in QQ[x, y]) is False
442
+ assert (sqrt(7) in RR[x, y]) is True
443
+
444
+ assert (2*sqrt(3) + 1 in EX) is True
445
+ assert (2*sqrt(3) + 1 in ZZ) is False
446
+ assert (2*sqrt(3) + 1 in QQ) is False
447
+ assert (2*sqrt(3) + 1 in RR) is True
448
+ assert (2*sqrt(3) + 1 in CC) is True
449
+ assert (2*sqrt(3) + 1 in ALG) is True
450
+ assert (2*sqrt(3) + 1 in ZZ[x, y]) is False
451
+ assert (2*sqrt(3) + 1 in QQ[x, y]) is False
452
+ assert (2*sqrt(3) + 1 in RR[x, y]) is True
453
+
454
+ assert (sin(1) in EX) is True
455
+ assert (sin(1) in ZZ) is False
456
+ assert (sin(1) in QQ) is False
457
+ assert (sin(1) in RR) is True
458
+ assert (sin(1) in CC) is True
459
+ assert (sin(1) in ALG) is False
460
+ assert (sin(1) in ZZ[x, y]) is False
461
+ assert (sin(1) in QQ[x, y]) is False
462
+ assert (sin(1) in RR[x, y]) is True
463
+
464
+ assert (x**2 + 1 in EX) is True
465
+ assert (x**2 + 1 in ZZ) is False
466
+ assert (x**2 + 1 in QQ) is False
467
+ assert (x**2 + 1 in RR) is False
468
+ assert (x**2 + 1 in CC) is False
469
+ assert (x**2 + 1 in ALG) is False
470
+ assert (x**2 + 1 in ZZ[x]) is True
471
+ assert (x**2 + 1 in QQ[x]) is True
472
+ assert (x**2 + 1 in RR[x]) is True
473
+ assert (x**2 + 1 in ZZ[x, y]) is True
474
+ assert (x**2 + 1 in QQ[x, y]) is True
475
+ assert (x**2 + 1 in RR[x, y]) is True
476
+
477
+ assert (x**2 + y**2 in EX) is True
478
+ assert (x**2 + y**2 in ZZ) is False
479
+ assert (x**2 + y**2 in QQ) is False
480
+ assert (x**2 + y**2 in RR) is False
481
+ assert (x**2 + y**2 in CC) is False
482
+ assert (x**2 + y**2 in ALG) is False
483
+ assert (x**2 + y**2 in ZZ[x]) is False
484
+ assert (x**2 + y**2 in QQ[x]) is False
485
+ assert (x**2 + y**2 in RR[x]) is False
486
+ assert (x**2 + y**2 in ZZ[x, y]) is True
487
+ assert (x**2 + y**2 in QQ[x, y]) is True
488
+ assert (x**2 + y**2 in RR[x, y]) is True
489
+
490
+ assert (Rational(3, 2)*x/(y + 1) - z in QQ[x, y, z]) is False
491
+
492
+
493
+ def test_issue_14433():
494
+ assert (Rational(2, 3)*x in QQ.frac_field(1/x)) is True
495
+ assert (1/x in QQ.frac_field(x)) is True
496
+ assert ((x**2 + y**2) in QQ.frac_field(1/x, 1/y)) is True
497
+ assert ((x + y) in QQ.frac_field(1/x, y)) is True
498
+ assert ((x - y) in QQ.frac_field(x, 1/y)) is True
499
+
500
+
501
+ def test_Domain_get_ring():
502
+ assert ZZ.has_assoc_Ring is True
503
+ assert QQ.has_assoc_Ring is True
504
+ assert ZZ[x].has_assoc_Ring is True
505
+ assert QQ[x].has_assoc_Ring is True
506
+ assert ZZ[x, y].has_assoc_Ring is True
507
+ assert QQ[x, y].has_assoc_Ring is True
508
+ assert ZZ.frac_field(x).has_assoc_Ring is True
509
+ assert QQ.frac_field(x).has_assoc_Ring is True
510
+ assert ZZ.frac_field(x, y).has_assoc_Ring is True
511
+ assert QQ.frac_field(x, y).has_assoc_Ring is True
512
+
513
+ assert EX.has_assoc_Ring is False
514
+ assert RR.has_assoc_Ring is False
515
+ assert ALG.has_assoc_Ring is False
516
+
517
+ assert ZZ.get_ring() == ZZ
518
+ assert QQ.get_ring() == ZZ
519
+ assert ZZ[x].get_ring() == ZZ[x]
520
+ assert QQ[x].get_ring() == QQ[x]
521
+ assert ZZ[x, y].get_ring() == ZZ[x, y]
522
+ assert QQ[x, y].get_ring() == QQ[x, y]
523
+ assert ZZ.frac_field(x).get_ring() == ZZ[x]
524
+ assert QQ.frac_field(x).get_ring() == QQ[x]
525
+ assert ZZ.frac_field(x, y).get_ring() == ZZ[x, y]
526
+ assert QQ.frac_field(x, y).get_ring() == QQ[x, y]
527
+
528
+ assert EX.get_ring() == EX
529
+
530
+ assert RR.get_ring() == RR
531
+ # XXX: This should also be like RR
532
+ raises(DomainError, lambda: ALG.get_ring())
533
+
534
+
535
+ def test_Domain_get_field():
536
+ assert EX.has_assoc_Field is True
537
+ assert ZZ.has_assoc_Field is True
538
+ assert QQ.has_assoc_Field is True
539
+ assert RR.has_assoc_Field is True
540
+ assert ALG.has_assoc_Field is True
541
+ assert ZZ[x].has_assoc_Field is True
542
+ assert QQ[x].has_assoc_Field is True
543
+ assert ZZ[x, y].has_assoc_Field is True
544
+ assert QQ[x, y].has_assoc_Field is True
545
+
546
+ assert EX.get_field() == EX
547
+ assert ZZ.get_field() == QQ
548
+ assert QQ.get_field() == QQ
549
+ assert RR.get_field() == RR
550
+ assert ALG.get_field() == ALG
551
+ assert ZZ[x].get_field() == ZZ.frac_field(x)
552
+ assert QQ[x].get_field() == QQ.frac_field(x)
553
+ assert ZZ[x, y].get_field() == ZZ.frac_field(x, y)
554
+ assert QQ[x, y].get_field() == QQ.frac_field(x, y)
555
+
556
+
557
+ def test_Domain_get_exact():
558
+ assert EX.get_exact() == EX
559
+ assert ZZ.get_exact() == ZZ
560
+ assert QQ.get_exact() == QQ
561
+ assert RR.get_exact() == QQ
562
+ assert ALG.get_exact() == ALG
563
+ assert ZZ[x].get_exact() == ZZ[x]
564
+ assert QQ[x].get_exact() == QQ[x]
565
+ assert ZZ[x, y].get_exact() == ZZ[x, y]
566
+ assert QQ[x, y].get_exact() == QQ[x, y]
567
+ assert ZZ.frac_field(x).get_exact() == ZZ.frac_field(x)
568
+ assert QQ.frac_field(x).get_exact() == QQ.frac_field(x)
569
+ assert ZZ.frac_field(x, y).get_exact() == ZZ.frac_field(x, y)
570
+ assert QQ.frac_field(x, y).get_exact() == QQ.frac_field(x, y)
571
+
572
+
573
+ def test_Domain_is_unit():
574
+ nums = [-2, -1, 0, 1, 2]
575
+ invring = [False, True, False, True, False]
576
+ invfield = [True, True, False, True, True]
577
+ ZZx, QQx, QQxf = ZZ[x], QQ[x], QQ.frac_field(x)
578
+ assert [ZZ.is_unit(ZZ(n)) for n in nums] == invring
579
+ assert [QQ.is_unit(QQ(n)) for n in nums] == invfield
580
+ assert [ZZx.is_unit(ZZx(n)) for n in nums] == invring
581
+ assert [QQx.is_unit(QQx(n)) for n in nums] == invfield
582
+ assert [QQxf.is_unit(QQxf(n)) for n in nums] == invfield
583
+ assert ZZx.is_unit(ZZx(x)) is False
584
+ assert QQx.is_unit(QQx(x)) is False
585
+ assert QQxf.is_unit(QQxf(x)) is True
586
+
587
+
588
+ def test_Domain_convert():
589
+
590
+ def check_element(e1, e2, K1, K2, K3):
591
+ assert type(e1) is type(e2), '%s, %s: %s %s -> %s' % (e1, e2, K1, K2, K3)
592
+ assert e1 == e2, '%s, %s: %s %s -> %s' % (e1, e2, K1, K2, K3)
593
+
594
+ def check_domains(K1, K2):
595
+ K3 = K1.unify(K2)
596
+ check_element(K3.convert_from( K1.one, K1), K3.one, K1, K2, K3)
597
+ check_element(K3.convert_from( K2.one, K2), K3.one, K1, K2, K3)
598
+ check_element(K3.convert_from(K1.zero, K1), K3.zero, K1, K2, K3)
599
+ check_element(K3.convert_from(K2.zero, K2), K3.zero, K1, K2, K3)
600
+
601
+ def composite_domains(K):
602
+ domains = [
603
+ K,
604
+ K[y], K[z], K[y, z],
605
+ K.frac_field(y), K.frac_field(z), K.frac_field(y, z),
606
+ # XXX: These should be tested and made to work...
607
+ # K.old_poly_ring(y), K.old_frac_field(y),
608
+ ]
609
+ return domains
610
+
611
+ QQ2 = QQ.algebraic_field(sqrt(2))
612
+ QQ3 = QQ.algebraic_field(sqrt(3))
613
+ doms = [ZZ, QQ, QQ2, QQ3, QQ_I, ZZ_I, RR, CC]
614
+
615
+ for i, K1 in enumerate(doms):
616
+ for K2 in doms[i:]:
617
+ for K3 in composite_domains(K1):
618
+ for K4 in composite_domains(K2):
619
+ check_domains(K3, K4)
620
+
621
+ assert QQ.convert(10e-52) == QQ(1684996666696915, 1684996666696914987166688442938726917102321526408785780068975640576)
622
+
623
+ R, xr = ring("x", ZZ)
624
+ assert ZZ.convert(xr - xr) == 0
625
+ assert ZZ.convert(xr - xr, R.to_domain()) == 0
626
+
627
+ assert CC.convert(ZZ_I(1, 2)) == CC(1, 2)
628
+ assert CC.convert(QQ_I(1, 2)) == CC(1, 2)
629
+
630
+ K1 = QQ.frac_field(x)
631
+ K2 = ZZ.frac_field(x)
632
+ K3 = QQ[x]
633
+ K4 = ZZ[x]
634
+ Ks = [K1, K2, K3, K4]
635
+ for Ka, Kb in product(Ks, Ks):
636
+ assert Ka.convert_from(Kb.from_sympy(x), Kb) == Ka.from_sympy(x)
637
+
638
+ assert K2.convert_from(QQ(1, 2), QQ) == K2(QQ(1, 2))
639
+
640
+
641
+ def test_GlobalPolynomialRing_convert():
642
+ K1 = QQ.old_poly_ring(x)
643
+ K2 = QQ[x]
644
+ assert K1.convert(x) == K1.convert(K2.convert(x), K2)
645
+ assert K2.convert(x) == K2.convert(K1.convert(x), K1)
646
+
647
+ K1 = QQ.old_poly_ring(x, y)
648
+ K2 = QQ[x]
649
+ assert K1.convert(x) == K1.convert(K2.convert(x), K2)
650
+ #assert K2.convert(x) == K2.convert(K1.convert(x), K1)
651
+
652
+ K1 = ZZ.old_poly_ring(x, y)
653
+ K2 = QQ[x]
654
+ assert K1.convert(x) == K1.convert(K2.convert(x), K2)
655
+ #assert K2.convert(x) == K2.convert(K1.convert(x), K1)
656
+
657
+
658
+ def test_PolynomialRing__init():
659
+ R, = ring("", ZZ)
660
+ assert ZZ.poly_ring() == R.to_domain()
661
+
662
+
663
+ def test_FractionField__init():
664
+ F, = field("", ZZ)
665
+ assert ZZ.frac_field() == F.to_domain()
666
+
667
+
668
+ def test_FractionField_convert():
669
+ K = QQ.frac_field(x)
670
+ assert K.convert(QQ(2, 3), QQ) == K.from_sympy(Rational(2, 3))
671
+ K = QQ.frac_field(x)
672
+ assert K.convert(ZZ(2), ZZ) == K.from_sympy(Integer(2))
673
+
674
+
675
+ def test_inject():
676
+ assert ZZ.inject(x, y, z) == ZZ[x, y, z]
677
+ assert ZZ[x].inject(y, z) == ZZ[x, y, z]
678
+ assert ZZ.frac_field(x).inject(y, z) == ZZ.frac_field(x, y, z)
679
+ raises(GeneratorsError, lambda: ZZ[x].inject(x))
680
+
681
+
682
+ def test_drop():
683
+ assert ZZ.drop(x) == ZZ
684
+ assert ZZ[x].drop(x) == ZZ
685
+ assert ZZ[x, y].drop(x) == ZZ[y]
686
+ assert ZZ.frac_field(x).drop(x) == ZZ
687
+ assert ZZ.frac_field(x, y).drop(x) == ZZ.frac_field(y)
688
+ assert ZZ[x][y].drop(y) == ZZ[x]
689
+ assert ZZ[x][y].drop(x) == ZZ[y]
690
+ assert ZZ.frac_field(x)[y].drop(x) == ZZ[y]
691
+ assert ZZ.frac_field(x)[y].drop(y) == ZZ.frac_field(x)
692
+ Ky = FiniteExtension(Poly(x**2-1, x, domain=ZZ[y]))
693
+ K = FiniteExtension(Poly(x**2-1, x, domain=ZZ))
694
+ assert Ky.drop(y) == K
695
+ raises(GeneratorsError, lambda: Ky.drop(x))
696
+
697
+
698
+ def test_Domain_map():
699
+ seq = ZZ.map([1, 2, 3, 4])
700
+
701
+ assert all(ZZ.of_type(elt) for elt in seq)
702
+
703
+ seq = ZZ.map([[1, 2, 3, 4]])
704
+
705
+ assert all(ZZ.of_type(elt) for elt in seq[0]) and len(seq) == 1
706
+
707
+
708
+ def test_Domain___eq__():
709
+ assert (ZZ[x, y] == ZZ[x, y]) is True
710
+ assert (QQ[x, y] == QQ[x, y]) is True
711
+
712
+ assert (ZZ[x, y] == QQ[x, y]) is False
713
+ assert (QQ[x, y] == ZZ[x, y]) is False
714
+
715
+ assert (ZZ.frac_field(x, y) == ZZ.frac_field(x, y)) is True
716
+ assert (QQ.frac_field(x, y) == QQ.frac_field(x, y)) is True
717
+
718
+ assert (ZZ.frac_field(x, y) == QQ.frac_field(x, y)) is False
719
+ assert (QQ.frac_field(x, y) == ZZ.frac_field(x, y)) is False
720
+
721
+ assert RealField()[x] == RR[x]
722
+
723
+
724
+ def test_Domain__algebraic_field():
725
+ alg = ZZ.algebraic_field(sqrt(2))
726
+ assert alg.ext.minpoly == Poly(x**2 - 2)
727
+ assert alg.dom == QQ
728
+
729
+ alg = QQ.algebraic_field(sqrt(2))
730
+ assert alg.ext.minpoly == Poly(x**2 - 2)
731
+ assert alg.dom == QQ
732
+
733
+ alg = alg.algebraic_field(sqrt(3))
734
+ assert alg.ext.minpoly == Poly(x**4 - 10*x**2 + 1)
735
+ assert alg.dom == QQ
736
+
737
+
738
+ def test_Domain_alg_field_from_poly():
739
+ f = Poly(x**2 - 2)
740
+ g = Poly(x**2 - 3)
741
+ h = Poly(x**4 - 10*x**2 + 1)
742
+
743
+ alg = ZZ.alg_field_from_poly(f)
744
+ assert alg.ext.minpoly == f
745
+ assert alg.dom == QQ
746
+
747
+ alg = QQ.alg_field_from_poly(f)
748
+ assert alg.ext.minpoly == f
749
+ assert alg.dom == QQ
750
+
751
+ alg = alg.alg_field_from_poly(g)
752
+ assert alg.ext.minpoly == h
753
+ assert alg.dom == QQ
754
+
755
+
756
+ def test_Domain_cyclotomic_field():
757
+ K = ZZ.cyclotomic_field(12)
758
+ assert K.ext.minpoly == Poly(cyclotomic_poly(12))
759
+ assert K.dom == QQ
760
+
761
+ F = QQ.cyclotomic_field(3)
762
+ assert F.ext.minpoly == Poly(cyclotomic_poly(3))
763
+ assert F.dom == QQ
764
+
765
+ E = F.cyclotomic_field(4)
766
+ assert field_isomorphism(E.ext, K.ext) is not None
767
+ assert E.dom == QQ
768
+
769
+
770
+ def test_PolynomialRing_from_FractionField():
771
+ F, x,y = field("x,y", ZZ)
772
+ R, X,Y = ring("x,y", ZZ)
773
+
774
+ f = (x**2 + y**2)/(x + 1)
775
+ g = (x**2 + y**2)/4
776
+ h = x**2 + y**2
777
+
778
+ assert R.to_domain().from_FractionField(f, F.to_domain()) is None
779
+ assert R.to_domain().from_FractionField(g, F.to_domain()) == X**2/4 + Y**2/4
780
+ assert R.to_domain().from_FractionField(h, F.to_domain()) == X**2 + Y**2
781
+
782
+ F, x,y = field("x,y", QQ)
783
+ R, X,Y = ring("x,y", QQ)
784
+
785
+ f = (x**2 + y**2)/(x + 1)
786
+ g = (x**2 + y**2)/4
787
+ h = x**2 + y**2
788
+
789
+ assert R.to_domain().from_FractionField(f, F.to_domain()) is None
790
+ assert R.to_domain().from_FractionField(g, F.to_domain()) == X**2/4 + Y**2/4
791
+ assert R.to_domain().from_FractionField(h, F.to_domain()) == X**2 + Y**2
792
+
793
+ def test_FractionField_from_PolynomialRing():
794
+ R, x,y = ring("x,y", QQ)
795
+ F, X,Y = field("x,y", ZZ)
796
+
797
+ f = 3*x**2 + 5*y**2
798
+ g = x**2/3 + y**2/5
799
+
800
+ assert F.to_domain().from_PolynomialRing(f, R.to_domain()) == 3*X**2 + 5*Y**2
801
+ assert F.to_domain().from_PolynomialRing(g, R.to_domain()) == (5*X**2 + 3*Y**2)/15
802
+
803
+ def test_FF_of_type():
804
+ assert FF(3).of_type(FF(3)(1)) is True
805
+ assert FF(5).of_type(FF(5)(3)) is True
806
+ assert FF(5).of_type(FF(7)(3)) is False
807
+
808
+
809
+ def test___eq__():
810
+ assert not QQ[x] == ZZ[x]
811
+ assert not QQ.frac_field(x) == ZZ.frac_field(x)
812
+
813
+
814
+ def test_RealField_from_sympy():
815
+ assert RR.convert(S.Zero) == RR.dtype(0)
816
+ assert RR.convert(S(0.0)) == RR.dtype(0.0)
817
+ assert RR.convert(S.One) == RR.dtype(1)
818
+ assert RR.convert(S(1.0)) == RR.dtype(1.0)
819
+ assert RR.convert(sin(1)) == RR.dtype(sin(1).evalf())
820
+
821
+
822
+ def test_not_in_any_domain():
823
+ check = list(_illegal) + [x] + [
824
+ float(i) for i in _illegal[:3]]
825
+ for dom in (ZZ, QQ, RR, CC, EX):
826
+ for i in check:
827
+ if i == x and dom == EX:
828
+ continue
829
+ assert i not in dom, (i, dom)
830
+ raises(CoercionFailed, lambda: dom.convert(i))
831
+
832
+
833
+ def test_ModularInteger():
834
+ F3 = FF(3)
835
+
836
+ a = F3(0)
837
+ assert isinstance(a, F3.dtype) and a == 0
838
+ a = F3(1)
839
+ assert isinstance(a, F3.dtype) and a == 1
840
+ a = F3(2)
841
+ assert isinstance(a, F3.dtype) and a == 2
842
+ a = F3(3)
843
+ assert isinstance(a, F3.dtype) and a == 0
844
+ a = F3(4)
845
+ assert isinstance(a, F3.dtype) and a == 1
846
+
847
+ a = F3(F3(0))
848
+ assert isinstance(a, F3.dtype) and a == 0
849
+ a = F3(F3(1))
850
+ assert isinstance(a, F3.dtype) and a == 1
851
+ a = F3(F3(2))
852
+ assert isinstance(a, F3.dtype) and a == 2
853
+ a = F3(F3(3))
854
+ assert isinstance(a, F3.dtype) and a == 0
855
+ a = F3(F3(4))
856
+ assert isinstance(a, F3.dtype) and a == 1
857
+
858
+ a = -F3(1)
859
+ assert isinstance(a, F3.dtype) and a == 2
860
+ a = -F3(2)
861
+ assert isinstance(a, F3.dtype) and a == 1
862
+
863
+ a = 2 + F3(2)
864
+ assert isinstance(a, F3.dtype) and a == 1
865
+ a = F3(2) + 2
866
+ assert isinstance(a, F3.dtype) and a == 1
867
+ a = F3(2) + F3(2)
868
+ assert isinstance(a, F3.dtype) and a == 1
869
+ a = F3(2) + F3(2)
870
+ assert isinstance(a, F3.dtype) and a == 1
871
+
872
+ a = 3 - F3(2)
873
+ assert isinstance(a, F3.dtype) and a == 1
874
+ a = F3(3) - 2
875
+ assert isinstance(a, F3.dtype) and a == 1
876
+ a = F3(3) - F3(2)
877
+ assert isinstance(a, F3.dtype) and a == 1
878
+ a = F3(3) - F3(2)
879
+ assert isinstance(a, F3.dtype) and a == 1
880
+
881
+ a = 2*F3(2)
882
+ assert isinstance(a, F3.dtype) and a == 1
883
+ a = F3(2)*2
884
+ assert isinstance(a, F3.dtype) and a == 1
885
+ a = F3(2)*F3(2)
886
+ assert isinstance(a, F3.dtype) and a == 1
887
+ a = F3(2)*F3(2)
888
+ assert isinstance(a, F3.dtype) and a == 1
889
+
890
+ a = 2/F3(2)
891
+ assert isinstance(a, F3.dtype) and a == 1
892
+ a = F3(2)/2
893
+ assert isinstance(a, F3.dtype) and a == 1
894
+ a = F3(2)/F3(2)
895
+ assert isinstance(a, F3.dtype) and a == 1
896
+ a = F3(2)/F3(2)
897
+ assert isinstance(a, F3.dtype) and a == 1
898
+
899
+ a = 1 % F3(2)
900
+ assert isinstance(a, F3.dtype) and a == 1
901
+ a = F3(1) % 2
902
+ assert isinstance(a, F3.dtype) and a == 1
903
+ a = F3(1) % F3(2)
904
+ assert isinstance(a, F3.dtype) and a == 1
905
+ a = F3(1) % F3(2)
906
+ assert isinstance(a, F3.dtype) and a == 1
907
+
908
+ a = F3(2)**0
909
+ assert isinstance(a, F3.dtype) and a == 1
910
+ a = F3(2)**1
911
+ assert isinstance(a, F3.dtype) and a == 2
912
+ a = F3(2)**2
913
+ assert isinstance(a, F3.dtype) and a == 1
914
+
915
+ F7 = FF(7)
916
+
917
+ a = F7(3)**100000000000
918
+ assert isinstance(a, F7.dtype) and a == 4
919
+ a = F7(3)**-100000000000
920
+ assert isinstance(a, F7.dtype) and a == 2
921
+ a = F7(3)**S(2)
922
+ assert isinstance(a, F7.dtype) and a == 2
923
+
924
+ assert bool(F3(3)) is False
925
+ assert bool(F3(4)) is True
926
+
927
+ F5 = FF(5)
928
+
929
+ a = F5(1)**(-1)
930
+ assert isinstance(a, F5.dtype) and a == 1
931
+ a = F5(2)**(-1)
932
+ assert isinstance(a, F5.dtype) and a == 3
933
+ a = F5(3)**(-1)
934
+ assert isinstance(a, F5.dtype) and a == 2
935
+ a = F5(4)**(-1)
936
+ assert isinstance(a, F5.dtype) and a == 4
937
+
938
+ assert (F5(1) < F5(2)) is True
939
+ assert (F5(1) <= F5(2)) is True
940
+ assert (F5(1) > F5(2)) is False
941
+ assert (F5(1) >= F5(2)) is False
942
+
943
+ assert (F5(3) < F5(2)) is False
944
+ assert (F5(3) <= F5(2)) is False
945
+ assert (F5(3) > F5(2)) is True
946
+ assert (F5(3) >= F5(2)) is True
947
+
948
+ assert (F5(1) < F5(7)) is True
949
+ assert (F5(1) <= F5(7)) is True
950
+ assert (F5(1) > F5(7)) is False
951
+ assert (F5(1) >= F5(7)) is False
952
+
953
+ assert (F5(3) < F5(7)) is False
954
+ assert (F5(3) <= F5(7)) is False
955
+ assert (F5(3) > F5(7)) is True
956
+ assert (F5(3) >= F5(7)) is True
957
+
958
+ assert (F5(1) < 2) is True
959
+ assert (F5(1) <= 2) is True
960
+ assert (F5(1) > 2) is False
961
+ assert (F5(1) >= 2) is False
962
+
963
+ assert (F5(3) < 2) is False
964
+ assert (F5(3) <= 2) is False
965
+ assert (F5(3) > 2) is True
966
+ assert (F5(3) >= 2) is True
967
+
968
+ assert (F5(1) < 7) is True
969
+ assert (F5(1) <= 7) is True
970
+ assert (F5(1) > 7) is False
971
+ assert (F5(1) >= 7) is False
972
+
973
+ assert (F5(3) < 7) is False
974
+ assert (F5(3) <= 7) is False
975
+ assert (F5(3) > 7) is True
976
+ assert (F5(3) >= 7) is True
977
+
978
+ raises(NotInvertible, lambda: F5(0)**(-1))
979
+ raises(NotInvertible, lambda: F5(5)**(-1))
980
+
981
+ raises(ValueError, lambda: FF(0))
982
+ raises(ValueError, lambda: FF(2.1))
983
+
984
+ def test_QQ_int():
985
+ assert int(QQ(2**2000, 3**1250)) == 455431
986
+ assert int(QQ(2**100, 3)) == 422550200076076467165567735125
987
+
988
+ def test_RR_double():
989
+ assert RR(3.14) > 1e-50
990
+ assert RR(1e-13) > 1e-50
991
+ assert RR(1e-14) > 1e-50
992
+ assert RR(1e-15) > 1e-50
993
+ assert RR(1e-20) > 1e-50
994
+ assert RR(1e-40) > 1e-50
995
+
996
+ def test_RR_Float():
997
+ f1 = Float("1.01")
998
+ f2 = Float("1.0000000000000000000001")
999
+ assert f1._prec == 53
1000
+ assert f2._prec == 80
1001
+ assert RR(f1)-1 > 1e-50
1002
+ assert RR(f2)-1 < 1e-50 # RR's precision is lower than f2's
1003
+
1004
+ RR2 = RealField(prec=f2._prec)
1005
+ assert RR2(f1)-1 > 1e-50
1006
+ assert RR2(f2)-1 > 1e-50 # RR's precision is equal to f2's
1007
+
1008
+
1009
+ def test_CC_double():
1010
+ assert CC(3.14).real > 1e-50
1011
+ assert CC(1e-13).real > 1e-50
1012
+ assert CC(1e-14).real > 1e-50
1013
+ assert CC(1e-15).real > 1e-50
1014
+ assert CC(1e-20).real > 1e-50
1015
+ assert CC(1e-40).real > 1e-50
1016
+
1017
+ assert CC(3.14j).imag > 1e-50
1018
+ assert CC(1e-13j).imag > 1e-50
1019
+ assert CC(1e-14j).imag > 1e-50
1020
+ assert CC(1e-15j).imag > 1e-50
1021
+ assert CC(1e-20j).imag > 1e-50
1022
+ assert CC(1e-40j).imag > 1e-50
1023
+
1024
+
1025
+ def test_gaussian_domains():
1026
+ I = S.ImaginaryUnit
1027
+ a, b, c, d = [ZZ_I.convert(x) for x in (5, 2 + I, 3 - I, 5 - 5*I)]
1028
+ assert ZZ_I.gcd(a, b) == b
1029
+ assert ZZ_I.gcd(a, c) == b
1030
+ assert ZZ_I.lcm(a, b) == a
1031
+ assert ZZ_I.lcm(a, c) == d
1032
+ assert ZZ_I(3, 4) != QQ_I(3, 4) # XXX is this right or should QQ->ZZ if possible?
1033
+ assert ZZ_I(3, 0) != 3 # and should this go to Integer?
1034
+ assert QQ_I(S(3)/4, 0) != S(3)/4 # and this to Rational?
1035
+ assert ZZ_I(0, 0).quadrant() == 0
1036
+ assert ZZ_I(-1, 0).quadrant() == 2
1037
+
1038
+ assert QQ_I.convert(QQ(3, 2)) == QQ_I(QQ(3, 2), QQ(0))
1039
+ assert QQ_I.convert(QQ(3, 2), QQ) == QQ_I(QQ(3, 2), QQ(0))
1040
+
1041
+ for G in (QQ_I, ZZ_I):
1042
+
1043
+ q = G(3, 4)
1044
+ assert str(q) == '3 + 4*I'
1045
+ assert q.parent() == G
1046
+ assert q._get_xy(pi) == (None, None)
1047
+ assert q._get_xy(2) == (2, 0)
1048
+ assert q._get_xy(2*I) == (0, 2)
1049
+
1050
+ assert hash(q) == hash((3, 4))
1051
+ assert G(1, 2) == G(1, 2)
1052
+ assert G(1, 2) != G(1, 3)
1053
+ assert G(3, 0) == G(3)
1054
+
1055
+ assert q + q == G(6, 8)
1056
+ assert q - q == G(0, 0)
1057
+ assert 3 - q == -q + 3 == G(0, -4)
1058
+ assert 3 + q == q + 3 == G(6, 4)
1059
+ assert q * q == G(-7, 24)
1060
+ assert 3 * q == q * 3 == G(9, 12)
1061
+ assert q ** 0 == G(1, 0)
1062
+ assert q ** 1 == q
1063
+ assert q ** 2 == q * q == G(-7, 24)
1064
+ assert q ** 3 == q * q * q == G(-117, 44)
1065
+ assert 1 / q == q ** -1 == QQ_I(S(3)/25, - S(4)/25)
1066
+ assert q / 1 == QQ_I(3, 4)
1067
+ assert q / 2 == QQ_I(S(3)/2, 2)
1068
+ assert q/3 == QQ_I(1, S(4)/3)
1069
+ assert 3/q == QQ_I(S(9)/25, -S(12)/25)
1070
+ i, r = divmod(q, 2)
1071
+ assert 2*i + r == q
1072
+ i, r = divmod(2, q)
1073
+ assert q*i + r == G(2, 0)
1074
+
1075
+ raises(ZeroDivisionError, lambda: q % 0)
1076
+ raises(ZeroDivisionError, lambda: q / 0)
1077
+ raises(ZeroDivisionError, lambda: q // 0)
1078
+ raises(ZeroDivisionError, lambda: divmod(q, 0))
1079
+ raises(ZeroDivisionError, lambda: divmod(q, 0))
1080
+ raises(TypeError, lambda: q + x)
1081
+ raises(TypeError, lambda: q - x)
1082
+ raises(TypeError, lambda: x + q)
1083
+ raises(TypeError, lambda: x - q)
1084
+ raises(TypeError, lambda: q * x)
1085
+ raises(TypeError, lambda: x * q)
1086
+ raises(TypeError, lambda: q / x)
1087
+ raises(TypeError, lambda: x / q)
1088
+ raises(TypeError, lambda: q // x)
1089
+ raises(TypeError, lambda: x // q)
1090
+
1091
+ assert G.from_sympy(S(2)) == G(2, 0)
1092
+ assert G.to_sympy(G(2, 0)) == S(2)
1093
+ raises(CoercionFailed, lambda: G.from_sympy(pi))
1094
+
1095
+ PR = G.inject(x)
1096
+ assert isinstance(PR, PolynomialRing)
1097
+ assert PR.domain == G
1098
+ assert len(PR.gens) == 1 and PR.gens[0].as_expr() == x
1099
+
1100
+ if G is QQ_I:
1101
+ AF = G.as_AlgebraicField()
1102
+ assert isinstance(AF, AlgebraicField)
1103
+ assert AF.domain == QQ
1104
+ assert AF.ext.args[0] == I
1105
+
1106
+ for qi in [G(-1, 0), G(1, 0), G(0, -1), G(0, 1)]:
1107
+ assert G.is_negative(qi) is False
1108
+ assert G.is_positive(qi) is False
1109
+ assert G.is_nonnegative(qi) is False
1110
+ assert G.is_nonpositive(qi) is False
1111
+
1112
+ domains = [ZZ_python(), QQ_python(), AlgebraicField(QQ, I)]
1113
+ if HAS_GMPY:
1114
+ domains += [ZZ_gmpy(), QQ_gmpy()]
1115
+
1116
+ for K in domains:
1117
+ assert G.convert(K(2)) == G(2, 0)
1118
+ assert G.convert(K(2), K) == G(2, 0)
1119
+
1120
+ for K in ZZ_I, QQ_I:
1121
+ assert G.convert(K(1, 1)) == G(1, 1)
1122
+ assert G.convert(K(1, 1), K) == G(1, 1)
1123
+
1124
+ if G == ZZ_I:
1125
+ assert repr(q) == 'ZZ_I(3, 4)'
1126
+ assert q//3 == G(1, 1)
1127
+ assert 12//q == G(1, -2)
1128
+ assert 12 % q == G(1, 2)
1129
+ assert q % 2 == G(-1, 0)
1130
+ assert i == G(0, 0)
1131
+ assert r == G(2, 0)
1132
+ assert G.get_ring() == G
1133
+ assert G.get_field() == QQ_I
1134
+ else:
1135
+ assert repr(q) == 'QQ_I(3, 4)'
1136
+ assert G.get_ring() == ZZ_I
1137
+ assert G.get_field() == G
1138
+ assert q//3 == G(1, S(4)/3)
1139
+ assert 12//q == G(S(36)/25, -S(48)/25)
1140
+ assert 12 % q == G(0, 0)
1141
+ assert q % 2 == G(0, 0)
1142
+ assert i == G(S(6)/25, -S(8)/25), (G,i)
1143
+ assert r == G(0, 0)
1144
+ q2 = G(S(3)/2, S(5)/3)
1145
+ assert G.numer(q2) == ZZ_I(9, 10)
1146
+ assert G.denom(q2) == ZZ_I(6)
1147
+
1148
+
1149
+ def test_EX_EXRAW():
1150
+ assert EXRAW.zero is S.Zero
1151
+ assert EXRAW.one is S.One
1152
+
1153
+ assert EX(1) == EX.Expression(1)
1154
+ assert EX(1).ex is S.One
1155
+ assert EXRAW(1) is S.One
1156
+
1157
+ # EX has cancelling but EXRAW does not
1158
+ assert 2*EX((x + y*x)/x) == EX(2 + 2*y) != 2*((x + y*x)/x)
1159
+ assert 2*EXRAW((x + y*x)/x) == 2*((x + y*x)/x) != (1 + y)
1160
+
1161
+ assert EXRAW.convert_from(EX(1), EX) is EXRAW.one
1162
+ assert EX.convert_from(EXRAW(1), EXRAW) == EX.one
1163
+
1164
+ assert EXRAW.from_sympy(S.One) is S.One
1165
+ assert EXRAW.to_sympy(EXRAW.one) is S.One
1166
+ raises(CoercionFailed, lambda: EXRAW.from_sympy([]))
1167
+
1168
+ assert EXRAW.get_field() == EXRAW
1169
+
1170
+ assert EXRAW.unify(EX) == EXRAW
1171
+ assert EX.unify(EXRAW) == EXRAW
1172
+
1173
+
1174
+ def test_canonical_unit():
1175
+
1176
+ for K in [ZZ, QQ, RR]: # CC?
1177
+ assert K.canonical_unit(K(2)) == K(1)
1178
+ assert K.canonical_unit(K(-2)) == K(-1)
1179
+
1180
+ for K in [ZZ_I, QQ_I]:
1181
+ i = K.from_sympy(I)
1182
+ assert K.canonical_unit(K(2)) == K(1)
1183
+ assert K.canonical_unit(K(2)*i) == -i
1184
+ assert K.canonical_unit(-K(2)) == K(-1)
1185
+ assert K.canonical_unit(-K(2)*i) == i
1186
+
1187
+ K = ZZ[x]
1188
+ assert K.canonical_unit(K(x + 1)) == K(1)
1189
+ assert K.canonical_unit(K(-x + 1)) == K(-1)
1190
+
1191
+ K = ZZ_I[x]
1192
+ assert K.canonical_unit(K.from_sympy(I*x)) == ZZ_I(0, -1)
1193
+
1194
+ K = ZZ_I.frac_field(x, y)
1195
+ i = K.from_sympy(I)
1196
+ assert i / i == K.one
1197
+ assert (K.one + i)/(i - K.one) == -i
1198
+
1199
+
1200
+ def test_issue_18278():
1201
+ assert str(RR(2).parent()) == 'RR'
1202
+ assert str(CC(2).parent()) == 'CC'
1203
+
1204
+
1205
+ def test_Domain_is_negative():
1206
+ I = S.ImaginaryUnit
1207
+ a, b = [CC.convert(x) for x in (2 + I, 5)]
1208
+ assert CC.is_negative(a) == False
1209
+ assert CC.is_negative(b) == False
1210
+
1211
+
1212
+ def test_Domain_is_positive():
1213
+ I = S.ImaginaryUnit
1214
+ a, b = [CC.convert(x) for x in (2 + I, 5)]
1215
+ assert CC.is_positive(a) == False
1216
+ assert CC.is_positive(b) == False
1217
+
1218
+
1219
+ def test_Domain_is_nonnegative():
1220
+ I = S.ImaginaryUnit
1221
+ a, b = [CC.convert(x) for x in (2 + I, 5)]
1222
+ assert CC.is_nonnegative(a) == False
1223
+ assert CC.is_nonnegative(b) == False
1224
+
1225
+
1226
+ def test_Domain_is_nonpositive():
1227
+ I = S.ImaginaryUnit
1228
+ a, b = [CC.convert(x) for x in (2 + I, 5)]
1229
+ assert CC.is_nonpositive(a) == False
1230
+ assert CC.is_nonpositive(b) == False
1231
+
1232
+
1233
+ def test_exponential_domain():
1234
+ K = ZZ[E]
1235
+ eK = K.from_sympy(E)
1236
+ assert K.from_sympy(exp(3)) == eK ** 3
1237
+ assert K.convert(exp(3)) == eK ** 3
1238
+
1239
+
1240
+ def test_AlgebraicField_alias():
1241
+ # No default alias:
1242
+ k = QQ.algebraic_field(sqrt(2))
1243
+ assert k.ext.alias is None
1244
+
1245
+ # For a single extension, its alias is used:
1246
+ alpha = AlgebraicNumber(sqrt(2), alias='alpha')
1247
+ k = QQ.algebraic_field(alpha)
1248
+ assert k.ext.alias.name == 'alpha'
1249
+
1250
+ # Can override the alias of a single extension:
1251
+ k = QQ.algebraic_field(alpha, alias='theta')
1252
+ assert k.ext.alias.name == 'theta'
1253
+
1254
+ # With multiple extensions, no default alias:
1255
+ k = QQ.algebraic_field(sqrt(2), sqrt(3))
1256
+ assert k.ext.alias is None
1257
+
1258
+ # With multiple extensions, no default alias, even if one of
1259
+ # the extensions has one:
1260
+ k = QQ.algebraic_field(alpha, sqrt(3))
1261
+ assert k.ext.alias is None
1262
+
1263
+ # With multiple extensions, may set an alias:
1264
+ k = QQ.algebraic_field(sqrt(2), sqrt(3), alias='theta')
1265
+ assert k.ext.alias.name == 'theta'
1266
+
1267
+ # Alias is passed to constructed field elements:
1268
+ k = QQ.algebraic_field(alpha)
1269
+ beta = k.to_alg_num(k([1, 2, 3]))
1270
+ assert beta.alias is alpha.alias
venv/lib/python3.10/site-packages/sympy/polys/domains/tests/test_quotientring.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tests for quotient rings."""
2
+
3
+ from sympy.polys.domains.integerring import ZZ
4
+ from sympy.polys.domains.rationalfield import QQ
5
+ from sympy.abc import x, y
6
+
7
+ from sympy.polys.polyerrors import NotReversible
8
+
9
+ from sympy.testing.pytest import raises
10
+
11
+
12
+ def test_QuotientRingElement():
13
+ R = QQ.old_poly_ring(x)/[x**10]
14
+ X = R.convert(x)
15
+
16
+ assert X*(X + 1) == R.convert(x**2 + x)
17
+ assert X*x == R.convert(x**2)
18
+ assert x*X == R.convert(x**2)
19
+ assert X + x == R.convert(2*x)
20
+ assert x + X == 2*X
21
+ assert X**2 == R.convert(x**2)
22
+ assert 1/(1 - X) == R.convert(sum(x**i for i in range(10)))
23
+ assert X**10 == R.zero
24
+ assert X != x
25
+
26
+ raises(NotReversible, lambda: 1/X)
27
+
28
+
29
+ def test_QuotientRing():
30
+ I = QQ.old_poly_ring(x).ideal(x**2 + 1)
31
+ R = QQ.old_poly_ring(x)/I
32
+
33
+ assert R == QQ.old_poly_ring(x)/[x**2 + 1]
34
+ assert R == QQ.old_poly_ring(x)/QQ.old_poly_ring(x).ideal(x**2 + 1)
35
+ assert R != QQ.old_poly_ring(x)
36
+
37
+ assert R.convert(1)/x == -x + I
38
+ assert -1 + I == x**2 + I
39
+ assert R.convert(ZZ(1), ZZ) == 1 + I
40
+ assert R.convert(R.convert(x), R) == R.convert(x)
41
+
42
+ X = R.convert(x)
43
+ Y = QQ.old_poly_ring(x).convert(x)
44
+ assert -1 + I == X**2 + I
45
+ assert -1 + I == Y**2 + I
46
+ assert R.to_sympy(X) == x
47
+
48
+ raises(ValueError, lambda: QQ.old_poly_ring(x)/QQ.old_poly_ring(x, y).ideal(x))
49
+
50
+ R = QQ.old_poly_ring(x, order="ilex")
51
+ I = R.ideal(x)
52
+ assert R.convert(1) + I == (R/I).convert(1)
venv/lib/python3.10/site-packages/sympy/polys/matrices/__init__.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+
3
+ sympy.polys.matrices package.
4
+
5
+ The main export from this package is the DomainMatrix class which is a
6
+ lower-level implementation of matrices based on the polys Domains. This
7
+ implementation is typically a lot faster than SymPy's standard Matrix class
8
+ but is a work in progress and is still experimental.
9
+
10
+ """
11
+ from .domainmatrix import DomainMatrix, DM
12
+
13
+ __all__ = [
14
+ 'DomainMatrix', 'DM',
15
+ ]
venv/lib/python3.10/site-packages/sympy/polys/matrices/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (607 Bytes). View file
 
venv/lib/python3.10/site-packages/sympy/polys/matrices/__pycache__/_typing.cpython-310.pyc ADDED
Binary file (1.1 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/matrices/__pycache__/ddm.cpython-310.pyc ADDED
Binary file (17.8 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/matrices/__pycache__/dense.cpython-310.pyc ADDED
Binary file (8.92 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/matrices/__pycache__/domainmatrix.cpython-310.pyc ADDED
Binary file (51.8 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/matrices/__pycache__/domainscalar.cpython-310.pyc ADDED
Binary file (4.37 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/matrices/__pycache__/eigen.cpython-310.pyc ADDED
Binary file (3.79 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/matrices/__pycache__/exceptions.cpython-310.pyc ADDED
Binary file (2.12 kB). View file
 
venv/lib/python3.10/site-packages/sympy/polys/matrices/__pycache__/linsolve.cpython-310.pyc ADDED
Binary file (5.45 kB). View file