3
$\begingroup$

How can I make Mathematica consider Assumptions in FullSimplify also when applying custom Transformation Functions?

It works with the Automatic Transformation Functions:

FullSimplify[Sqrt[a^2], a < 0]
-a
FullSimplify[a < 0, a < 0]
True

It does not work with custom Transformation Functions:

custom Transformation function replacing negative terms by pi:

tf2[e_] := e /. a__ /; a < 0 -> π

custom complexity function making pi as a result attractive:

myCount = (-Count[#, π, {0, Infinity}]) &;


mySimplify = (FullSimplify[#, a < 0, TransformationFunctions -> {tf2},
      ComplexityFunction -> myCount]) &;

This works for numbers

mySimplify[1]

1

mySimplify[-3]

π

It does however not consider the assumption that a<0

mySimplify[a]

a

$\endgroup$
  • $\begingroup$ A bit hacky, but you could do tf2[e_] := e /. {a__ /; ToCharacterCode[ToString@a] == {97} -> Pi, a__ /; a < 0 -> Pi} I don't know why your example doesn't work though. $\endgroup$ – Feyre Jan 8 '17 at 10:36
  • $\begingroup$ O.k., but a is just an example, I want to match more complex terms later. $\endgroup$ – wolfgang6444 Jan 8 '17 at 10:45
  • 3
    $\begingroup$ I think it's a matter of mistaking how much assumptions is willing to do. After all Assuming[a < 0, TrueQ[a < 0]] doesn't work, and /; tests the truth of a condition. $\endgroup$ – Feyre Jan 8 '17 at 10:58
  • $\begingroup$ Your tf2 is not using any function using assumptions. Try tf2[e_] := e /. a_ /; Refine[a < 0] -> \[Pi] and mySimplify = Assuming[a < 0, FullSimplify[#, TransformationFunctions -> {tf2}, ComplexityFunction -> myCount]] &;. $\endgroup$ – jkuczm Apr 10 '17 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.