internals – Protecting symbols against redefinition by Mathematica?


Just spent an hour to isolate my crashes to the following unintuitive behavior. SemidefiniteProgramming redefines the $otimes$ symbol…but only the first time it is called. I’ve been using this symbol for my Kronecker products to keep implementations small.

Is there some way I can get an error or warning when Mathematica redefines my symbols? Alternatively, is there another symbol that I should perhaps use instead of $otimes$ to avoid this?

This is for Mathematica 12.1.0.0 on Mac.

Unprotect(TensorProduct);
TensorProduct = KroneckerProduct;
Protect(TensorProduct);
ii = IdentityMatrix(2);

Print(ii(TensorProduct)ii); (* prints {{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}} *)
SemidefiniteOptimization(x, {x > 0}, {x});
Print(ii(TensorProduct)ii); (* prints {{{{1,0},{0,1}},{{0,0},{0,0}}},{{{0,0},{0,0}},{{1,0},{0,1}}}} *)
```