Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
add comment

1 Answer 1

up vote 3 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
add comment

Your Answer

 
discard

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.