# How to overload the operator “*” as KroneckerProduct [closed]

Can I use the expression below

a * b * c * d

KroneckerProduct[a,b,c,d]

automatically when a,b,c,d are matrix.

The number of elements (a,b,c,d) is arbitrary,
such as a*b, a*b*c and a*b*c*d*e*f all can work well.

It seems overriding the operator * in Mathematica is not a good method. And my special applicaon that importing expressions from external file in string format has some others ways.

=================

=================

1

=================

It was clarified in comments that expressions are supposed to be read into Mathematica from a text file. To achieve what OP wants one can read the file as list of held expressions, perform appropriate replacements, then release hold.

If we have a test.txt file with following contents:

a * b * c * d
a^dag

We can read it in following way:

% /. {Times -> KroneckerProduct, x_^dag :> ConjugateTranspose[x]} // ReleaseHold
(* {HoldComplete[a b c d], HoldComplete[a^dag]} *)
(* {KroneckerProduct[a, b, c, d], ConjugateTranspose[a]} *)

If we have more control over format of this text file and can accept non-ASCII characters, then we could use operators without builtâ€in meaning, as already suggested in comments. With unicode.txt file:

a âŠ— b âŠ— c âŠ— d
a^â€

we could do this:

% /. {
CircleTimes -> KroneckerProduct,
x_^\[Dagger] :> ConjugateTranspose[x]
} // ReleaseHold
(* {a âŠ— b âŠ— c âŠ— d, a^â€ } *)
(* {KroneckerProduct[a, b, c, d], ConjugateTranspose[a]} *)

That doc page link is so useful. Thank you jkuczm!
– matheorem
Sep 25 at 1:34