For now these are very lightweight objects, bascally just containers
storing an expression, a key (string) and a value (boolean).

This will be used extensively by the query module
---
 sympy/__init__.py                             |    1 +
 sympy/assumptions/__init__.py                 |    1 +
 sympy/assumptions/assumptions.py              |   41 +++++++++++++++++++++++++
 sympy/assumptions/known_facts.py              |   21 +++++++++++++
 sympy/assumptions/tests/test_assumptions_2.py |   23 ++++++++++++++
 5 files changed, 87 insertions(+), 0 deletions(-)
 create mode 100644 sympy/assumptions/__init__.py
 create mode 100644 sympy/assumptions/assumptions.py
 create mode 100644 sympy/assumptions/known_facts.py
 create mode 100644 sympy/assumptions/tests/test_assumptions_2.py

diff --git a/sympy/__init__.py b/sympy/__init__.py
index f4c7d3a..d5b33fc 100644
--- a/sympy/__init__.py
+++ b/sympy/__init__.py
@@ -22,6 +22,7 @@ def __sympy_debug():
 import symbol as stdlib_symbol
 from sympy.core import *
 
+from assumptions import Assume
 from polys import *
 from series import *
 from functions import *
diff --git a/sympy/assumptions/__init__.py b/sympy/assumptions/__init__.py
new file mode 100644
index 0000000..41e388a
--- /dev/null
+++ b/sympy/assumptions/__init__.py
@@ -0,0 +1 @@
+from assumptions import Assume
\ No newline at end of file
diff --git a/sympy/assumptions/assumptions.py b/sympy/assumptions/assumptions.py
new file mode 100644
index 0000000..473751d
--- /dev/null
+++ b/sympy/assumptions/assumptions.py
@@ -0,0 +1,41 @@
+from sympy.core.symbol import Symbol
+
+class Assume(object):
+    """New-style assumptions
+
+    >>> from sympy import Symbol, Assume
+    >>> x = Symbol('x')
+    >>> Assume(x, integer=True)
+    Assume( x, integer, True )
+    >>> Assume(x, integer=False)
+    Assume( x, integer, False )
+    """
+
+    __global_registry = {}
+
+    def __init__(self, expr, *args, **kwargs):
+        if not isinstance(expr, Symbol):
+            raise NotImplementedError
+        if len(kwargs) != 1:
+            raise ValueError('Wrong set of arguments')
+        self._args = (expr, kwargs.keys()[0], kwargs.values()[0])
+
+    @property
+    def expr(self):
+        return self._args[0]
+
+    @property
+    def key(self):
+        return self._args[1]
+
+    @property
+    def value(self):
+        return self._args[2]
+
+    def __repr__(self):
+        return u"Assume( %s, %s, %s )" % (self.expr, self.key, self.value)
+
+    def __eq__(self, other):
+        if isinstance(other, type(self)):
+            return self._args == other._args
+        return False
\ No newline at end of file
diff --git a/sympy/assumptions/known_facts.py b/sympy/assumptions/known_facts.py
new file mode 100644
index 0000000..cb2a9e9
--- /dev/null
+++ b/sympy/assumptions/known_facts.py
@@ -0,0 +1,21 @@
+
+known_facts_dict = {
+    'even'       : ['integer & ~odd'],
+    'composite'  : ['integer & ~prime'],
+    'complex'    : ['real | imaginary', 'rational | irrational | imaginary'], 
# this is not quite correct
+    'integer'    : ['rational & numerator_is_one'],
+    'irrational' : ['real & ~rational'],
+    'imaginary'  : ['complex & ~real'],
+    'rational'   : ['real & ~irrational'],
+    'real'       : ['complex & ~imaginary', 'rational | irrational'],
+    'unbounded'  : ['extended_real & ~bounded'],
+    'negative'   : ['real & ~positive & ~zero'],
+    'nonpositive': ['real & ~positive', 'zero | negative'],
+    'nonnegative': ['real & ~negative', 'zero | positive'],
+    'noninteger' : ['real & ~integer'],
+    'nonzero'    : ['real & ~zero'],
+    'odd'        : ['integer & ~even'],
+    'prime'      : ['integer & positive & ~composite'],
+    'positive'   : ['real & ~negative & ~zero'],
+    'zero'       : ['real & ~positive & ~negative']
+}
diff --git a/sympy/assumptions/tests/test_assumptions_2.py 
b/sympy/assumptions/tests/test_assumptions_2.py
new file mode 100644
index 0000000..768418d
--- /dev/null
+++ b/sympy/assumptions/tests/test_assumptions_2.py
@@ -0,0 +1,23 @@
+"""rename this to test_assumptions.py when the old assumptions system is 
deleted"""
+from sympy.core import Symbol
+from sympy.assumptions import Assume
+
+def test_assume():
+    x = Symbol('x')
+    assump = Assume(x, integer=True)
+    assert assump.expr == x
+    assert assump.key == 'integer'
+    assert assump.value == True
+
+def test_assume_False():
+    x = Symbol('x')
+    assump = Assume(x, integer=False)
+    assert assump.expr == x
+    assert assump.key == 'integer'
+    assert assump.value == False
+
+def test_assume_equal():
+    x = Symbol('x')
+    assert Assume(x, positive=True)  == Assume(x, positive=True)
+    assert Assume(x, positive=True)  != Assume(x, positive=False)
+    assert Assume(x, positive=False) == Assume(x, positive=False)
\ No newline at end of file
-- 
1.6.1.2


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy-patches" group.
To post to this group, send email to sympy-patches@googlegroups.com
To unsubscribe from this group, send email to 
sympy-patches+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sympy-patches?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to