**assumptions in __new__ in Symbol class

25 views
Skip to first unread message

Abhishek K Das

unread,
May 16, 2014, 9:20:45 PM5/16/14
to sy...@googlegroups.com
    def __new__(cls, name, **assumptions):
       
"""Symbols are identified by name and assumptions::


        >>> from sympy import Symbol
        >>> Symbol("
x") == Symbol("x")
        True
        >>> Symbol("
x", real=True) == Symbol("x", real=False)
        False


        """



       
if assumptions.get('zero', False):
           
return S.Zero
        is_commutative
= fuzzy_bool(assumptions.get('commutative', True))
       
if is_commutative is None:
           
raise ValueError(
               
'''Symbol commutativity must be True or False.''')

I was studying how declaration of Symbol works with the help of winpdb . `name` is for the name of symbol and `assumptions` are the assumptions associated with it .
What about the cls variable , I didn't understand it's use and what does assumptions.get('zero',False) mean ? 

Abhishek K Das

unread,
May 16, 2014, 9:52:25 PM5/16/14
to sy...@googlegroups.com
Along with this I needed to ask one more thing as for the definition of class Zero , there are methods where S.Zero is returned . Has the word Zero been hardcoded to 0 somewhere because
I don't understand how that returns value 0 . Similarly is the case with `One` also . 

Aaron Meurer

unread,
May 16, 2014, 10:43:01 PM5/16/14
to sy...@googlegroups.com
cls is the class that is being instantiated. It will usually be
Symbol, but if something subclasses Symbol, it will be that instead.
It is similar to self, except self is usually used for instances, not
classes.

Zero is the SymPy version of 0. If you type "0", that gives the Python
int(0). Zero prints as 0, and any time you combine another SymPy
operation with 0, it gets transformed to 0 (via sympify()). The
"Advanced Expression Manipulation" section of the tutorial explains
this in more detail.

Aaron Meurer
> --
> 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 post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/52ea2793-3c7b-43ba-a816-02dd1f804c65%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages