On Sun, 14 Jul 2019 at 13:29, David Bailey <d...@dbailey.co.uk> wrote:
>
> On 13/07/2019 22:36, Oscar Benjamin wrote:
>
>
> Generally it is a lot easier to understand SymPy if you are
> experienced with Python. A lot of our users are new to both Python and
> SymPy and I think that makes it hard to explain what's going on. Some
> things would be cleaner for users if SymPy was not embedded within
> Python and can be confusing unless you already know Python well and
> can see why things are the way they are.
>
> --
> Oscar
>
> I am also fairly new to Python and sympy, but I think I have pushed through 
> this pain barrier.
>
> As far as I can see, you really need to use symbols() or var() to set up 
> variables which are going to be used as symbols in bits of algebra or 
> calculus, but you do not need to make a variable symbolic if it is just going 
> to be used to hold expressions or for some other pythonic purpose, such as a 
> counter. However, no harm is done (someone correct me if I am wrong) if you 
> create a lot of symbols, which you can do with :
>
> from sympy.abc import *
>
> because if, say, you subsequently assign X=42 that will harmlessly destroy 
> the sympy symbol attached to x which will become pythonic again, but you 
> obviously want to use it as a constant so that is fine.
>
> I think a good strategy is to either save some letters for use as pythonic 
> variables, or only use variables with more than one character as pythonic 
> variables (they don't look nice in expressions, anyway)
>
> If you want to use x in expressions, then it is probably best not to assign 
> it to 42 (as above) but to leave it symbolic, and use subs to replace it in 
> an expression by 42.

Everything you say here is correct. You need to have a clean
separation in your mind between the Python variable names and the
sympy Symbol objects. When you fully understand all of these things
the results below will not be surprising:
```
>>> z = Symbol('x')
>>> z
x
>>> x = z**2
>>> x
x**2
```
(I don't generally recommend writing code like that though)

--
Oscar

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxTJmhrApFgxjN6pfHEvM70gWD0AfabEATXhQisGm0qctQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to