I am very new using Mathematica and I would like to define a rule of replacement which operates as below, keeping freedom for what concern the pre-factors that can appear in the equation: $$e^{\pm ix} \to \delta(\pm x).$$

ruleInt = {Exp[I A___ x] -> DiracDelta[A x] }

but it works with the plus, not with the minus sign and it does not work with any other symbol, such as a number or a variable. I also tried to write my string A followed by one or two or underscores, but actually I am not able to control it as it is not clear the difference between those possibilities. The Wolfram manual was of any help.

Can you help me with this?


  • $\begingroup$ Welcome to Mathematica.SE! 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 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$ – user9660 Oct 28 '15 at 17:37
  • 1
    $\begingroup$ But $\delta (+x) = \delta (-x)$. $\endgroup$ – David G. Stork Oct 28 '15 at 17:49
  • $\begingroup$ Yes David, it has to be meant symbolically. I had in mind cases such as: $$ e^{i (\epsilon- \pm \epsilon^'}t}->\delta(\epsilon \pm \epsilon').$$ I intentionally omitted it to focus on the generic nature of the symbol I wanted to appear there. $\endgroup$ – MKO876 Oct 29 '15 at 9:53

When you used the term "my string A" in the question that is not quite the correct nomenclature. A is what is known as a named pattern.

At the moment, ruleInt does not need curly brackets (although there is also no harm).

ruleInt = Exp[I A___ x] -> DiracDelta[A x]

Let's try your rule on the following test cases.

{Exp[-4 I], Exp[I x], Exp[2 x I], Exp[-2 x I], Exp[a x I], 
  Exp[-a x I]} /. ruleInt

with the result

Mathematica graphics

It works on the second and fifth elements of the list.

It is very helpful when making replacement rules to look at the FullForm of expressions. Indeed the full form is the syntax that is actually used when performing replacements.

FullForm[Exp[-4 I]]

Power[E, Complex[0,-4]]

FullForm[Exp[I x]]

Power[E, Times[Complex[0,1],x]

FullForm[Exp[2 x I]]

Power[E, Times[Complex[0,2],x]

FullForm[Exp[-2 x I]]

Power[E, Times[Complex[0,-2],x]

FullForm[Exp[a x I]]

Power[E, Times[Complex[0,1],a,x]

FullForm[Exp[-a x I]]

Power[E, Times[Complex[0,-1],a,x]

Observe that Times only occurs when a symbol is present. This suggest modify ruleInt to take into account two cases (now we will use the curly brackets).

   Power[E,Times[Complex[0,x_?NumberQ],y__]]->DiracDelta[x y]}

Now apply it to the original test.

{Exp[-4 I], Exp[I x], Exp[2 x I], Exp[-2 x I], Exp[a x I], 
  Exp[-a x I]} /. ruleInt2


Mathematica graphics

Now a symbolic DiracDelta is the output for all tests with the exception of the first one. Since this is entirely numeric the computed result it output.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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