4
$\begingroup$

This question already has an answer here:

I am trying to understand how assumptions and simplification works with this simple example:

x+y=5, assume x = 2y

So I write:

Assuming[x == 2y, Simplify[x+y==5]]

And the result makes sense to me:

3y == 5

But then if want to do

x+y=5, assume y = 2x

and I write:

Assuming[y == 2x, Simplify[x+y==5]]

I get:

x+y==5

when I should be getting:

3x==5

Why?

Update: I know this works: Simplify[x + y == 5] /. y -> 2 x what I want to understand is why Assuming does what it does: Am I using it wrong somehow?

I now tried: Assuming[q == 2 p, Simplify[p + q == 5]] vs Assuming[p == 2 q, Simplify[p + q == 5]] same issue, I am starting to wonder if it has something to do with alphabetical order of the name of the variables.

$\endgroup$

marked as duplicate by Luxspes, Community Apr 15 '18 at 23:16

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ Simplify measures "simplicity" via the measure Simplify`SimplifyCount[expr]. None of the three expressions is simpler than the other by this measure. So any of the three answers would be acceptable to Simplify. (It is odd that in one case the original is chosen and in the other, the equivalent is.) $\endgroup$ – Michael E2 Apr 15 '18 at 22:31
  • $\begingroup$ Interesting, thanks for commenting, to be clear, this is not the only case Assuming acts weirdly, this is just the simplest example I could come up with $\endgroup$ – Luxspes Apr 15 '18 at 22:56
  • $\begingroup$ I guess there is something else to it, otherwise there would be no difference between in the output of the 2 assumptions $\endgroup$ – Luxspes Apr 15 '18 at 23:02
  • $\begingroup$ I tried Reduce and the following happens. This command Assuming[y == 2 x, Reduce[x + y == 5]] // Simplify does not give anything, while this one again gives the correct result Reduce[x + y == 5] /. y -> 2 x // Simplify. Can it have to do with replacement rules by Mma? $\endgroup$ – Konstantinos Apr 15 '18 at 23:07
1
$\begingroup$

As @Michael E2 points out, your results have equal complexity according to Mathematica's default metric. When there's more than one answer, which one Mathematica chooses may depend on its canonical ordering of expressions. You can get it to prefer to eliminate symbols by defining your own ComplexityFunction.

cf[e_] := Count[e, _Symbol, All]

But then:

Assuming[y == 2 x, Simplify[x + y == 5, ComplexityFunction -> cf]]
(* 3 y == 10 *)

It seems to implicitly prefer y to x, presumably because y comes later in the alphabet.

$\endgroup$
0
$\begingroup$

ComplexityFunction can help:

Assuming[y == 2 x, 
 Simplify[x + y == 5, 
  ComplexityFunction ->
   (Simplify`SimplifyCount[#] + 2 Length@Variables[# /. Equal -> List] &)]]
(*  3 y == 10  *)
$\endgroup$
  • $\begingroup$ It's 3x==5 or 6x==3y==10. $\endgroup$ – Carl Woll Apr 15 '18 at 22:45
  • $\begingroup$ @CarlWoll Thanks, I think I thought I was doing x == 2 y.... $\endgroup$ – Michael E2 Apr 15 '18 at 22:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.