Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I provide a custom function in TransformationFunctions options of FullSimplify that can do a transformation only for some values of its argument. What is the proper way to bail out from the function and instruct FullSimplify to skip this transformation for the current argument when the transformation is not applicable to it?

share|improve this question
up vote 4 down vote accepted

I usually set up a wrapper function that transforms if input is valid and otherwise acts like Identity:

pickyTransform[expr_] := 0

helper[expr_] /; ! AtomQ[expr] && FreeQ[expr, _?NumericQ] := pickyTransform[expr] 
helper[expr_] := expr

FullSimplify[a^3 + x^y, TransformationFunctions -> {helper}]
(* a^3 *)

This works fine most of the time, but in more annoying cases where the transformation function can be smart about expressions of the form Thing + x_ * AnotherThing even if x by itself would be considered non-applicable it can be useful to replace all non-applicable subexpressions with something inert and simplify that before replacing the inert subexpressions back to their original form.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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