SymPy is a Google Summer of Code 2011 Mentoring Organization

March 18, 2011

I am proud to announce that SymPy has been accepted as a mentoring organization for Google Summer of Code 2011. This is great news for the project. Although we have participated in the past under the umbrella of the Python Software Foundation and Portland State University mentoring organizations, this is the first time that we have been accepted as a mentoring organization. Out of 417 organizations that applied to Google, 175 were accepted, 50 of which were new.

In case you don’t know, Google Summer of Code is a program run by Google every year where they pay college students all around the world to write code for open source projects. Each student has a mentor assigned to him/her, who helps the student get started with interacting with open source (most students who are accepted have never participated in open source before).

So now that were are accepted, students are open to applications. The actual application period opens on March 28, and closes on April 8 (see the program timeline).

To students:

If you are interested in applying, please write the to mailing list and introduce yourself. The program is open to anyone worldwide who is 18 years of age or older who is enrolled in a higher education institution (this includes undergraduate and graduate). If you are interested in applying, here is what you should do (if you have not already):

- As I said above, write to the list and introduce yourself. You might also join our IRC channel, which is #sympy on freenode.

- Start thinking about what you want to apply to do. See our ideas page. However, we are open to ideas that are not on that page. Anything that fits in a computer algebra system would fit in SymPy. If you have an idea not on that page, please discuss it on our mailing list, so we can see if it has not already be implemented, and if it is fitting for SymPy and for a project. I recommend you apply to do something that you are interested in personally.

- We require for any student to be accepted that he/she submit at least one patch to SymPy, which gets reviewed and pushed in. See issues labeled EasyToFix in our issue tracker for some easy to fix issues that are a good place to start. Don’t worry if you do not know how to send in a patch or use git. We will help you (that is the whole point of the program). Just ask on the mailing list, on the issue page, or on IRC.

- You should start thinking about your application. See our application template (it will also be at our page on the Google site). If you like, you can start a page on our wiki to write your proposal. If you do this, we will help you edit it (though understand that we will not help you write it). Remember that we want you to get accepted just as much as you do, so you can help improve SymPy!

To SymPy developers:

- We need people who are willing to mentor students. If you are willing to mentor, please add your name to the bottom of the ideas page.

- Please edit the ideas page to improve formatting and add new ideas.

Good luck to all students who plan on applying!


True is True is False is True is False

March 15, 2011

Time for another one of my WTF Python blog posts. Yesterday, I randomly typed this in a Python session (it was late at night):

>>> True is True is False is True is False
False

First a little background, in case you don’t know. The is operator in Python does exact object comparison in memory. Unlike ==, which only compares it two objects are equal, is only returns True if both arguments have the same memory address. So you can have something like:

>>> a = 12345
>>> b = 12345
>>> a == b
True
>>> a is b
False

Now, there are a handful of Python built-ins that are always equal one another with the is operator. True and False are two such constants:

>>> a = True
>>> b = True
>>> a == b
True
>>> a is b
True
>>> c = False
>>> d = False
>>> c == d
True
>>> c is d
True

Now, going back to the above, we see that each is returns True or False, which is then evaluated with the next one. Or at least that is what you would think is happening. But go back and look at it again, and see if you can figure out what it should evaluate to. You could probably guess that something was amiss from the fact that I was blogging about it. If you haven’t figured it out already, look at the following:

>>> True is True is False is True is False
False
>>> (((True is True) is False) is True) is False
True
>>> True is (True is (False is (True is False)))
True

So it seems that is does not associate to the left or to the right. Let’s see if we can figure out what is going on. First off, True is True, etc. do behave as you expect them to:

>>> True is True
True
>>> False is False
True
>>> True is False
False
>>> False is True
False

It is when we start using multiple iss in the same statement that we start seeing problems:

>>> False is False is False
True
>>> (False is False) is False
False

So what’s going on here? False is False is True, so maybe it is short-circuiting somehow.

>>> True is False is False
False
>>> False is False is True
False

No, that is not it. Those reduce to False is False and True is True when associating to the left, respectively, and True is True and True is True when associating to the right.

Finally, at this point, it occurs to me what is really going on. Have you figured it out too (or maybe you already knew all along)? Maybe you can guess it from this statement, which uses None, another built-in object that always compares equal to itself with the is operator:

>>> None is None is None
True

So you see what is happening? is doesn’t associate at all. Rather, using multiple iss in one statement does multiple comparisons at once. Any a is b is … x will return True if a, b, …, and x are all equal by the is operator (they share the same identity or memory address), and False otherwise. Actually, this isn’t surprising, since == works the same way:

>>> False == False == False
True
>>> (False == False) == False
False

This syntax can actually be useful to test equality of three or more items at once efficiently (Python will not evaluate the same operand more than once, and it short circuits). But it can be confusing when comparing with True or False, since a is b and a == b themselves evaluate to one of those values. So remember that it is NOT associative in any way. Rather, it acts as an n-way comparison.

Finally, as this table of operator precedence in Python shows, is and == have the same precedence in Python. Therefore, it should be possible to combine the two in these same statement. Indeed, you can:

>>> a = 12345
>>> b = 12345
>>> c = b
>>> a == b == c
True
>>> a is b is c
False
>>> # Because this is False
... 
>>> a is b
False
>>> # But this is True
... 
>>> b is c
True
>>> # So we get
... 
>>> a == b is c
True

Follow

Get every new post delivered to your Inbox.

Join 122 other followers

%d bloggers like this: