Issue with Upvalues
How about the following?:
Clear[ext, extc]
ext /: ext[n_] extc[m_] := extc[m - n]
ext /: ext[n_] ext[m_] := ext[m + n]
extc /: extc[n_] extc[m_] := extc[m + n]
ext /: Conjugate@ext[n_] := extc[n]
extc /: Conjugate@extc[n_] := ext[n]
extc[n_?Negative] := ext[-n]
ext[n_?Negative] := extc[-n]
extc[0] = 1;
ext /: Power[ext[m_], n_] := ext[m n]
extc /: Power[extc[m_], n_] := extc[m n]
$Pre = # &;
patt = Except[Clear | ClearAll | Remove];
ext /: (h : patt)[a___, ext, b___] := h[a, ext@1, b]
extc /: (h : patt)[a___, extc, b___] := h[a, extc@1, b]
Format@ext[n_] := EXt^n
Format@extc[n_] := EXtC^n
Example:
ext
(* EXt *)
ext^2 extc^3
(* EXtC *)
ext extc^n // Conjugate
(* EXt^(-1 + n) *)
Here's a variation of @xzczd's idea, using only a single symbol and adding formatting:
Clear[ext]
ext[n_] ext[m_] ^:= ext[n+m]
ext[n_]^m_ ^:= ext[n m]
Conjugate[ext[n_]] ^:= ext[-n]
ext[0] = 1;
MakeBoxes[ext[n_],StandardForm]:=Switch[Unevaluated @ n,
0, "1",
1, MakeBoxes[EXt],
-1, MakeBoxes[EXtC],
_Integer?Negative, With[{s=-n}, MakeBoxes[EXtC^s]],
_, MakeBoxes[EXt^n]
]
For example:
EXt = ext[1]
EXtC = ext[-1]
EXt
EXtC
And:
EXt^2 EXtC^2
EXt^2 EXtC^3
EXt EXtC^n //Conjugate
1
EXtC
EXt^(-1 + n)