Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between var and Symbol in sympy

Is there any difference between the two methods var and symbol in the sympy module in python? cause both are working the same way. I googled it and I did not find a detailed explanation for a difference. Are they really the exact same thing or one of them is actually using the other or what?

like image 357
Safwat Alshazly Avatar asked Mar 20 '17 07:03

Safwat Alshazly


People also ask

How do you define a symbol in SymPy?

SymPy also has a Symbols() function that can define multiple symbols at once. String contains names of variables separated by comma or space. In SymPy's abc module, all Latin and Greek alphabets are defined as symbols. Hence, instead of instantiating Symbol object, this method is convenient.

What is the difference between symbol and symbols in Python?

Symbol is a class. symbols is a function that can create multiple instances of the Symbol class.

What is symbol module in Python?

The % symbol in Python is called the Modulo Operator. It returns the remainder of dividing the left hand operand by right hand operand.

How do you define a symbol in Python?

Symbolic math symbols are declared using SymPy's symbols() function. Pass a string surrounded by quotes to the symbols() function as an input argument. The the output of the symbols() function is assigned to a SymPy symbols object (not a string, no quotes).


1 Answers

There is an answer to that in the FAQ. Basically, var(x) is equal to x = Symbol('x'), but the former doesn't force you to type x twice, while the latter is more explicit. var calls symbols, according to the docs.

Symbol also takes options, as explained in this post. You can pass assumptions (like positive=True), classes (if you want to create a named expression for example) or seq=<True|False> if you want the symbol to be an iterator.

There is also symbols, which can create tuples of symbols quickly, as explained here: a = symbols('a0:%d' % 5), which creates a tuple (a0, a1, a2, a3, a4).

like image 56
StefanS Avatar answered Oct 04 '22 05:10

StefanS