Skip to main content
Avoid evaluation leak
Source Link
Carl Woll
  • 131.7k
  • 6
  • 246
  • 359

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[n=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)

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[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)

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)

Fix typo
Source Link
Carl Woll
  • 131.7k
  • 6
  • 246
  • 359

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[n,
    0, "1",
    1, MakeBoxes[EXt],
    -1, MakeBoxes[EXtC],
    _Integer?Negative, With[{s=-n}, MakeBoxes[EXtC^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)

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[n,
    0, "1",
    1, MakeBoxes[EXt],
    -1, MakeBoxes[EXtC],
    _Integer?Negative, With[{s=-n}, MakeBoxes[EXtC^n]],
    _, 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)

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[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)

Source Link
Carl Woll
  • 131.7k
  • 6
  • 246
  • 359

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[n,
    0, "1",
    1, MakeBoxes[EXt],
    -1, MakeBoxes[EXtC],
    _Integer?Negative, With[{s=-n}, MakeBoxes[EXtC^n]],
    _, 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)