4

I have a variable (say, e) that can assume only the values $1$ or $-1$. My calculations are extensive and if I introduce the symbol e to represent these possible values ($1$ or $-1$), I get an output with several powers of e.

I can, of course, after the calculation is done, simplify the result through a list that replace the even powers of e by $1$, and the odd powers by e. However, I would like instead to define a symbol e so that Mathematica understands (automatically, even in the middle of its calculations) that e^2 is 1 and e^3 == e (etc.).

In other words, I want Mathematica to treat e in the same manner as it treats the imaginary number I, except that e^2 == 1 instead of $-1$ (etc.) Is that possible in Mathematica or in Maple? Thanks.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
R. Vieira
  • 43
  • 2

1 Answers1

12

A quick way is to use TagSet[] and TagSetDelayed[] to teach Power[] how to deal with your special symbol:

e /: e^0 = 1;
e /: e^1 = e;
e /: e^(n_Integer) := e^Mod[n, 2]

Thus:

Table[e^k, {k, 0, 5}]
   {1, e, 1, e, 1, e}
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574