# Finding integer solutions for trigonometric equation $8\sin^2\left(\frac{(k+1)\pi}{n}\right)=n\sin\left(\frac{2\pi}{n}\right)$

I thought up the problem of finding a regular $n$-sided polygon that has a diagonal with lenght $d_k$ such that the area of the polygon equals ${d_k}^2$. By doing some easy trigonometry within the polygon I got the equation $$8\sin^2\left(\frac{(k+1)\pi}{n}\right)=n\sin\left(\frac{2\pi}{n}\right).$$ Where $d_k$ is the length of the diagonal which skips $k$ vertices. (So $d_0$ is just the length of one side.)

I have checked some values of $n$ and it seems that $(4,0)$ and $(12,3)$ are the only (primitive and non-trivial) possible values for $(n,k)$.

But how can I verify whether this is true?

-
maple found for $n \le 100$ only solutions for which $n=4,12$. For $n=4$ we have $k=0,2,4,6,...$ while for $n=12$ we have $k=3,7,15,19,...$ the pattern repeating mod 12. –  coffeemath Jan 25 at 13:49
Perhaps squaring both sides and then using an automorphism approach similar to math.stackexchange.com/questions/235658/… works. If this method works out I'll post a follow-up answer but unfortunately I don't have time right now to try it. –  dinoboy Jan 25 at 17:12
I think the solutions $(12,3)$ and $(12,7)$ are the same, just going opposite ways around. Similarly, $(4,0)$ is one side and $(4,2)$ is the other side. Based on your original problem, you demand $k \le n-2$ and solutions $k$ and $n-2-k$ are equivalent. –  Ross Millikan Mar 28 at 16:48

(4,0) and (12,3) are the only "primitive and non-trivial" solutions $(n,k)$ with $n\leq 10^5$.

Considering the symmetries that are present both in your geometry question and in the resulting equation, let a "primitive and non-trivial" solution be a pair $(n,k)$ with $n,k\in \mathbb{Z}$, $n\geq 3$, and $0\leq k \leq n/2 - 1$, satisfying$$8\sin^2\left(\frac{(k+1)\pi}{n}\right)=n\sin\left(\frac{2\pi}{n}\right).$$ The fact that $k$ can be restricted to a finite interval for each $n$ opens the problem up for a direct numerical search. Here's my implementation in PARI/GP:

N_MIN=3;
N_MAX=100000;
N_BLOCKSIZE=100;
TOLERANCE=1e-20;

\\ We express the problem in terms of m,n, where m=k+1.
\\ We only call the (slow) sin function once for each computation of the LHS.
lhs(m,n)={sqrt_lhs=sin(m*Pi/n); sqrt_lhs*sqrt_lhs;}
rhs(n)=sin(2*Pi/n)*n/8;

\\ Check m,n for |LHS-RHS| < TOLERANCE
for(n=N_MIN,N_MAX,cur_rhs=rhs(n); if(n%N_BLOCKSIZE==0,printf("# Done checking all n<%u\n", n)); for(m=1,n/2,{
cur_lhs=lhs(m,n);
if(abs(cur_lhs-cur_rhs)<TOLERANCE, printf("%u\t%u\t%e\n", n, m-1, cur_lhs-cur_rhs))
}));
quit


Note: If I'm not mistaken, this is guaranteed to find all solutions $(m,n)$ with $n<n_\max = 10^5$, even though floating point math is used (assuming there are no bugs in PARI/GP or my computer). The point is that PARI/GP claims a default precision of 38 decimal digits, while the tolerance for root-finding in the above code is equivalence to 20 decimal digits. If you calculate the error propagation assuming 38-digit precision for the sin functions, the maximum absolute error after the few arithmetic operations per $n,m$ pair is still on the order of $10^{-38}$. The code can in principle give false positives if the RHS and LHS aren't equal but happen to be within the tolerance of one another, but it can't give false negatives. (In fact for these parameters there were no false positives, either.)

Update: Here is an implementation in C using 128-bit floating point arithmetic:

#include <stdio.h>

// To compile: gcc -O3 -std=c99 -lquadmath trig.c -o trig

#define M_2PIq 6.2831853071795864769252867665590058q

#define N_MIN 3
#define N_MAX 2000
#define N_BLOCKSIZE 100
#define TOLERANCE 1e-20q
#define DIGITS 35

int main(){

// We express the problem in terms of m,n, where m=k+1.
for(unsigned n=N_MIN; n<=N_MAX; n++){

// Print out a status update each N_BLOCKSIZE iterations.
if(n%N_BLOCKSIZE==0) printf("# Done checking all n<%u\n", n);

// Compute the RHS only once per n
__float128 cur_rhs = sinq(M_2PIq/n)*n/8.0q;
for(unsigned m=1; 2*m<=n; m++){

// We only call the (slow) sin function once for each computation of the LHS.
__float128 cur_lhs=sinq(m*M_PIq/n);
cur_lhs*=cur_lhs;

// Print out (n,k) if a solution is found
if( fabsq(cur_lhs-cur_rhs) < TOLERANCE ){
char str_difference[DIGITS];