Ondrej Certik wrote:
On Fri, Mar 19, 2010 at 7:01 PM, Ondrej Certik <ond...@certik.cz> wrote:
Hi,

please review my 2 patches in "pu" branch at github:

* ee232d5 (HEAD, github/pu, pu) atan2(y, x) can now be converted to/from Sage
* 17806ba test_sage: Use S() instead of sympify()

please review also these patches in the same branch:

* 08250dc (HEAD, github/pu, pu) test_sage.py: add the tests into the Sage doctes
* 658eccb mpmath: test for sage_utils.bitcount

Ondrej


Hi Ondrej,

I've just tried to run the tests on your pu branch, but got two failing tests (see below). It may be due to my poor attempt to install sage. I get the same errors without your patches. Note: I just downloaded the latest version of sage to give it a spin. After some fiddling with the environment vars (like SAGE_ROOT), the tests were running.

This is the first time I try Sage. It gives me such a bloated impression that it becomes scary and repelling...

cheers,

Toon


py.test sympy/test_external/test_sage.py
/usr/bin/python: /home/toon/tmp/build/sage/sage-4.3.3-linux-32bit-ubuntu_9.10-i686-Linux//local/lib/libz.so.1: no version information available (required by /usr/bin/python)
   ? cannot open `standard.lib`
============================= test process starts =============================
executable:   /usr/bin/python  (2.6.4-final-0)
/usr/lib/python2.6/dist-packages/py/process/cmdexec.py:27: DeprecationWarning: The popen2 module is deprecated. Use the subprocess module.
  import popen2
using py lib: /usr/lib/python2.6/dist-packages/py <rev unknown>

sympy/test_external/test_sage.py[13] .F.........F.

_______________________________________________________________________________
__________________________ entrypoint: test_complex ___________________________

    def test_complex():
>       check_expression("I", "")

[/mnt/data/toon/unief/research/code/work/sympy/sympy/test_external/test_sage.py:64]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def check_expression(expr, var_symbols):
        """Does eval(expr) both in Sage and SymPy and does other checks."""

        # evaluate the expression in the context of Sage:
        sage.var(var_symbols)
        a = globals().copy()
        # safety checks...
        assert not "sin" in a
        a.update(sage.__dict__)
        assert "sin" in a
        e_sage = eval(expr, a)
        assert not isinstance(e_sage, sympy.Basic)

        # evaluate the expression in the context of SymPy:
        sympy.var(var_symbols)
        b = globals().copy()
        assert not "sin" in b
        b.update(sympy.__dict__)
        assert "sin" in b
        b.update(sympy.__dict__)
        e_sympy = eval(expr, b)
        assert isinstance(e_sympy, sympy.Basic)

        # Do the actual checks:
E       assert sympy.S(e_sage) == e_sympy
>       assert I == I
         +  where I = S(I)
         +    where S = sympy.S

[/mnt/data/toon/unief/research/code/work/sympy/sympy/test_external/test_sage.py:52]
_______________________________________________________________________________
_________________________ entrypoint: test_functions __________________________

    def test_functions():
        check_expression("sin(x)", "x")
        check_expression("cos(x)", "x")
        check_expression("tan(x)", "x")
        check_expression("cot(x)", "x")
        check_expression("asin(x)", "x")
        check_expression("acos(x)", "x")
        check_expression("atan(x)", "x")
>       check_expression("atan2(y, x)", "x, y")

[/mnt/data/toon/unief/research/code/work/sympy/sympy/test_external/test_sage.py:113]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def check_expression(expr, var_symbols):
        """Does eval(expr) both in Sage and SymPy and does other checks."""

        # evaluate the expression in the context of Sage:
        sage.var(var_symbols)
        a = globals().copy()
        # safety checks...
        assert not "sin" in a
        a.update(sage.__dict__)
        assert "sin" in a
        e_sage = eval(expr, a)
        assert not isinstance(e_sage, sympy.Basic)

        # evaluate the expression in the context of SymPy:
        sympy.var(var_symbols)
        b = globals().copy()
        assert not "sin" in b
        b.update(sympy.__dict__)
        assert "sin" in b
        b.update(sympy.__dict__)
        e_sympy = eval(expr, b)
        assert isinstance(e_sympy, sympy.Basic)

        # Do the actual checks:
>       assert sympy.S(e_sage) == e_sympy

[/mnt/data/toon/unief/research/code/work/sympy/sympy/test_external/test_sage.py:52]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def sympify(a, locals=None, convert_xor=True):
        """Converts an arbitrary expression to a type that can be used
           inside sympy. For example, it will convert python ints into
           instance of sympy.Rational, floats into instances of sympy.Real,
           etc. It is also able to coerce symbolic expressions which does
inherit after Basic. This can be useful in cooperation with SAGE.

           It currently accepts as arguments:
               - any object defined in sympy (except maybe matrices [TODO])
               - standard numeric python types: int, long, float, Decimal
               - strings (like "0.09" or "2e-19")
               - booleans, including None (will leave them unchanged)

If the argument is already a type that sympy understands, it will do nothing but return that value. This can be used at the beginning of a
           function to ensure you are working with the correct type.

           >>> from sympy import sympify

           >>> sympify(2).is_integer
           True
           >>> sympify(2).is_real
           True

           >>> sympify(2.0).is_real
           True
           >>> sympify("2.0").is_real
           True
           >>> sympify("2e-45").is_real
           True

        """
# XXX instead of duplicating _sympify it would be better to call _sympify # directly from here, but a lot of SymPy still calls sympify (no '_') and
        # this will add unneccesary overhead.
        #
        # When everything settles, let's refactor this.
        #                                      -- kirr
        if locals is None:
            locals = {}
        if isinstance(a, (Basic, BasicType, bool)):
            return a
        if a is None:
            return a
        elif isinstance(a, (int, long)):
            return Integer(a)
        elif isinstance(a, (float, decimal.Decimal)):
            return Real(a)
        elif isinstance(a, complex):
            real, imag = map(sympify, (a.real, a.imag))
            return real + S.ImaginaryUnit * imag
        elif isinstance(a, (list,tuple,set)):
            return type(a)([sympify(x) for x in a])

# let's see if 'a' implements conversion methods such as '_sympy_' or # '__int__', that returns a SymPy (by definition) or SymPy compatible
        # expression, so we just use it
        for methname, conv in [
                ('_sympy_',None),
                ('__float__', Real),
                ('__int__', Integer),
                ]:
            meth = getattr(a, methname, None)
            if meth is None:
                continue

# we have to be careful -- calling Class.__int__() almost always is not
            # a good idea
            try:
>               v = meth()

[/mnt/data/toon/unief/research/code/work/sympy/sympy/core/sympify.py:86]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

> [failure to get at sourcelines from <TracebackEntry /mnt/data/toon/unief/research/code/work/sympy/expression.pyx:932>]

[/mnt/data/toon/unief/research/code/work/sympy/expression.pyx:932]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def __call__(self, ex=None):
        """
            .. note::

If this object does not have an attribute *ex*, then an argument
               must be passed into :meth`__call__`::

            EXAMPLES::

sage: from sage.symbolic.expression_conversions import Converter
                sage: c = Converter(use_fake_div=True)
                sage: c(SR(2))
                Traceback (most recent call last):
                ...
                NotImplementedError: pyobject
                sage: c(x+2)
                Traceback (most recent call last):
                ...
                NotImplementedError: arithmetic
                sage: c(x)
                Traceback (most recent call last):
                ...
                NotImplementedError: symbol
                sage: c(x==2)
                Traceback (most recent call last):
                ...
                NotImplementedError: relation
                sage: c(sin(x))
                Traceback (most recent call last):
                ...
                NotImplementedError: composition
                sage: c(function('f', x).diff(x))
                Traceback (most recent call last):
                ...
                NotImplementedError: derivative

            We can set a default value for the argument by setting
            the ``ex`` attribute::

                sage: c.ex = SR(2)
                sage: c()
                Traceback (most recent call last):
                ...
                NotImplementedError: pyobject
            """
        if ex is None:
            ex = self.ex

        try:
            obj = ex.pyobject()
            return self.pyobject(ex, obj)
        except TypeError, err:
            if 'self must be a numeric expression' not in err:
                raise err

        operator = ex.operator()
        if operator is None:
            return self.symbol(ex)

        if operator in arithmetic_operators:
if getattr(self, 'use_fake_div', False) and operator is _operator.mul:
                div = self.get_fake_div(ex)
                return self.arithmetic(div, div.operator())
            return self.arithmetic(ex, operator)
        elif operator in relation_operators:
            return self.relation(ex, operator)
        elif isinstance(operator, FDerivativeOperator):
            return self.derivative(ex, operator)
        else:
>           return self.composition(ex, operator)

[/home/toon/tmp/build/sage/sage-4.3.3-linux-32bit-ubuntu_9.10-i686-Linux/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py:220]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def composition(self, ex, operator):
        """
            EXAMPLES::

sage: from sage.symbolic.expression_conversions import SympyConverter
                sage: s = SympyConverter()
                sage: f = sin(2)
                sage: s.composition(f, f.operator())
                sin(2)
                sage: type(_)
                sin
                sage: f = arcsin(2)
                sage: s.composition(f, f.operator())
                asin(2)
            """
        f = repr(operator)
        g = ex.operands()
        import sympy
        # translates Sage function names to SymPy function names
        translation_table = {
                "arcsin": "asin",
                "arccos": "acos",
                "arctan": "atan",
                "arccot": "acot",
                "arcsinh": "asinh",
                "arccosh": "acosh",
                "arctanh": "atanh",
                "arccoth": "acoth",
                }
        if f in translation_table:
            f = translation_table[f]
        f_sympy = getattr(sympy, f, None)
        if f_sympy:
            return f_sympy(*sympy.sympify(g))
        else:
E raise NotImplementedError("SymPy function '%s' doesn't exist" % f)
>           NotImplementedError: SymPy function 'arctan2' doesn't exist

[/home/toon/tmp/build/sage/sage-4.3.3-linux-32bit-ubuntu_9.10-i686-Linux/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py:646]
_______________________________________________________________________________
============= tests finished: 11 passed, 2 failed in 0.68 seconds =============
DO *NOT* COMMIT!

--
You received this message because you are subscribed to the Google Groups 
"sympy-patches" group.
To post to this group, send email to sympy-patc...@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