2

I've found an issue about Sympy that I can't understand.

Why does this return false...

factor(81*q + 90) == 9*(9*q + 10)

... whilst this returns true?

factor(q**2-64) == (q+8)*(q-8)

When I type

factor(81*q + 90)

the output is exactly this expression

9*(9*q + 10)

So, why doesn't Sympy consider my first comparison is true?

user2905179
  • 21
  • 1
  • 6

2 Answers2

1

SymPy automatically distributes number*addition, like 9*(9*q + 10) into 81*q + 90. factor uses a trick to prevent this automatic simplification (basically, Mul(9, 9*q + 10, evaluate=False)).

There is an open issue to remove this automatic simplification, but it hasn't been implemented yet.

asmeurer
  • 75,821
  • 22
  • 150
  • 217
  • Thank you for your help. Do you have any ideia on how I could verify whether an input string is totally factored or not? – user2905179 Feb 16 '16 at 14:13
  • I think the only way is to check if `factor(expr) == expr`. – asmeurer Feb 16 '16 at 15:44
  • Yes, but it doesn't work in cases like this: `factor(81*q + 90) == 9*(9*q + 10)` – user2905179 Feb 17 '16 at 11:10
  • If you are starting out with expr as a string you can use `sympify(string, evaluate=False)` to convert it to an expression without distributing the constants (or any other evaluation). – asmeurer Feb 17 '16 at 16:46
0

From docs

You may do as below:

factor(81*q + 90).equals(9*(9*q + 10))
Prokhozhii
  • 369
  • 3
  • 10