Re: [sympy] diff(x^x,x)

43 views
Skip to first unread message

Oscar Benjamin

unread,
May 29, 2015, 5:17:11 PM5/29/15
to sympy


On 29 May 2015 22:06, "Thomas Leitz" <unruh...@gmail.com> wrote:
>
> Hi,
>
> the online shell at http://live.sympy.org/ tells me
>
> diff(x^x,x) = 0
>
> Why is that?

^ doesn't do what you're expecting in Python. Use ** for exponentiation.

--
Oscar

Francesco Bonazzi

unread,
May 30, 2015, 9:39:00 AM5/30/15
to sy...@googlegroups.com
In [1]: x^x
Out[1]: False

In [2]: diff(False, x)
Out[2]: 0



You should use ** instead of ^ if you'd like to represent exponentiation. The symbol ^ stands for XOR.

Christophe Bal

unread,
May 30, 2015, 2:01:17 PM5/30/15
to sympy-list
And because  x^x  means  x xor x  which numeric value is  0  or  1  so the derivative is equal to zero.


Christophe BAL
Enseignant de mathématiques en Lycée et développeur Python amateur
---
French math teacher in a "Lycée" and Python amateur developer


Aaron Meurer

unread,
May 31, 2015, 4:50:52 PM5/31/15
to sy...@googlegroups.com
Actually, that's not quite true. SymPy has its own boolean types, and
x ^ x gives the SymPy BooleanFalse (S.false). The derivative of this
is 0 not because it interprets it as a numeric 0 but because it
doesn't depend on x, and diff automatically knows that the derivative
of any expression that doesn't depend on x is 0.

Perhaps we should make derivatives of booleans give TypeError. That
would make it much easier to see what is going on.

It may also be worth it to print a warning in SymPy Live when ^ is used.

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/CAAb4jG%3DudR3U3EG2VDUW5qdAG5TEo8HBxTDWc8f3_4f9a20Vjw%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.

Joachim Durchholz

unread,
May 31, 2015, 5:17:38 PM5/31/15
to sy...@googlegroups.com
Am 31.05.2015 um 22:50 schrieb Aaron Meurer:
> Perhaps we should make derivatives of booleans give TypeError. That
> would make it much easier to see what is going on.

+1

Similarly, integer-valued functions should (probably?) emit a warning if
a derivative is taken. The derivative is technically correct, but
usually not what one wanted.

> It may also be worth it to print a warning in SymPy Live when ^ is used.

I'll be all for it if somebody picks that up.

Christophe Bal

unread,
May 31, 2015, 5:29:07 PM5/31/15
to sympy-list

I also vote for the TypeError.

--
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.
Reply all
Reply to author
Forward
0 new messages