# Keep Mathematica from simplifying functions with a specified Head

I want to run Simplify and/or Refine on various expressions, but keep it from touching anything that contains a specific Head.

For example, I would like to Refine the following expression under the assumption x>0 but not do anything with any part of the expression whose Head is Log:

expr = Sqrt[x^4] Log[x^2] + Log[x^4];
Refine[expr, x>0]


(* 4 Log[x] + 2 x^2 Log[x] *)


I would like to see

(* x^2 Log[x^2] + Log[x^4] *)


Where the Logarithms remain unsimplified

• Simplify[expr, Assumptions -> {x > 0}, ExcludedForms -> {_Log}] --- makes you wish Refine had the same option :) – kglr Aug 23 '14 at 14:55
• ... maybe something like Refine[expr /. Log -> log, x > 0] /. log -> Log? – kglr Aug 23 '14 at 14:59

For Simplify there is the option ExcludedForms:

expr = Sqrt[x^4] Log[x^2] + Log[x^4];
Simplify[expr, Assumptions -> {x > 0}, ExcludedForms -> {_Log}]
(* x^2 Log[x^2] + Log[x^4] *)


For Refine, you can wrap the heads to be excluded with Hold:

Refine[expr /. Log -> Hold[Log], x > 0] // ReleaseHold
(*  x^2 Log[x^2] + Log[x^4] *)


or use ReplaceAll twice

Refine[expr /. Log -> "log", x > 0] /. "log" -> Log
(*  x^2 Log[x^2] + Log[x^4] *)


With V10 we can write

expr = Sqrt[x^4] Log[x^2] + Log[x^4] /. x_Log :> Inactivate[x];

Refine[expr, x > 0] // Activate EDIT

Thanks to Chip Hurst's comment the above should, of course, be written as

expr = Inactivate[Sqrt[x^4] Log[x^2] + Log[x^4], Log]


One of the advantages of Inactivate is that we can selectively Activate:

expr = Inactivate[Sqrt[x^4] Log[x^2] + Log[x^4] + Sin[Pi/2], Log | Sin];

Activate[Refine[expr, x > 0], Log] Activate[%, Sin] Another advantage is that - different from kguler's nice answer - the above examples don't have to distinguish Simplify from Reduce.

• You could also do expr = Inactivate[Sqrt[x^4] Log[x^2] + Log[x^4], Log], instead of pattern matching yourself. – Chip Hurst Aug 23 '14 at 16:00