# Mean distance to the centroid of a regular n-gon of circumradius R.
import numberdb.sage as numberdb
from sage.rings.real_arb import RealBallField

def mean_regular_polygon(n, R=1, digits=100):
    if n < 3:
        raise ValueError("n must be at least 3")
    F = RealBallField(numberdb.bits(digits, losing=80))
    theta = F.pi()/n
    h = F(R)*theta.cos()
    return h/3*(1/theta.cos()
                +(1/theta.cos()+theta.tan()).log()/theta.tan())

print(mean_regular_polygon(6))
