The observations I made I got from messing around with Unevaluated, Trace, Hold and FullForm.
My intuition was that we could make get the same behavior of Sqrt for numbers as for Symbols using Unevaluated. However, there is a a rule for Sqrt[anything] that must look like this
HoldPattern[Sqrt[anything_]]:> Power[anything, Rational[1,2]]
So an Unevaluated on an argument of Sqrt will just get cleared by this rule. So we have to look at Power instead.
Now, this observation seems crucial. It appears there is a rule that looks like this
Clear[power]
power[power[x_, y_] /;
And[IntegerQ[x], IntegerQ[y]], d_] :=
power["power"[x, y], d]
Where I use the string "power" to avoid that the results of examples satisfy this rule again. If you are used to using Unevaluated, you will know that Unevaluated only gets stripped if a rule is applied. Now we can test if there is really such a rule (you can also verify this using Trace and asking the FullForm's of intermediate expressions you surround with Hold, but it is easier to use Unevaluated). This shows the rule in action:
Power[Unevaluated[Power[3, 4]], d]
-> 81^d
whereas
Power[Unevaluated[Power[3, a]], d]
-> Power[Unevaluated[Power[3, a]], d]
So in the first case, a rule was applied, whereas in the second case there was no rule applied. To see that the test really involves IntegerQ and not NumberQ (or something), note that
Power[Unevaluated[Power[3., 4]], d]
-> Power[Unevaluated[Power[3., 4]], d]
We can see that my symbol power behaves in the same way for the three examples
power[Unevaluated[power[3, 4]], d]
-> power[power[3, 4], d]
(where we have to imagine that "power"[3,4] just evaluates to 81).
power[Unevaluated[power[3., 4]], d]
-> power[Unevaluated[power[3., 4]], d]
and
power[power[3, a]], d]
-> power[power[3, a]], d]
Now, lets get back to your problem. In your example, as Sqrt does not have Hold attributes, -3^2 immediately gets evaluated to 9 and there is no fun. However, using all this knowledge about Unevaluated, we can now do the following
Unprotect[Power]
Power[Power[a_, 2] /; a < 0, Rational[1, 2]] := a
So that
Sqrt[Unevaluated[Unevaluated[(-3)^2]]]
-> -3
Which I think is very nice :).
With respect to consistency... Sqrt could have been given the attribute HoldAll. It could have been made so that it would pass its argument to Power with a wrapper Unevaluated. And a rule could have been implemented like the one for Power I defined above. But I guess it would just be confusing, as none of the other "basic functions" (Times Plus Divide etc) have such attributes and they don't pass ever pass the head Unevaluated.
Remarks: Related Mathematica rules
I also found a rule in MMA which may lead to more insight into how MMA handles this kind of expression. We have
Trace[Power[Unevaluated[Power[Times[-1, q], 4]], d],
TraceOriginal -> True][[4]] // FullForm
-> HoldForm[Power[Power[Times[-1, q], 4], d]]
But
Power[Unevaluated[Power[Times[-1, a], 3]], d]
-> Power[Unevaluated[Power[Times[-1, a], 3]], d]
This appears to be the result of a rule like this
power[power[times[x_, a_], y_] /; And[x == -1, EvenQ[y]], d_] :=
power[power[times[x, a], d]]
I also found some other related rules, but I cannot say more about those yet.
Actually, I now find the subject extremely interesting, as it seems that MMA is using rules of a form that I haven't seen yet. MMA seems to have some very abstract rule for handling cases like the following
Power[Unevaluated[
Power[Power[Power[Power[Power[Times[1, a1], a2], a3], a4], a5],
a6]], a7]
-> Power[Power[Power[Power[Power[Power[a1,a2],a3],a4],a5],a6],a7]
It would seem that here that there is a rule at work that can deal with very deep nesting. If you are interested, please look at my question here
Sqrt
is a (single-valued) function. It returns the principal square root, which is a (complex) number with a nonnegative real part. Note thatSqrt[x^2]
remains unevaluated. But, for instance,Simplify[Sqrt[x^2], Re[x] < 0]
returns-x
(only). $\endgroup$Sqrt[]
was always intended to be a function. One input, one output. Mathematica conveniently happens to use the principal branch. $\endgroup$Sqrt[x^2]
not returnAbs[x]
?" - wild guess, but maybe, just maybe, because of things likeSqrt[(3 + 4 I)^2]
not being equal toAbs[3 + 4 I]
? $\endgroup$