How to Overload Times and Plus for Matrix Multiplication in Math

I want to reload Times, and Plusfor matrix multiplication in math, for example, let Timesthe BE BitAnd, and Plus is the BE BitOr, and then multiply the matrix.

Is there a way to do this in a simple way without rewriting your own matrix multiplication?

Thank.

+3
source share
1 answer

The question is what you want to change - the behavior Timesand Plus, or Dot. Generally, a trick is Blockoften the easiest way. In this case, since it Dotdoes not call higher-level Plusor Times, you can do:

mat1 = {{1,2},{3,4}};
mat2= {{5,6},{7,8}};
Block[{Dot = Inner[BitAnd,#1,#2,BitOr]&},
  mat1.mat2]

{{3,0},{5,2}}

, ( Inner) - , Dot Plus Times.

+4

All Articles