5
$\begingroup$

Is there a way to change operator precedence for built-in symbols?

I'd like \[TensorProduct] (which I redefine to KroneckerProduct) to take precedence after dot, so that the following is true

A.B\[TensorProduct]C.D == (A.B)\[TensorProduct](C.D)
$\endgroup$
4
  • 1
    $\begingroup$ Related: 140609. People tend to suggest workarounds rather than actual ways to change operator precedence. Edit You might give TensorProduct a HoldAll attribute and define downvalues (to TensorProduct) when a Dot object appears in TensorProduct. $\endgroup$
    – jjc385
    Apr 19, 2017 at 16:24
  • 1
    $\begingroup$ Also, how exactly do you redefine \[TensorProduct] to KroneckerProduct? $\endgroup$
    – jjc385
    Apr 19, 2017 at 16:35
  • $\begingroup$ I do TensorProduct=KroneckerProduct $\endgroup$ Apr 19, 2017 at 20:14
  • $\begingroup$ How about using CircleTimes = KroneckerProduct and then A.B\[CircleTimes]C.D $\endgroup$
    – chuy
    Apr 20, 2017 at 16:46

1 Answer 1

7
$\begingroup$

If you enter \[TensorProduct] using the input alias t*, then you can override the input alias to produce a TemplateBox with a SyntaxForm setting to lower the precedence:

CurrentValue[EvaluationNotebook[], {InputAliases,"t*"}]=TemplateBox[
    {},
    "TensorProduct",
    DisplayFunction->("\[TensorProduct]"&),
    InterpretationFunction:>(Sequence["~","TensorProduct","~"]&),
    SyntaxForm->"*"
];

Your example (as an image to show the alias in action):

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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