# How to find the sum with Mathematica?

That hard problem was invented by V. P. Beshkarev (Russia) in 1971:

Sum[Tan[(4*j - 3)*Pi/180], {j, 1, 45}] // FullSimplify


The result should be 45, but the command is running on my comp without any output for hours. I know its tricky calculation by hand which cannot be mimicked with Mathematica.

• N[Sum[Tan[(4*j - 3)*Pi/180], {j, 1, 45}]] gives 45. – Carl Lange Feb 7 at 20:02
• @Carl Lange: Up to a certain precision, is not so? Did you carefully read the question and its tags? – user64494 Feb 7 at 20:04
• Sorry, it's not clear to me what you're expecting as a result except "The result should be 45". Why do you expect FullSimplify to do anything in this case? – Carl Lange Feb 7 at 20:11
• @Carl Lange: A simpler problem of such type is Sum[j,{j,1,100}], where the result should be 5050, not 5050.0 . Hope I am clear now. – user64494 Feb 7 at 20:14
• @CarlLange I guess, it is only about challenging Mathematica's symbolic capabilities. – Henrik Schumacher Feb 7 at 20:27

Sometimes the easiest approach is to just divide it up into steps and see which transformations can be done reasonably quickly. First, I define the expression:

expr = Sum[Tan[(4*j - 3)*Pi/180], {j, 1, 45}];


Verify its result numerically:

N[expr]


45.

This is likely, but not necessarily, exact. Thus, the strategy will be trying to prove that some transformation of expr - 45 is 0 exactly. Since expr is primarily trigonometric, there's a few functions that come to mind immediately. TrigExpand does not evaluate quickly, but TrigToExp shows a fairly self-similar form of a group of fractions. I find fractions usually become easier to work with after Apart, and it turns out that transformation is also reasonably quick. However, after Apart the numbers do not precisely add up to anything specific, so the 45 would seem to be a residual effect of several independent parts of this expression.

At this point I tried to see if Simplify could sort it out:

Simplify[Apart[TrigToExp[expr]] - 45]


0

Which is an exact result, though derived through somewhat convoluted means, which shows that expr == 45 exactly, so long as no errors occurred during TrigToExp and Apart, which are both supposed to be complex safe.

• Sorry, but the code suggested by you is running without any output on my comp during several minutes. The same issue with Apart[TrigToExp[expr]] too. I will try to execute your code in cloud. – user64494 Feb 7 at 20:37
• It takes about 5 seconds on an i7 4770K on Mathematica 10.1. It takes about 8.4 on a fresh start of 11.2 for me as well. Not a super easy computation, so I wouldn't be surprised if it takes a little bit, but I'd expect it to take less than 2 minutes on most machines. – eyorble Feb 7 at 20:40
• Reproduced in Mathematica online in 6 s.. Simply and strongly. – user64494 Feb 7 at 20:47
• Hm. I am very curious. I am on version 11.3 on a 4980HQ (so the single-thread performance should be very similar to the 4770K) and this computation takes 47 seconds (returning the correct result). That's significant slow-down... – Henrik Schumacher Feb 7 at 21:21
• @HenrikSchumacher on the cloud it takes like 90s – b3m2a1 Feb 8 at 0:01
Sum[Tan[(4*j - 3)*Pi/180], {j, 1, 45}] // RootReduce

(* 45 *)

• +1. It is unclear to me how it works. – user64494 Feb 8 at 3:50
• @user64494 - Mostly only people at Wolfram know "how it works". It is one of the functions like Simplify, FullSimplify, ComplexExpand, TrigReduce, etc. that are used to find alternate forms of expressions. Experimentation is often required to find which one or which combination is best for a given expression. – Bob Hanlon Feb 8 at 4:16