2

Why does the following return False?

import sympy as sp

x = sp.Symbol('x')
y = sp.Symbol('y')

sp.log(x*y) == sp.log(x) + sp.log(y)
sammosummo
  • 495
  • 1
  • 7
  • 17

1 Answers1

4

There is an underlying assumption for this rule that your variables are positive. SymPy won't perform this simplification (correctly) if this is not indicated.

To make this assumption clear to SymPy,

x = sp.Symbol('x', positive=True)
y = sp.Symbol('y', positive=True)

Now read this Q/A on equality in SymPy to see that you ought to be simplifying in your comparison.

>>> sp.simplify(sp.log(x*y) - (sp.log(x) + sp.log(y))) == 0
True
miradulo
  • 28,857
  • 6
  • 80
  • 93