Re: [sympy] what does Equal and == do in sympy

2015-05-29 Thread Robert
Hello,

Thanks for the help previously. I've run into a different issue with 
regards to Eq.

Sympify will automatically convert Eq into ==
 sympy.sympify('Eq(a, b)')
a == b

which if you sympify again will have the behavior you described originally.
 sympy.sympify(str(sympy.sympify('Eq(a, b)')))
False

Do you know of any way to stop the converion of Eq to ==?

Thanks,
Rob



On Friday, April 27, 2012 at 5:29:53 PM UTC-5, Aaron Meurer wrote:

 Equal is not anything.  You've just created an undefined function 
 called Equal (Function('Equal')) with that sympify command. 

 What you are probably looking for is Eq() (or Equality()).  This 
 creates a symbolic equality.  You can manipulate different sides of 
 the equation using Eq.lhs and Eq.rhs, like 

 In [496]: Eq(x, y) 
 Out[496]: x = y 

 In [497]: Eq(x, y).lhs 
 Out[497]: x 

 In [498]: Eq(x, y).rhs 
 Out[498]: y 

 Eq() will reduce to True when or False when it can see that the 
 expressions are always equal or unequal: 

 In [504]: Eq(x, y).subs({x: 1, y: 1}) 
 Out[504]: True 

 In [505]: Eq(x, y).subs({x: 1, y: 2}) 
 Out[505]: False 

 == is a lot different.  This is used to exactly compare expressions. 
 a == b will be a boolean, True if a and be are exactly equal and False 
 otherwise.  I say exactly equal because == does structural 
 comparison, not mathematical comparison.  So we have 

 In [499]: x*(y + z) == x*y + x*z 
 Out[499]: False 

 In [500]: x*(y + z) == x*(y + z) 
 Out[500]: True 

 If you want to do a mathematical comparison, the best way is to 
 subtract one expression from the other and pass it to simplify(), and 
 see if it goes to 0.  For example: 

 In [501]: a = x*(y + z) 

 In [502]: b = x*y + x*z 

 In [503]: simplify(a - b) 
 Out[503]: 0 

 See http://docs.sympy.org/dev/gotchas.html#equals-signs for more 
 discussion on this. 

 Aaron Meurer 

 On Fri, Apr 27, 2012 at 4:16 PM, Robert phu...@gmail.com javascript: 
 wrote: 
  Hello, 
  
  I have a question about == and Equal in sympy. 
  
  Their behavior is strange to me. 
  
  In [108]: expr = sympy.simplify('Equal(A,B)') 
  In [111]: expr.subs(dict(A=1, B=1)) 
  Equal(1, 1) 
  
  In [112]: expr = sympy.simplify('A==B') 
  In [113]: expr 
  False 
  
  In [115]: A = sympy.Symbol('A') 
  In [116]: B = sympy.Symbol('B') 
  
  In [117]: A==B 
  False 
  
  In [118]: sympy.__version__ 
  '0.7.1' 
  
  -- 
  You received this message because you are subscribed to the Google 
 Groups sympy group. 
  To post to this group, send email to sy...@googlegroups.com 
 javascript:. 
  To unsubscribe from this group, send email to 
 sympy+un...@googlegroups.com javascript:. 
  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 unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@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/09c3fbc5-1746-4ff3-9f81-0171a65849e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] what does Equal and == do in sympy

2015-05-29 Thread Robert
I was able to write a LambdaPrinter that does what I want for the time 
being:


class NonRelationalOpPrinter(lambdarepr.LambdaPrinter):

'''
 from structures import symbolic
 for op in ['Eq', 'Ne', 'Gt', 'Lt', 'Ge', 'Le']:
...   
 
sympy.sympify((symbolic.NonRelationalOpPrinter().doprint(sympy.sympify('%s(%s(a,
 
b), c)' % (op, op)
(a == b) == c
(a != b) != c
(a  b)  c
(a  b)  c
(a = b) = c
(a = b) = c
'''

def _printRelation(self, expr, name):
return '%s(%s)' % (name, , .join(map(self._print, expr.args)))

def _print_Equality(self, expr):
return self._printRelation(expr, 'Equality')

def _print_Unequality(self, expr):
return self._printRelation(expr, 'Unequality')

def _print_GreaterThan(self, expr):
return self._printRelation(expr, 'GreaterThan')

def _print_LessThan(self, expr):
return self._printRelation(expr, 'LessThan')

def _print_StrictGreaterThan(self, expr):
return self._printRelation(expr, 'StrictGreaterThan')

def _print_StrictLessThan(self, expr):
return self._printRelation(expr, 'StrictLessThan')



On Friday, May 29, 2015 at 4:31:59 AM UTC-5, Robert wrote:

 Hello,

 Thanks for the help previously. I've run into a different issue with 
 regards to Eq.

 Sympify will automatically convert Eq into ==
  sympy.sympify('Eq(a, b)')
 a == b

 which if you sympify again will have the behavior you described originally.
  sympy.sympify(str(sympy.sympify('Eq(a, b)')))
 False

 Do you know of any way to stop the converion of Eq to ==?

 Thanks,
 Rob



 On Friday, April 27, 2012 at 5:29:53 PM UTC-5, Aaron Meurer wrote:

 Equal is not anything.  You've just created an undefined function 
 called Equal (Function('Equal')) with that sympify command. 

 What you are probably looking for is Eq() (or Equality()).  This 
 creates a symbolic equality.  You can manipulate different sides of 
 the equation using Eq.lhs and Eq.rhs, like 

 In [496]: Eq(x, y) 
 Out[496]: x = y 

 In [497]: Eq(x, y).lhs 
 Out[497]: x 

 In [498]: Eq(x, y).rhs 
 Out[498]: y 

 Eq() will reduce to True when or False when it can see that the 
 expressions are always equal or unequal: 

 In [504]: Eq(x, y).subs({x: 1, y: 1}) 
 Out[504]: True 

 In [505]: Eq(x, y).subs({x: 1, y: 2}) 
 Out[505]: False 

 == is a lot different.  This is used to exactly compare expressions. 
 a == b will be a boolean, True if a and be are exactly equal and False 
 otherwise.  I say exactly equal because == does structural 
 comparison, not mathematical comparison.  So we have 

 In [499]: x*(y + z) == x*y + x*z 
 Out[499]: False 

 In [500]: x*(y + z) == x*(y + z) 
 Out[500]: True 

 If you want to do a mathematical comparison, the best way is to 
 subtract one expression from the other and pass it to simplify(), and 
 see if it goes to 0.  For example: 

 In [501]: a = x*(y + z) 

 In [502]: b = x*y + x*z 

 In [503]: simplify(a - b) 
 Out[503]: 0 

 See http://docs.sympy.org/dev/gotchas.html#equals-signs for more 
 discussion on this. 

 Aaron Meurer 

 On Fri, Apr 27, 2012 at 4:16 PM, Robert phu...@gmail.com wrote: 
  Hello, 
  
  I have a question about == and Equal in sympy. 
  
  Their behavior is strange to me. 
  
  In [108]: expr = sympy.simplify('Equal(A,B)') 
  In [111]: expr.subs(dict(A=1, B=1)) 
  Equal(1, 1) 
  
  In [112]: expr = sympy.simplify('A==B') 
  In [113]: expr 
  False 
  
  In [115]: A = sympy.Symbol('A') 
  In [116]: B = sympy.Symbol('B') 
  
  In [117]: A==B 
  False 
  
  In [118]: sympy.__version__ 
  '0.7.1' 
  
  -- 
  You received this message because you are subscribed to the Google 
 Groups sympy group. 
  To post to this group, send email to sy...@googlegroups.com. 
  To unsubscribe from this group, send email to 
 sympy+un...@googlegroups.com. 
  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 unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@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/db78709d-2af8-426a-968a-20434f211058%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[sympy] diff(x^x,x)

2015-05-29 Thread Thomas Leitz
Hi,

the online shell at http://live.sympy.org/ tells me

diff(x^x,x) = 0

Why is that?

Tom

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@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/5f6df3dd-904b-4d1a-afcc-9ce8ff0d7a50%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2015-05-29 Thread Oscar Benjamin
On 29 May 2015 22:06, Thomas Leitz unruhsc...@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

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@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/CAHVvXxSNEU1dGr9zKOXRq1uFQYYEz10qHNku0JmzGmCqBhAq2w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.