1
$\begingroup$

I'm using strings as symbolic notation for non-commutative linear algebra and need to be able to concatenate without losing ordering and without combining the strings (in order to apply rules I've defined), like this:

a = {"X","Y","Z"}

b = {"I","J","K"}

Command[a,b] -> {"X""I","Y""J","Z""K"}
Command[b,a] -> {"I""X","J""Y","K""Z"}

The closest I've gotten so far is the following:

stringJoin[x__String] := StringJoin[x]
SetAttributes[stringJoin, Listable]
n=stringJoin[a,b]
m=stringJoin[b,a]

Output: n = {"XI","YJ","ZK"} , m = {"IX","JY","KZ"}

$\endgroup$
  • 1
    $\begingroup$ Possible approach: SetAttributes[CircleTimes, Listable]; Format[CircleTimes[a_, b_], StandardForm] := DisplayForm@RowBox[{a, b}]. Usage: {"a", "b", "c"}\[CircleTimes]{"u", "v", "w"}. $\endgroup$ – user31159 Jun 15 '16 at 15:46
  • 2
    $\begingroup$ You can use NonCommutativeMultiply. $\endgroup$ – march Jun 15 '16 at 16:13

Your Answer

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

Browse other questions tagged or ask your own question.