# Implementing Dual Unit from Dual Numbers

I'm trying to implement the dual unit $$\epsilon$$ defined by $$\epsilon^2 = 0$$ into Mathematica but I'm having trouble defining $$\epsilon^n = 0$$ for $$n\geq 2$$. In this answer they simply use dualE /: Power[dualE, 2] := 0 which works well for $$n=2$$ but not for any other $$n\geq 2$$. I've tried

dualE /: Power[dualE, n] := If[n>=2, 0, dualE^n]

but then I just get $$\epsilon^n = \epsilon^n$$ for any $$n$$. I can also define the function

Nilpotent[dualE, n] := If[n>=2, 0, Power[dualE, n]]

which then gives Nilpotent[dualE, n] = 0 for $$n\geq 2$$, but if I try

dualE /: Power[dualE, n] := Nilpotent[dualE, n]

this still doesn't give the desired result for $$\epsilon^{n\geq 2}$$! As a last ditch effort I tried Table[dualE /: power[dualE, n] := 0, {n, 2, 100}]; which at least gives $$\epsilon^n = 0$$ for $$2\leq n \leq 100$$ but still evaluates to $$\epsilon^n$$ for any non-integer values of $$n$$.

There must be a way to define $$\epsilon^{n\geq2}=0$$ and $$\epsilon^{n<2}=\epsilon^n$$ properly so any help would be much appreciated!

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Jan 25 at 2:47

You have to use a pattern _ for the second argument; moreover, it might also be a good idea to ensure that n is an integer.

dualE /: Power[dualE, n_Integer /; n >= 2] := 0


Now things seem to work:

(1 + dualE)^2 // Expand


1 + 2 dualE

• Thanks, that's great for integer values of n. Can I make it so it works for non-integer values of n too? E.g. dualE^(5/2) = 0. – Thomas Jan 28 at 1:31
• I've worked it out now: dualE /: Power[dualE, n_] := 0 /; n>=2 does the trick! – Thomas Jan 28 at 3:09