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 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]

Instead of

(* 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

share|improve this question
3  
Simplify[expr, Assumptions -> {x > 0}, ExcludedForms -> {_Log}] --- makes you wish Refine had the same option :) –  kguler Aug 23 at 14:55
    
... maybe something like Refine[expr /. Log -> log, x > 0] /. log -> Log? –  kguler Aug 23 at 14:59

2 Answers 2

up vote 8 down vote accepted

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] *)
share|improve this answer

With V10 we can write

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

Refine[expr, x > 0] // Activate

enter image description here

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]

enter image description here

Activate[%, Sin]

enter image description here

Another advantage is that - different from kguler's nice answer - the above examples don't have to distinguish Simplify from Reduce.

share|improve this answer
2  
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 at 16:00

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.