# Detecting operator Set in Assumptions

Here is a typical issue: Simplify[x + y, x = y] produces 2 True.

Is there a way to detect operator Set in assumptions and issue a warning?

Update: As Mr.Wizard suggested it is possible to write a wrapper for Simplify that will check the second argument. But since there are many built-in functions which use assumptions it will be cumbersome to overload them all. Maybe there is a more simple way?

-
Look up $Pre and $PreRead – R. M. Jan 24 '13 at 23:32
rm-rf gave you the best advice I think. Consider putting some function in $Pre which checks for whatever list of patterns you create of stuff you want to be warned about. – Rojolalalalalalalalalalalalala Jan 25 '13 at 2:17 ## 2 Answers I'm not sure I understand the spirit of your question. My apologies of this answer is obvious to you and you intended something else. Simplify::badSet = "Function Set used in assumptions where is likely in error."; SetAttributes[mySimplify, HoldAll]; mySimplify[expr_, assum_] := Message[Simplify::badSet] /; ! FreeQ[Unevaluated@assum, Set] mySimplify[else__] := Simplify[else]  Now: mySimplify[x + y, x = a]  Simplify::badSet: Set used in assumptions where is likely in error. >> You could overload Simplify itself if you are comfortable with such things. You'll want to be familiar with the Villegas-Gayley method of you choose that path. - This made me think about SyntaxInformation's "ColorEqualSigns" option, only to find that it isn't working (on my system, v8 or v9) other than for the first argument – Rojolalalalalalalalalalalalala Jan 25 '13 at 0:02 Try "ColorEqualSigns" /. SyntaxInformation /@ {And, For, Implies, Nand, Nor, Not, Or, Which, Xor}. +1 btw. In >v8 that gives {All, {2, 2}, All, All, All, All, All, Odd, All}. Try it with a custom function, it doesn't work either – Rojolalalalalalalalalalalalala Jan 25 '13 at 0:03 @Rojo same result in v7: {All, {2, 2}, All, All, All, All, All, Odd, All} – Mr.Wizard Jan 25 '13 at 0:09 And it also doesn't work? And[x=4, y=6] only colours red the first =? – Rojolalalalalalalalalalalalala Jan 25 '13 at 0:23 @Rojo sorry; that's the same too. – Mr.Wizard Jan 25 '13 at 0:25 @rm-rf suggested somtething along these lines I believe $cancelOnSyntaxError = False;

syntaxCheckingRules = {i : HoldPattern[Simplify[_, _ = _]] :>
"Equal in " <> ToString@HoldForm@i};

fixRules[lhs_ :> rhs_] :=
lhs :> Block[{}, (Print@rhs; dontEval = True) /; True];

$Pre = Function[code, Block[{dontEval = False}, Unevaluated[code] /. fixRules /@ syntaxCheckingRules; If[! dontEval || !$cancelOnSyntaxError, code, \$Canceled]
], HoldAllComplete];


Too add more checks, append to syntaxCheckingRules the pattern of the syntax error and the string you want to be displayed as output.

With that set

Simplify[2, x = 4]


prints a warning message

-