Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is Right.

NestWhile[Log, 100, # > 1 &]
{100} //. {x_} /; x > 1 :> {Log[x]}
100. //. x_ /; x > 1 :> Log[x]

This is wrong,why?

100 //. x_ /; x > 1 :> Log[x]

enter image description here

share|improve this question
up vote 7 down vote accepted

The reason your final form fails is that ReplaceRepeated will replace deeper parts of the expression when the first pattern test fails. Like this:

Log[Log[Log[100]]] /. x_ /; x > 1 :> flag[x]

You'll get a similar (though not identical) error message from this:

Nest[Log, 100, 50] > 1;

Greater::nord: Invalid comparison with Log[Log[Log[Log[Log[Log[Log[Log[<<1>>]]]]]]]] attempted. >>

After Log is nested five times you get the I Pi term seen in your original message:

 Nest[Log, 100, 5]
I π + Log[-Log[Log[Log[Log[100]]]]]
share|improve this answer
Right, and Log[100.] evaluates so it has no deeper pieces. – rcollyer Jan 9 '14 at 14:48

Your Answer


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.