# Make ConjugateTranspose distributive

Related to 123974, is there a way to make the ConjugateTranspose function, input as esc-hc-esc distributive for all symbols? For example, with d = (a + b)/Sqrt[2], I want d\[HermitianConjugate] give $(a^\dagger+b^\dagger)/\sqrt{2}$. I can define

hc[x__Plus] := Plus @@ (ConjugateTranspose /@ (List @@ x))

which only takes care of terms like hc[a+b] bit not for more complicated expressions.

• Have you looked at Distribute? Commented Feb 21, 2018 at 10:09
• @SjoerdSmit yes, Distribute works for e.g. a+b but not, say, (a+b)/2 Commented Feb 21, 2018 at 15:26

How does this work for you?

ConjugateTranspose[d] //. {
ConjugateTranspose[(op : (Plus | Times))[a__]] :> op @@ (ConjugateTranspose /@ {a}),
ConjugateTranspose[NonCommutativeMultiply[a__]] :> NonCommutativeMultiply @@ (ConjugateTranspose /@ Reverse[{a}]),
ConjugateTranspose[n_?NumericQ] :> Conjugate[n]
}

Essentially, this uses ReplaceRepeated to implement the algebraic rules of ConjugateTranspose: it falls through addition and (scalar) multiplication; it turns numbers into their conjugates; and it falls through non-commutative multiplication but reverses the order of multiplication.

• works for me, thanks a lot! Commented Feb 21, 2018 at 15:27
• also added rule: ConjugateTranspose[ConjugateTranspose[a__]] :> a so that $(a^\dagger)^\dagger=a$. Commented Feb 21, 2018 at 15:55
• Oh, it doesn't do that by itself? Well, seems sensible to me, then. I would change the matching pattern to ConjugateTranspose[ConjugateTranspose[a_]], though, since ConjugateTranspose should never have more than one argument in the first place. Commented Feb 21, 2018 at 16:19
• good, point, thanks again! Commented Feb 21, 2018 at 16:25