Ask Your Question

Expand cos(2*pi/n) for n=5, 17, 257, 65537 to Radicals (Fermat prime numbers)

asked 2023-11-26 14:01:11 +0100

geroyx gravatar image

updated 2023-11-27 11:28:22 +0100

I want to expand $\cos\left( \dfrac{2\pi}{n} \right)$ for $n=5,~17,~ 257, 65537$ to radicals, for example: $\cos\left( \dfrac{2\pi}{5} \right) =\frac14 \sqrt{5} -\frac14$

BTW: These $n$ are Fermat prime numbers, see Exact trigonometric values.

Is this a possible task?

x = var('x')
test = (x+1)^2 # test
test.expand() # works :)

term = cos(2*pi/5)
term.expand() # works :)

term = cos(2*pi/17)
term.expand() # works not :(

PS: I tried



as well.

edit retag flag offensive close merge delete


GAP's package radiroot can do that - see

Max Alekseyev gravatar imageMax Alekseyev ( 2023-11-26 14:22:34 +0100 )edit

@Max Alekseyev I'm asking in the here about a solution with SageMath / Python. The fact that there are basically programs that can do this is another topic. Thank you anyway.

geroyx gravatar imagegeroyx ( 2023-11-26 14:35:16 +0100 )edit

GAP is naturally accessible from within Sage - see

Max Alekseyev gravatar imageMax Alekseyev ( 2023-11-26 14:49:53 +0100 )edit

@Max Alekseyev Oh, I am sorry. 1) Can I use this when using online 2) Could you give me a simple syntax example (including this library)?

geroyx gravatar imagegeroyx ( 2023-11-26 14:57:47 +0100 )edit

2 Answers

Sort by » oldest newest most voted

answered 2023-11-27 09:06:44 +0100

Sébastien gravatar image

Using the method radical_expression for algebraic real field element, you can sometimes obtain a result. Its doc says Attempt to obtain a symbolic expression using radicals. If no exact symbolic expression can be found, the algebraic number will be returned without modification:

sage: AA
Algebraic Real Field
sage: AA(cos(2*pi/5)).radical_expression()
1/4*sqrt(5) - 1/4
sage: AA(cos(2*pi/7)).radical_expression()
(7/144*I*sqrt(3) + 7/432)^(1/3) + 7/36/(7/144*I*sqrt(3) + 7/432)^(1/3) - 1/6

But it does not work for n=17 and n=257:

sage: AA(cos(2*pi/17)).radical_expression()
sage: AA(cos(2*pi/257)).radical_expression()
edit flag offensive delete link more

answered 2023-11-26 18:28:58 +0100

Max Alekseyev gravatar image

updated 2023-11-27 02:21:29 +0100

Here in a sample code using GAP's RadiRoot package that works for $n=5$ and $n=17$. It produces the result in the form of a LaTeX file. For $n=257$, it gives an error Transitive groups of degree 128 are not available, while for $n=65537$ it goes into lengthy calculations (I was not patient enough to wait for an answer).

n = 5
f = cos(2*pi/n).minpoly()
x = f.variables()[0]
gap.eval(f'{x} := Indeterminate( Rationals, "{x}" );')
assert gap.eval(f'IsSolvablePolynomial({f});')     # necessary condition
fname = gap.eval(f'RootsOfPolynomialAsRadicals( {f}, "latex" );').strip('"')
with open(fname) as file:
    for line in file:
edit flag offensive delete link more


Thx. Works fine for n=17; but not for n=5 or n=257... (at my cocalc).

geroyx gravatar imagegeroyx ( 2023-11-26 19:02:36 +0100 )edit

@Max Alekseyev Did you test this with your code?

geroyx gravatar imagegeroyx ( 2023-11-26 21:52:35 +0100 )edit

See updated answer.

Max Alekseyev gravatar imageMax Alekseyev ( 2023-11-27 01:51:52 +0100 )edit

I think, if it can't calc for the Fermat prime $n=257$, it wont be able to calc for the Fermat prime $n=65537$.

geroyx gravatar imagegeroyx ( 2023-11-27 09:58:52 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2023-11-26 14:01:11 +0100

Seen: 118 times

Last updated: Nov 27 '23