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!

  • $\begingroup$ 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! $\endgroup$
    – Michael E2
    Jan 25, 2019 at 2:47

2 Answers 2


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

  • $\begingroup$ 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. $\endgroup$
    – Thomas
    Jan 28, 2019 at 1:31
  • 1
    $\begingroup$ I've worked it out now: dualE /: Power[dualE, n_] := 0 /; n>=2 does the trick! $\endgroup$
    – Thomas
    Jan 28, 2019 at 3:09

This way:

$Post = MatrixFunction[
      Function[ε, #], {{0, 0}, {1, 0}}] /. {{a_, 
        b_}, {0, a_}} -> 
      a + ε b /. {{a_, 0}, {b_, a_}} -> 
     a + ε b &;


The following variants will also work (and better):

$Post=Normal[Series[#, {ε, 0, 1}]]&;


$Post=(#/.ε->0)+ε(D[#, ε]/.ε->0)&;

(the last method is the most universal)

Use this way:


 Out:= 1 + (I ε Pi)/2

 In:=Log[a + ε]

 Out:=ε/a + Log[a]

 In:=f[a + b ε]

 Out:=f[a] + b ε f'[a]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.