Define the following four rational numbers. $$ a = \frac{4243257079864535154162785598448178442416}{41016602865234375} \\ b = -\frac{143308384621912247542172258992236503771301}{1210966757832031250} \\ c = \frac{350687399375274064088342133116344593437371021}{4109863607096484375000} \\ d = -\frac{762284492856611655417326017768244278005511063}{12085448243163671875000} $$ Let $$ p = \frac{501}{10}, \qquad m = \frac{499}{10}. $$ Compute $$ \mathrm{Result} = a \cos [p] + b \cos [m] + c \sin [p] + d \sin [m]. $$ Each term in this sum is roughly $10^{23}$. There is a curious cancellation (using 40 digits) happening amongst these four terms; the correct answer is $\mathrm{Result}=7.32 \times 10^{-18}$.
My question: Where does this cancellation come from, analytically? Can you massage the terms into a form where the cancellation is manifest, and machine precision can evaluate the answer with a semblance of accuracy?
(If you're curious, the result came from the analytic integral of a highly oscillatory function.)