3
Unprotect[Power];
Power[0, 0] = 1;
Protect[Power];
Unprotect[Dot];
Dot[x_, y_?NumberQ] := x y;
Dot[x_?NumberQ, y_] := x y;
Protect[Dot];
$Post = # /. f_[{x__}] :> MatrixFunction[f, {x}] &;
Sqrt[( {
    {-1, 0},
    {0, -1}
   } )] // MatrixForm

The output comes in list form, not as a matrix.

Anixx
  • 3,585
  • 1
  • 20
  • 32

2 Answers2

1

You only need the last 2 lines to reproduce the issue, and the last 2 lines can be further simplified to

$Post = # /. f_[{x__}] :> aaa[f, {x}] &;
{{-1, 0}, {0, -1}} // MatrixForm
(* aaa[MatrixForm, {{-1, 0}, {0, -1}}] *)

As we can see, the rule in $Post is executed later than MatrixForm i.e. the code above is amount to

$Post =.;
{{-1, 0}, {0, -1}} // MatrixForm // (# /. f_[{x__}] :> aaa[f, {x}] &)

This is consistent with the description in the document of $Post:

$Post is a global variable whose value, if set, is applied to every output expression.

See also the introduction in the tutorial The Main Loop.

xzczd
  • 65,995
  • 9
  • 163
  • 468
0

Consider the full form your your evaluated expression:

Sqrt[({{-1, 0}, {0, -1}})] // MatrixForm //FullForm

enter image description here

This matches your pattern:

 f_[{x__}]

With f == MatrixForm and {x_} == {{-1, 0}, {0, -1}}

Therefore, the matrix representation is changed into:

MatrixFunction[Sqrt, {{-1, 0}, {0, -1}}]

and this evaluates into:

{{I, 0}, {0, I}}
Daniel Huber
  • 51,463
  • 1
  • 23
  • 57