Hello!

I have an application where I use undefined functions as keys in 
dictionaries.

This works great out of the box for sympy.Function
However, I want to set real=True so I created a class factory which 
overrides _eval_is_real

Now the trouble starts. I tried to work my way through the jungle of 
metaclasses and the assumptions systems
but I don't seem to be able to fix this:

-*- coding: utf-8 -*-

from sympy.core.function import UndefinedFunction
import sympy

def MaybeRealFunction(key, real=None):

    class _Function(UndefinedFunction):
        @staticmethod
        def _eval_is_real(self):
            return real

    return _Function(key)


def main():
    x = sympy.Symbol('x')
    assert x == sympy.Symbol('x')

    f_x = sympy.Function('f')(x)
    assert f_x == sympy.Function('f')(x)

    g_x = MaybeRealFunction('g', real=True)(x)
    assert g_x.is_real
    assert g_x == g_x
    assert g_x == MaybeRealFunction('g', real=True)(x) # <--- This one fails

if __name__ == '__main__':
    main()


Any ideas?

Best regards,
/Björn

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to