--
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 sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/f0084d3b-db98-43cb-becd-020a368aec87%40googlegroups.com.
>>> To unsubscribe from this group and stop receiving emails from it, send an email to sy...@googlegroups.com.
>>> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/f0084d3b-db98-43cb-becd-020a368aec87%40googlegroups.com.
>
> --
> 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 sy...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to sy...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6Jk3fcvts_x3Cri-Fek0GcPmw0_DpW9pi0ObyxYHRO8-Q%40mail.gmail.com.
Thank you. This has been extremely helpful. Sorry once again for posting the wrong code initially.
James,
I found the creation of symbols in SymPy incredibly confusing and counter-intuitive - it was almost spoiling my enjoyment of using the wonderful SymPy system. I decided to work out a systematic way of using SymPy for short calculations that eliminates this confusion.
I avoid all use of Symbol, symbols, or any of the related ways of creating symbols, except for creating special symbols, such as undefined function symbols. I start any use of SymPy thus:
import sympy
from sympy.abc import *
from sympy import *
The module sympy.abc contains symbols for all 52 single-letter
variables - which are obviously most useful for algebra - in upper
and lower case.
Unfortunately a few upper case symbols are used by SymPy for specific purposes - so the order of the above imports is important - SymPy symbols should override those from abc so they are imported last. This is described in the SymPy documentation:
"As of the time of writing this, the names C
, O
,
S
,
I
,
N
,
E
,
and Q
are colliding with names defined in SymPy. If you import them from
both sympy.abc
and sympy
,
the second import will “win”. This is an issue only for * imports,
which should only be used for short-lived code such as interactive
sessions and throwaway scripts that do not survive until the next
SymPy upgrade, where sympy
may contain a different set of
names."
Using the above, I then choose a few (often zero) variables to
use in the traditional Python fashion (i.e. variables that will be
assigned values) and I have the rest available for algebra. If you
need a lot of Python variables - say in a complicated algorithm -
it may be easier to use multi-letter names for them - which
totally avoids any clash with symbols.
I don't create any normal symbols explicitly.
Note that the above quote from the SymPy documentation does not abhor the use of 'import *' for "short lived code", which might be better phrased as "small sized code". I suspect that typically most users only want to write a small SymPy 'program' - sometimes just one line - and for those uses 'import *' seems infinitely preferable. Of course, most of the people who post here are seasoned SymPy developers, and they are writing large amounts (hundreds or thousands of lines) of SymPy code - symbolic integration algorithms or whatever - and for them I can see that importing the entire contents of SymPy or other modules would be dangerous.
I hope that helps, and doesn't create too much controversy!
David