Le samedi 30 avril 2011 à 08:59 -0700, Tom Bachmann a écrit :
> This is roughly what I had in mind:
> [Everything is fake here, to only thing that is supposed to be
> illustrated is how assumptions get cleared up when their objects
> vanish.]
> 
> import weakref
> 
> class Assumption(object):
>     pass
> 
> class AssumePositive(Assumption):
> 
>     def __init__(self, x):
>         self.var = weakref.ref(x, self.cb)
> 
>     def cb(self, var):
>         if self.callback:
>             self.callback(self)
> 
>     def __str__(self):
>         return str(self.var) + ' > 0'
> 
> class Symbol(object):
>     def __init__(self, name):
>         self.name = name
> 
>     def __str__(self):
>         return str(self.name)
> 
> assumptions = {}
> 
> def remove_assumption(wr):
>     print 'removing assumption', assumptions[wr]
>     del assumptions[wr]
> 
> N = 0
> def assume(a):
>     global N
>     print 'adding assumption', a, 'as', N
>     assumptions[a] = N
>     a.callback = remove_assumption
>     N += 1
> 
> def test2():
>     x = Symbol('y')
>     assume(AssumePositive(x))
>     print assumptions
>     print 'leaving test2'
> 
> def test():
>     x = Symbol('x')
>     assume(AssumePositive(x))
>     print assumptions
>     print 'entering test2'
>     test2()
>     print assumptions
>     print 'leaving test'
> 
> test()
> 
I don't see how this is in any way better than storing the assumptions
on the object. For instance, assume(AssumePositive(x + y)) won't work
properly. And it's not clear how assumptions can be retrieved.

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

Reply via email to