# How to make TransformationFunctions work with Simplify

Here is a transformation function that replaces f with a polynomial:

expansion = Function[# /. f[a_, b_, c_] :>
Expand[a^2 + b^2 + c^2 - 2 a b - 2 a c - 2 b c]];


As you can see, applying expansion on the following expression leads to a simplification:

expr = (x^2 - y^2 + z)^2 - f[x^2, y^2, z];

expr // expansion // Simplify

(*4 x^2 z*)


Question: However, adding expansion to TransformationFunctions doesn't work (why not?):

Simplify[expr, TransformationFunctions->{Automatic, expansion}]

(x^2 - y^2 + z)^2 - f[x^2, y^2, z]


Note: I compared the built-in ComplexityFunction for the two forms, and made sure the 4 x^2 z indeed is simpler:

SimplifyCount[(x^2 - y^2 + z)^2 - f[x^2, y^2, z]]
SimplifyCount[4 x^2 z]

(*25*)
(*6*)


I must not done something correctly. Help please?

• FullSimplify[expr, TransformationFunctions -> {Automatic, expansion}] gives the answer 4 x^2 z immediately. – andre314 Dec 18 '15 at 17:52
• g[a_, b_, c_] := a^2 + b^2 + c^2 - 2 a b - 2 a c - 2 b c expr = (x^2 - y^2 + z)^2 - g[x^2, y^2, z] // Simplify; Simplify[expr, TransformationFunctions -> {Automatic, expansion}]. I think this works. – Diogo Dec 18 '15 at 18:31
• @QuantumDot, this works Simplify[h[x], TransformationFunctions -> ((# /. h[a_] :> 1 a) &)], but this does not Simplify[h[x], TransformationFunctions -> ((# /. h[a_] :> 2 a) &)]. Looks like a bug? – garej Dec 19 '15 at 22:12