Assumptions

18 views
Skip to first unread message

Mr D

unread,
Mar 26, 2017, 7:35:58 AM3/26/17
to sympy
So I read through the blog post on assumptions

http://matthewrocklin.com/blog/work/2013/02/05/Assuming

Its a really interesting project, but I'm wondering, why switch assumptions methods in the first place?

Another question I have is about the issue of garbage collection of the assumptions when a symbol is deleted. When you have symbol 'x' and you decide to undefine it, would it be possible to incorporate a garbage collector that is defined when you import the sympy module? But garbage collection could be expensive though, no? But that wouldn't be a crucial drawback though, would it, because it would be simlar complexity as regular garbage collection which happens anyhow?

Also, when using global assumptions dictionary or whatnot, if we pass a symbol to a function, we can access the global assumptions there in connection with that symbol. But suppose we have a symbol 'x' in the global scope, and it has some assumptions attached to it. Next we define a function in which another symbol named 'x' is defined. How do we distinguish between the local symbol's assumptions and those of the global symbols? Well, that should be easy, you have a local dictionary, and if the symbol is there, you use that, otherwise you use the global dictionary. But, for that to work, the global_assumptions object has to be able to determine the level of scope you're in. Well, that is easy since you can use the dir() command, right? But, the question with that is performance, and if there is a better way to do it.

I'm wondering if maybe there is a way to connect to the defined assumptions by using the variable symbol table. So, for instance, suppose you defined a symbol variable:

x = Symbol(x, positive=True)

Now, we want this to work since one of the requirements is backward compatibility with old assumptions. Is it possible to define static class in the Symbol object that, when the positive=True parameter is added, the static function gets called and adds to the global_assumptions object? Now, suppose you call a line saying Symbol('x', positive=True) and not attach it to a variable. Well, it gets garbage collected, right? So, how should it update the global_assumptions to get rid of the corresponding assumption? In wonder maybe the assumptions can be referenced by some function looking at the variable symbol table, kinda like what you see when you execute the dir() function. And, if the corresponding entry in dir() is gone after geting rid of the symbol variable, then the corresponding assumption cannot be accessed and can therefore be garbage collected eventually?
Reply all
Reply to author
Forward
0 new messages