# function for toggling a symbol inside a FullForm

Hello I would like to build a function for the hermitic conjugation of f[i]. When applied to f[i], it should result in f\[Dagger][i], and when applied to f\[Dagger][i], it should result in f[i], where i is some integer. How could I do that please ?

Thank you.

• Do you mean conjugate transpose, Hermitian conjugate, Hermitian adjoint? What would the function be operating on? Have you tried anything at all? Give us some more detail. – MarcoB Apr 22 '16 at 15:29
• To answer MarcoB: All I need is the symbolic manipulation mentioned in my post. f[i] is an abstract object (second quantization operator). All I need is to toggle the \[Dagger] part of the FullForm. In case you wonder why, I am trying to use the package DiracQ for quantum calculations, but it lacks this simple formal operation. – cipocip Apr 22 '16 at 16:07

I'm not familiar with the package you using, but if by "toggling the \[Dagger]" you mean converting the expression f[i] to (f^\[Dagger])[i], which is equivalent to SuperDagger[f][i], then you need to define something like this:

Dagger[f_] := Operate[SuperDagger, f]
SuperDagger[SuperDagger[x_]] := x


Never mind, I figured it out, converting the argument to String and using StringReplace and RegularExpression inside a Module to toggle the dagger symbol.

Example code:

    ToManipString[a_] := ToString[FullForm[ToBoxes[a]]];
BackToExpres[a_] :=
ReleaseHold[MakeExpression[ToExpression[a], StandardForm]];

Dag[a_] :=
Module[{},
newstr = BackToExpres[
StringReplace[
ToManipString[a], {"\"\\[Sigma]\"" -> "\"\[Sigma]\[Dagger]\"",
"\"b\"" -> "\"b\\[Dagger]\""}]];
If[newstr ==
a, {newstr =
BackToExpres[
StringReplace[
ToManipString[a], {"\"\\[Sigma]\\[Dagger]\"" -> "\"\[Sigma]\"",
"\"b\\[Dagger]\"" -> "\"b\""}]]}, newstr];


This version works for "b" and "sigma" operators multiplied by symbolic stuff, like sqrt(2).

• You might consider including code in your answer to be useful to others as well. – J. M. will be back soon Apr 23 '16 at 11:46
• I suggest that you post some background on what you want to achieve... I am pretty confident that there is a better way to do what you want – sebhofer Aug 21 '16 at 17:14