1
$\begingroup$

I'd like my expressions like A^d get interpreted as MatrixPower[A, d] for matrix arguments A, any suggestions how to do this?

$\endgroup$
  • 3
    $\begingroup$ Power (^) is a built-in symbol. My suggestion: Don't mess with built-in symbols. You will be happier in the long run if you don't. $\endgroup$ – Henrik Schumacher Sep 23 at 0:53
  • $\begingroup$ Yes, I'm aware this may break some things $\endgroup$ – Yaroslav Bulatov Sep 23 at 1:15
9
$\begingroup$

One way to do it is to use Notation package.

Needs["Notation`"]

distinguishMatrixPowerAndPower[A_, d_] := 
 If[SquareMatrixQ[A], MatrixPower[A, d], Power[A, d]]

Notation[A_^d_\[DoubleLongRightArrow]distinguishMatrixPowerAndPower[A_,d_]] (* this line is inserted using Notation Palette. *)

This is the result:

In[]:= {{1, 1}, {1, 2}}^2

Out[]= {{2, 3}, {3, 5}}

In[]:= 5^2

Out[]= 25
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.