Mathematical Constants

Source »

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.

Program was tested with g++. 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:

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

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.

The Constants

Alladi-Grinstead constant A085291, MathWorld

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

Limited by the size of \(n\): std::size_t.

Apéry's constant A002117, MathWorld, Wiki

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

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)$$

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}$$

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}}$$

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}}$$

Glaisher-Kinkelin constant A074962, MathWorld, Wiki

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

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}$$

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)$$

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}$$

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}$$

One MathWorld, Wiki

Equation used: \(1\)

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

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

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}$$

Porter's constant A086237, MathWorld

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

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)$$

Sierpinski constant S A241017, MathWorld

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

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}$$

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