Hi David,
However, my feeling is that some proportion of SymPy users will work
interactively - in one scope - without defining any Python functions. So
they might calculate a polynomial without regard to any assumptions, and
then wish to apply an assumption for one specific calculation and hit
the problem you encountered.
Agreed.
On the
other hand, there must be a notion of the scope of a declaration.
I think all you need to do is redefine x using inconsistent assumptions.
This can be done in the same scope - there is no analogy with C or
Fortran, where you can't declare a variable twice in the same scope.
Indeed, you can call Symbol as many times as you like - it doesn't
define anything, it just sets up an instance of a class.
Unfortunately my OO background/knowledge is not strong enough to
understand this properly. Roughly speaking, I know what your words
mean, but not what the implications are.
I would have thought that it would not be hard for the SymPy developers
to provide a switch that could fault the situation where a symbol is
redefined with the same name but different assumptions. I fully accept
that this would be mostly useful for interactive work.
IMO it would be good to flag ANY instance of a symbol redefinition that
creates a different object than the original one. But if I understood
Oscar's reply to your message, this could add a lot of overhead. I
suppose there a function which is called each time a new Symbol is
instantiated. If that's only called for code that looks like
x = Symbol('x', ...)
then I would not expect a big overhead. But Oscar's reply suggests that
it could be called much more frequently.
I feel that gotchas of this sort could cause some real disaster because
it might be burried in a mass of algebra, and not be noticed before
papers or theses had been written.
Certainly the behavior surprised me, and it means that some of the sympy
code I have written in the past month is wrong. Even though it appears
to work correctly, that's accidental, not by design.
Cheers,
Bruce
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/10c2481e-71f7-4125-5620-a6c3c6f2a774%40googlemail.com.