# Why does Simplify ignore an assumption?

Here is the example:

Simplify[x + y, x + y == a]
Simplify[x + y, x + y == 5]


Mathematica 9 output:

x+y
5


I expect the complexity of a to be lower than complexity of Plus[x,y], and the result of the first line should be a.

Even if I specify ComplexityFunction explicitly:

Simplify[x + y, x + y == a, ComplexityFunction -> LeafCount]


I still get x+y as a result. It's however obvious that LeafCount[x+y] is greater than LeafCount[a].

Why does Simplify ignore x+y==a but uses x+y==5? How can I define the former assumption in a right way?

• It is interesting that Simplify[x y, x y == a] returns a. Jan 17, 2013 at 1:48
• As does Simplify[x^2+y^2,x^2+y^2==a], and Simplify[x+y,x+y==Cos[a]] returns Cos[a] Jan 17, 2013 at 2:03
• ... and, Simplify[x + y, x + y == Unevaluated[a]]  gives a...?
– kglr
Jan 17, 2013 at 2:09
• Simplify[x+y, x+y == boo[]] also gives boo[]. Strange. Jan 17, 2013 at 2:15
• It's something I've seen posted before, but can't find. It has to do with the fact that Simplify seems to have a preference for alphabetical order in sums. So you can get the expected result by replacing a with any symbol that lexically comes after x and y. For example, use Simplify[x + y, x + y == xPlusY] or just Simplify[x + y,x + y==z]. It probably tries substitutions not in all permutations but only in alphabetical order when sums are involved.
– Jens
Jan 17, 2013 at 7:21

We can see from the examples in the comments to the question that Simplify (and FullSimplify which builds on it) doesn't try all permutations of substitutions. That's probably justified in general to keep the computational effort from exploding, but in your example it leads to the quirky behavior that the variable names affect the result of the simplification.

For example, you get

Clear[a, z];
Simplify[x + y, x + y == a]

(* ==> x + y *)

Simplify[x + y, x + y == z]

(* ==> z *)


The only difference is that the last assumption uses a variable name that comes lexically after the names which you would like to replace.

I think the reason for this is that Mathematica tries substitutions in sums only in a specific sequence dictated by the alphabetical order of the variables it encounters.

My heuristic conclusion from this would be that assumptions in which you would like variables to be substituted by new names should have the new names chosen such that they come lexically after the "old" names.

If this doesn't work for you, the best alternative would be to do the elimination explicitly using Eliminate.

Here's a little tool from Adam Strzebonski that deals with the issue that Jens describes.

VOISimplify[vars_, expr_, assum_: True] :=
Module[{perm, ee, best}, perm = Permutations[vars];
ee = (FullSimplify @@ ({expr, assum} /. Thread[vars -> #])) & /@ perm;
best = Sort[Transpose[{LeafCount /@ ee, ee, perm}]][];


Now:

VOISimplify[{a, x, y}, x + y, x + y == a]

a

• It looks like WRI is aware of this strange behavior for already seven years. Here is the link Jan 20, 2013 at 1:26
{"ft_lang_label":"__label__en","ft_lang_prob":0.7365318,"math_prob":0.984051,"size":1169,"snap":"2023-40-2023-50","text_gpt3_token_len":356,"char_repetition_ratio":0.1776824,"word_repetition_ratio":0.07936508,"special_character_ratio":0.28999144,"punctuation_ratio":0.13438736,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99853426,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-09-27T19:32:58Z\",\"WARC-Record-ID\":\"<urn:uuid:bfca20b0-0854-4878-924d-fac88dc2593d>\",\"Content-Length\":\"184836\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:41ec5318-80b2-4426-ace4-a167f0c7eed1>\",\"WARC-Concurrent-To\":\"<urn:uuid:39a55789-c933-49cd-9d22-d8f7a74021ec>\",\"WARC-IP-Address\":\"104.18.11.86\",\"WARC-Target-URI\":\"https://mathematica.stackexchange.com/questions/17926/why-does-simplify-ignore-an-assumption?noredirect=1\",\"WARC-Payload-Digest\":\"sha1:D7UNCE5TPH5GWU6IAFUIDCWSQRHMYDF6\",\"WARC-Block-Digest\":\"sha1:VXJS3VMTWSDKM2JUBG46DAOYZDMBX72Q\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233510319.87_warc_CC-MAIN-20230927171156-20230927201156-00470.warc.gz\"}"}