The following is a well-known Bessel function identity:

$$J_{-n}(z)=(-1)^n J_n(z),\qquad n\in\mathbb Z$$

To check this, I used the following code and the result is as what I expected.

In[2]:= FullSimplify[(-1)^n*BesselJ[n, z] == BesselJ[-n, z], n ∈ Integers]
Out[2]= True

The problem is that Mathematica does not return zero when I try to simplify the following expression:

$$(-1)^n J_{n}(z)-J_{-n}(z),\qquad n\in\mathbb Z$$

I tried the following code, but the output is as complex as the input:

In[3]:= FullSimplify[(-1)^n*BesselJ[n, z] - BesselJ[-n, z], n ∈ Integers]
Out[3]= -BesselJ[-n, z] + (-1)^n BesselJ[n, z]    (*result I expected : 0*)

My goal is to command Mathematica to reduce the expression to zero, and I need some advice.


2 Answers 2

FullSimplify[(-1)^n*BesselJ[n, z] - BesselJ[-n, z],  n ∈ Integers, 
             ComplexityFunction -> (StringLength @ ToString @ # &)]


ComplexityFunction -> (Count[#, _BesselJ | _Power, {-2}] &)
ComplexityFunction -> (Count[#, _?NumberQ, Infinity] &)
  • 3
    $\begingroup$ I daresay it is baffling that the usual approach of comparing LeafCount[]s doesn't work... $\endgroup$ May 15, 2013 at 16:50
  • $\begingroup$ @J.M. ComplexityFunction -> (StringLength @ ToString @ # & could be useful at the code golf site $\endgroup$ May 15, 2013 at 17:59
  • 1
    $\begingroup$ Actually, I don't know what (StringLength @ ToString @ # &) means. Nonetheless, I got some clues from looking at the other two options. The options you suggested are quite informative and could be utilized in many similar situations. $\endgroup$
    – Tom Wayne
    May 16, 2013 at 8:41
  • $\begingroup$ @Tom, it simply treats the expression being applied to as a string, and counts the number of characters in said string. $\endgroup$ May 16, 2013 at 11:19
  • $\begingroup$ @J.M. Now I got it. That's quite a compact form. $\endgroup$
    – Tom Wayne
    May 17, 2013 at 14:02

A bit of cheating:

DifferenceRootReduce[(-1)^n BesselJ[n, z] - BesselJ[-n, z], n]

I must admit I'm not sure why FullSimplify[] fails on this, tho.

  • $\begingroup$ Very nice. $\phantom{}$ $\endgroup$ May 15, 2013 at 15:50
  • 2
    $\begingroup$ That's a brilliant answer. Still, it's a mystery why FullSimplify doesn't work on this expression. $\endgroup$
    – Tom Wayne
    May 15, 2013 at 16:10

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.