SymPy is built on top of Python, so symbol names have to be defined to
be used.

x = Symbol('x') is no different (from Python's point of view) from x =
1 or x = 'x'.  It is just a variable assignment.  In particular, this
means that variable names don't have to match at all the name of the
Symbol that they hold.  Nowhere can anything tell what the name of
your variable is, or if you even used one at all (e.g., it's
impossible for a function like solve() to tell if you used x =
Symbol('x'); solve(x**2 - 1) or just solve(Symbol('x')**2 - 1) or even
y = Symbol('x'); solve(y**2 - 1); they all appear exactly the same to
it).

I don't know if this helps you in your application.  It's really hard
to say what you should do without knowing more.

Finally, I should point out that if you are working strictly
interactively, there is the var() function, which performs some magic
to define symbols for you, like

>>> var('x y z')
>>> x
x

However, it's not recommended to use this function unless you are
working interactively, because there can be some subtle issues (e.g.,
it might not work unless it's called at the module level), and it's
somewhat bad style.

Another option would be to create the variable definitions
programitically.  The python() function might help.  For example:

In [67]: python(symbols("x, y, z, a, b, c, d"))
Out[67]:
     x = Symbol('x')
     y = Symbol('y')
     z = Symbol('z')
     a = Symbol('a')
     b = Symbol('b')
     c = Symbol('c')
     d = Symbol('d')
e = (x, y, z, a, b, c, d)

You can take all those definitions and paste them into your file.

Aaron Meurer

On Wed, Jul 18, 2012 at 5:30 PM, Brad <[email protected]> wrote:
> Hi,
>
> I have an application in which many symbolic variables (close to 100) need
> to be defined.
>
> I am aware that one can do
>
> x,y,z = sympy.symbols('x y z')
>
> or
>
> x = sympy.Symbol('x'); y = sympy.Symbol('y'); z = sympy.Symbol('z')
>
> For my application, many of the symbol names are very close in spelling, so
> it takes a great deal of care to assure that the exact same variable name is
> used on the left-hand and right-hand sides of the assignment.
>
> Is there a way to assign them in a more automatic and potentially error free
> manner?
>
> For instance, it would be convenient, and less error prone in my case, if I
> could do something like
>
> vars = ['x,'y','z']
> for v in vars:
>   sympy.implicit_symbol(v)
>
> and then use x, y, and z as symbolic variables.
>
> Thank you.
>
> Kind regards,
> Brad
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sympy/-/ecdKdlhEhQgJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.

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

Reply via email to