# Mathematical Constants

My mathematical constants project is a library of C++ templates that work to calculate certain mathematical constants. I use Boost for mathematical functions (such as the Riemann zeta function) and basic constants (such as $$\pi$$). The list of mathematical constants is from this website.

Programs are tested on Linux and compiled with g++ version 7.3.1. I recommend compiling with the -O3 flag. The library has been tested with C++17, C++14, and C++11. To call a constant, use the following syntax:

• constant::constant_name<T>() for most constants (ex: constant::euler_mascheroni<double>()
• constant::func::champernowne<T>(b) and constant::func::favard<T>(r) for Champernowne and Favard constants

All constants have been verified to be accurate to 100 digits with two digits of rounding error, except the following constants:

• Gauss constant: 1 extra digit error
• Niven constant: 3 extra digits error
• Sierpinski constant K: 2 extra digits error
• Sierpinski constant S: 1 extra digit error
• Weierstrass constant: 1 extra digit error

To avoid rounding error, increase the accuracy of your type. Rounding error does not increase linearly, but rather sub-linearly: going from 100 to 500 digits of accuracy does not quintuple the rounding error, instead it goes from 2 digits to 3 for most constants. Most constants extend to many digits of accuracy without issue, except the Alladi-Grinstead constant, which becomes very slow at higher accuracy (greater than ~100).

I use Catch for unit testing, and Valgrind for memory leak checking.

##  The Constants 

Equation used: $$c=\sum_{n=1}^{\infty}\frac{\zeta(n+1)-1}{n}$$

• $$\zeta(z)$$ is the Riemann zeta function;

Limited by the size of $$n$$: std::size_t.

#### Apéry's constant — A002117, MathWorld, Wiki

Equation used: $$\zeta(3)$$

• $$\zeta(z)$$ is the Riemann zeta function;

#### Buffon's constant — A060294

Equation used: $$\frac{2}{\pi}$$

#### Catalan's constant — A006752, MathWorld, Wiki

Equation used: $$G=\frac{1}{8}\left(\psi_1(\frac{1}{4})-\pi^2\right)$$

• $$\psi_1(z)$$ is the Trigamma function;

#### Champernowne constants $$C_b$$ — MathWorld, Wiki

Equation used: $$f(b)=C_{b}=\sum_{n=1}^{\infty}\frac{n}{b^{n+\sum_{k=1}^{n}\lfloor\log_{b}k\rfloor}}$$

Default argument is $$b=10$$. Limited by the size of $$n$$ and $$k$$: std::size_t.

#### Delian constant — A002580, MathWorld, Wiki

Equation used: $$\sqrt[3]{2}$$

#### $$e$$ (Euler's number, Napier's constant) — A001113, MathWorld, Wiki

Formal equation: $$e=\sum_{n=0}^{\infty}\frac{1}{n!}$$

Instead used: boost::math::constants::e.

#### Erdős-Borwein constant — A065442, MathWorld, Wiki

Equation used: $$E=\sum_{n=1}^{\infty}\frac{1}{2^n-1}$$

Limited by the size of $$n$$: std::size_t.

#### Euler-Mascheroni constant — A001620, MathWorld, Wiki

Formal equation: $$\gamma=\lim_{n\rightarrow \infty}\left(-\ln n+\sum_{k=1}^{n}\frac{1}{k}\right)$$

Instead used: boost::math::constants::euler.

#### Favard Constants $$K_r$$ — MathWorld, Wiki

Formal equation: $$K_r=\frac{4}{\pi}\sum_{k=0}^{\infty}\left[\frac{(-1)^k}{2k+1}\right]^{r+1}$$

Instead used: \begin{align}&f(r)=K_r=\begin{cases}\frac{4}{\pi}\lambda(r+1)&\text{if }r\text{ is odd}\\\\\frac{4}{\pi}\beta(r+1)&\text{if }r\text{ is even}\end{cases}\\\\&\lambda(s)=(1-2^{-s})\zeta(s)\\\\&\beta(s)=\frac{(-2)^{-2s}}{\Gamma(s)}\left[\psi^{(s-1)}\left(\frac{1}{4}\right)-\psi^{(s-1)}\left(\frac{3}{4}\right)\right]\end{align}

• $$\lambda(z)$$ is the Dirichlet lambda function;
• $$\beta(z)$$ is the Dirichlet beta function;
• $$\zeta(z)$$ is the Riemann zeta function;
• $$\Gamma(z)$$ is the Gamma function;
• $$\psi^{(m)}(z)$$ is the Polygamma function;

Default parameter is $$r=2$$.

#### Gauss' constant — A014549, MathWorld, Wiki

Equation used: $$G=\frac{\Gamma(\frac{1}{4})^2}{2\sqrt{2}\pi^{3/2}}$$

• $$\Gamma(z)$$ is the Gamma function;

#### Gelfond-Schneider constant — A007507, MathWorld, Wiki

Equation used: $$2^\sqrt{2}$$

#### Gelfond's constant — A039661, MathWorld, Wiki

Equation used: $$e^\pi$$

#### Gieseking's constant — A143298, MathWorld

Equation used: $$G=\frac{9-\psi_1(\frac{2}{3})+\psi_1(\frac{4}{3})}{4\sqrt{3}}$$

• $$\psi_1(z)$$ is the Trigamma function;

#### Glaisher-Kinkelin constant — A074962, MathWorld, Wiki

Formal equation: $$A=e^{\frac{1}{12}-\zeta'(-1)}$$

• $$\zeta'(z)$$ is the derivative of the Riemann zeta function;

Instead used: boost::math::constants::glaisher.

#### Golden ratio — A001622, MathWorld, Wiki

Equation used: $$\phi=\frac{1+\sqrt{5}}{2}$$

#### $$i$$ (Imaginary unit, as a complex conjugate) — MathWorld, Wiki

Formal equation: $$i=\sqrt{-1}$$

Instead used: std::complex<T>(0,1).

#### Inverse golden ratio (golden ratio conjugate) — A094214, MathWorld, Wiki

Equation used: $$\Phi=\frac{1}{\phi}=\frac{2}{1+\sqrt{5}}$$

#### Khinchin's constant — A002210, MathWorld, Wiki

Formal equation: $$K_0=\prod_{n=1}^{\infty}\left[1+\frac{1}{n(n+2)}\right]^{\log_2n}$$

Instead used: boost::math::constants::khinchin.

#### Khinchin-Lévy constant — A100199, MathWorld, Wiki

Equation used: $$\beta=\frac{\pi^2}{12\ln{2}}$$

#### Kinkelin constant — A084448

Equation used: $$K=\frac{1}{12}-\log{A}$$

• $$A$$ is the Glaisher–Kinkelin constant;

#### Knuth's random-generators constant — A156309

Equation used: $$\frac{1-\frac{1}{\sqrt{3}}}{2}$$

#### Lévy's constant — A086702, MathWorld, Wiki

Equation used: $$\gamma =e^{{\pi ^{2}/(12\ln 2)}}$$

#### Lieb's square ice constant — A118273, MathWorld, Wiki

Equation used: $$\frac{8\sqrt{3}}{9}$$

#### Loch's constant — A086819, MathWorld, Wiki

Equation used: $$\frac{6\ln(2)\ln(10)}{\pi^2}$$

#### Niven's constant — A033150, MathWorld, Wiki

Equation used: $$C=1+\sum_{j=2}^{\infty}\left(1-\frac{1}{\zeta(j)}\right)$$

• $$\zeta(z)$$ is the Riemann zeta function;

Limited by the size of $$j$$: std::size_t.

#### Norton's constant — A143304, MathWorld

Equation used: $$B = -\frac{\pi^2-6\log(2)(-3+2\gamma+\log(2)+24\log(A)-2\log(\pi)))}{\pi^2}$$

• $$\gamma$$ is the Euler-Mascheroni constant;
• $$A$$ is the Glaisher–Kinkelin constant;

#### Omega constant — A030178, MathWorld, Wiki

Equation used: \begin{align}&\omega_0=0\\&\omega_{n+1}=\omega_n-\frac{\omega_ne^{\omega_n}-1}{e^{\omega_n}+\omega_ne^{\omega_n}}\end{align}

• $$\omega$$ is estimated through successive approximation using Halley's method;

#### One — MathWorld, Wiki

Equation used: $$1$$

#### Pi ($$\pi$$, Archimedes' constant) — A000796, MathWorld, Wiki

Formal equation: $$\pi=\frac{C}{d}$$

• $$C$$ is a circle's circumference;
• $$d$$ is the same circle's diameter;

Instead used: boost::math::constants::pi.

#### Plastic number — A060006, MathWorld, Wiki

Equation used: $$\rho=\frac{\sqrt[3]{108+12\sqrt{69}}+\sqrt[3]{108-12\sqrt{69}}}{6}$$

#### Pogson's ratio — A189824, MathWorld, Wiki

Equation used: $$100^{1/5}$$

#### Polya's random-walk constant $$p(3)$$ — A086230, MathWorld

Equation used: \begin{align}&u(3) = \frac{\sqrt{6}}{32\pi^3}\Gamma\left(\frac{1}{24}\right)\Gamma\left(\frac{5}{24}\right)\Gamma\left(\frac{7}{24}\right)\Gamma\left(\frac{11}{24}\right)\\&p(3) = 1 - \frac{1}{u(3)}\end{align}

• $$\Gamma(z)$$ is the Gamma function;

#### Porter's constant — A086237, MathWorld

Equation used: $$C=\frac{6\ln2(48\ln A-\ln2-4\ln\pi-2)}{\pi^2}-\frac{1}{2}$$

• $$A$$ is the Glaisher–Kinkelin constant;

#### Prince Rupert's cube constant — A093577, MathWorld, Wiki

Equation used: $$\frac{3\sqrt{2}}{4}$$

#### Pythagoras' constant — A002193, MathWorld, Wiki

Equation used: $$\sqrt{2}$$

#### Robbins constant — A073012, MathWorld, Wiki

Equation used: $$\Delta(3)=\frac{4+17\sqrt{2}-6\sqrt{3}-7\pi}{105}+\frac{\ln(1+\sqrt{2})}{5}+\frac{2\ln(2+\sqrt{3})}{5}$$

#### Sierpinski constant K — A062089, Wiki

Equation used: $$K=\pi\ln\left(\frac{4\pi^3e^{2\gamma}}{\Gamma(\frac{1}{4})^4}\right)$$

• $$\gamma$$ is the Euler-Mascheroni constant;
• $$\Gamma(z)$$ is the Gamma function;

#### Sierpinski constant S — A241017, MathWorld

Equation used: $$S=\ln\left(\frac{4\pi^3e^{2\gamma}}{\Gamma(\frac{1}{4})^4}\right)$$

• $$\gamma$$ is the Euler-Mascheroni constant;
• $$\Gamma(z)$$ is the Gamma function;

#### Silver ratio — A014176, MathWorld, Wiki

Equation used: $$\delta_{S}=1+\sqrt{2}$$

#### Theodorus' constant — A002194, MathWorld, Wiki

Equation used: $$\sqrt{3}$$

#### Twenty-Vertex entropy constant — A104956, MathWorld

Equation used: $$\frac{3\sqrt{3}}{2}$$

#### Weierstrass constant $$\frac{1}{2}\sigma(1|1,i)$$ — A094692, MathWorld

Equation used: $$\frac{1}{2}\sigma(1|1,i)=\frac{2^{5/4}\sqrt{\pi}e^{\pi/8}}{\Gamma\left(\frac{1}{4}\right)^2}$$

• $$\sigma(z|\omega_1,\omega_2)$$ is the Weierstrass sigma function;
• $$\Gamma(z)$$ is the Gamma function;

#### Wyler's constant — A180872, MathWorld

Equation used: $$\alpha_W=\frac{9}{8\pi^4}\left(\frac{\pi^5}{1920}\right)^{1/4}$$

#### Zero — MathWorld, Wiki

Equation used: $$0$$

##  The Unfinished Constants 

• Artin's constant
• Backhouse constant
• Inverse of Backhouse constant
• Barban's constant
• Bernstein's constant
• Besicovitch constant
• Blazys constant
• Boling's constant
• Brun's constant B2
• Brun's constant B4
• Brun's constant B'4
• Cahen's constant
• Copeland-Erdös constant
• Conway's constant
• Dottie number
• Efimov's scaling constant
• Embree-Trefethen constant
• Feigenbaum reduction parameter α
• Feigenbaum bifurcation velocity δ
• Feller-Tornier constant
• Flajolet-Odlyzko constant
• Foias constant
• Foias-Ewing constant
• Fransén-Robinson constant
• Gauss-Kuzmin-Wirsing constant
• Gerver's moving sofa constant
• Gibbs constant G
• Wilbraham-Gibbs constant G'
• Golomb–Dickman constant
• Gompertz constant
• Graham's constant G(3)
• Grossman's constant
• Heath-Brown–Moroz constant
• Kempner-Mahler number
• Kolakoski constant
• Komornik-Loreti constant
• Landau-Ramanujan constant
• Lagrange numbers
• Laplace limit constant
• Linnik's constant
• Liouville's constant
• Meissel-Mertens constant
• Mills' constant
• Minkowski-Bower constant
• MRB constant
• Oscillatory-integral MRB constant, modulus
• Oscillatory-integral MRB constant, real part
• Oscillatory-integral MRB constant, imag part
• Murata's constant
• Odlyzko-Wilf constant
• Otter's constant
• Otter's asymptotic constant βu
• Otter's asymptotic constant βr
• Plouffe's constant
• Prévost's constant
• Reciprocal even Fibonacci constant
• Reciprocal odd Fibonacci constant
• Rényi's parking constant
• Salem number
• Sarnak's constant
• Schwarzschild constant
• Shall-Wilson constant
• Soldner's constant