NMSE Section 6.1 mentioned, B

Percentage Accurate: 78.7% → 99.7%
Time: 11.1s
Alternatives: 8
Speedup: 1.9×

Specification

?
\[\begin{array}{l} \\ \left(\frac{\pi}{2} \cdot \frac{1}{b \cdot b - a \cdot a}\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right) \end{array} \]
(FPCore (a b)
 :precision binary64
 (* (* (/ PI 2.0) (/ 1.0 (- (* b b) (* a a)))) (- (/ 1.0 a) (/ 1.0 b))))
double code(double a, double b) {
	return ((((double) M_PI) / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b));
}
public static double code(double a, double b) {
	return ((Math.PI / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b));
}
def code(a, b):
	return ((math.pi / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b))
function code(a, b)
	return Float64(Float64(Float64(pi / 2.0) * Float64(1.0 / Float64(Float64(b * b) - Float64(a * a)))) * Float64(Float64(1.0 / a) - Float64(1.0 / b)))
end
function tmp = code(a, b)
	tmp = ((pi / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b));
end
code[a_, b_] := N[(N[(N[(Pi / 2.0), $MachinePrecision] * N[(1.0 / N[(N[(b * b), $MachinePrecision] - N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 / a), $MachinePrecision] - N[(1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(\frac{\pi}{2} \cdot \frac{1}{b \cdot b - a \cdot a}\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right)
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 78.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(\frac{\pi}{2} \cdot \frac{1}{b \cdot b - a \cdot a}\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right) \end{array} \]
(FPCore (a b)
 :precision binary64
 (* (* (/ PI 2.0) (/ 1.0 (- (* b b) (* a a)))) (- (/ 1.0 a) (/ 1.0 b))))
double code(double a, double b) {
	return ((((double) M_PI) / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b));
}
public static double code(double a, double b) {
	return ((Math.PI / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b));
}
def code(a, b):
	return ((math.pi / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b))
function code(a, b)
	return Float64(Float64(Float64(pi / 2.0) * Float64(1.0 / Float64(Float64(b * b) - Float64(a * a)))) * Float64(Float64(1.0 / a) - Float64(1.0 / b)))
end
function tmp = code(a, b)
	tmp = ((pi / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b));
end
code[a_, b_] := N[(N[(N[(Pi / 2.0), $MachinePrecision] * N[(1.0 / N[(N[(b * b), $MachinePrecision] - N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 / a), $MachinePrecision] - N[(1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(\frac{\pi}{2} \cdot \frac{1}{b \cdot b - a \cdot a}\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right)
\end{array}

Alternative 1: 99.7% accurate, 1.9× speedup?

\[\begin{array}{l} [a, b] = \mathsf{sort}([a, b])\\ \\ \frac{\frac{\frac{\pi}{\frac{a}{0.5}}}{b}}{a + b} \end{array} \]
NOTE: a and b should be sorted in increasing order before calling this function.
(FPCore (a b) :precision binary64 (/ (/ (/ PI (/ a 0.5)) b) (+ a b)))
assert(a < b);
double code(double a, double b) {
	return ((((double) M_PI) / (a / 0.5)) / b) / (a + b);
}
assert a < b;
public static double code(double a, double b) {
	return ((Math.PI / (a / 0.5)) / b) / (a + b);
}
[a, b] = sort([a, b])
def code(a, b):
	return ((math.pi / (a / 0.5)) / b) / (a + b)
a, b = sort([a, b])
function code(a, b)
	return Float64(Float64(Float64(pi / Float64(a / 0.5)) / b) / Float64(a + b))
end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
	tmp = ((pi / (a / 0.5)) / b) / (a + b);
end
NOTE: a and b should be sorted in increasing order before calling this function.
code[a_, b_] := N[(N[(N[(Pi / N[(a / 0.5), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision] / N[(a + b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\frac{\frac{\pi}{\frac{a}{0.5}}}{b}}{a + b}
\end{array}
Derivation
  1. Initial program 79.7%

    \[\left(\frac{\pi}{2} \cdot \frac{1}{b \cdot b - a \cdot a}\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. un-div-invN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{2}}{b \cdot b - a \cdot a} \cdot \left(\color{blue}{\frac{1}{a}} - \frac{1}{b}\right) \]
    2. associate-/r*N/A

      \[\leadsto \frac{\mathsf{PI}\left(\right)}{2 \cdot \left(b \cdot b - a \cdot a\right)} \cdot \left(\color{blue}{\frac{1}{a}} - \frac{1}{b}\right) \]
    3. associate-*l/N/A

      \[\leadsto \frac{\mathsf{PI}\left(\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right)}{\color{blue}{2 \cdot \left(b \cdot b - a \cdot a\right)}} \]
    4. distribute-lft-out--N/A

      \[\leadsto \frac{\mathsf{PI}\left(\right) \cdot \frac{1}{a} - \mathsf{PI}\left(\right) \cdot \frac{1}{b}}{\color{blue}{2} \cdot \left(b \cdot b - a \cdot a\right)} \]
    5. div-invN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \mathsf{PI}\left(\right) \cdot \frac{1}{b}}{2 \cdot \left(b \cdot b - a \cdot a\right)} \]
    6. div-invN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{2 \cdot \left(b \cdot b - a \cdot a\right)} \]
    7. *-commutativeN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{\left(b \cdot b - a \cdot a\right) \cdot \color{blue}{2}} \]
    8. difference-of-squaresN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{\left(\left(b + a\right) \cdot \left(b - a\right)\right) \cdot 2} \]
    9. associate-*r*N/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{\left(b + a\right) \cdot \color{blue}{\left(\left(b - a\right) \cdot 2\right)}} \]
    10. *-commutativeN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{\left(b + a\right) \cdot \left(2 \cdot \color{blue}{\left(b - a\right)}\right)} \]
    11. *-commutativeN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{\left(2 \cdot \left(b - a\right)\right) \cdot \color{blue}{\left(b + a\right)}} \]
    12. associate-/r*N/A

      \[\leadsto \frac{\frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{2 \cdot \left(b - a\right)}}{\color{blue}{b + a}} \]
    13. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{2 \cdot \left(b - a\right)}\right), \color{blue}{\left(b + a\right)}\right) \]
  4. Applied egg-rr99.6%

    \[\leadsto \color{blue}{\frac{\frac{\frac{\pi}{a} - \frac{\pi}{b}}{2 \cdot \left(b - a\right)}}{b + a}} \]
  5. Taylor expanded in a around 0

    \[\leadsto \mathsf{/.f64}\left(\color{blue}{\left(\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{a \cdot b}\right)}, \mathsf{+.f64}\left(b, a\right)\right) \]
  6. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(\frac{\mathsf{PI}\left(\right)}{a \cdot b}\right)\right), \mathsf{+.f64}\left(\color{blue}{b}, a\right)\right) \]
    2. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{PI}\left(\right), \left(a \cdot b\right)\right)\right), \mathsf{+.f64}\left(b, a\right)\right) \]
    3. PI-lowering-PI.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \left(a \cdot b\right)\right)\right), \mathsf{+.f64}\left(b, a\right)\right) \]
    4. *-lowering-*.f6499.7%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{*.f64}\left(a, b\right)\right)\right), \mathsf{+.f64}\left(b, a\right)\right) \]
  7. Simplified99.7%

    \[\leadsto \frac{\color{blue}{0.5 \cdot \frac{\pi}{a \cdot b}}}{b + a} \]
  8. Step-by-step derivation
    1. associate-*r/N/A

      \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{a \cdot b}\right), \mathsf{+.f64}\left(\color{blue}{b}, a\right)\right) \]
    2. associate-/r*N/A

      \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{a}}{b}\right), \mathsf{+.f64}\left(\color{blue}{b}, a\right)\right) \]
    3. associate-*l/N/A

      \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{\frac{1}{2}}{a} \cdot \mathsf{PI}\left(\right)}{b}\right), \mathsf{+.f64}\left(b, a\right)\right) \]
    4. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\left(\frac{\frac{1}{2}}{a} \cdot \mathsf{PI}\left(\right)\right), b\right), \mathsf{+.f64}\left(\color{blue}{b}, a\right)\right) \]
    5. clear-numN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\left(\frac{1}{\frac{a}{\frac{1}{2}}} \cdot \mathsf{PI}\left(\right)\right), b\right), \mathsf{+.f64}\left(b, a\right)\right) \]
    6. associate-*l/N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\left(\frac{1 \cdot \mathsf{PI}\left(\right)}{\frac{a}{\frac{1}{2}}}\right), b\right), \mathsf{+.f64}\left(b, a\right)\right) \]
    7. *-un-lft-identityN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{\frac{a}{\frac{1}{2}}}\right), b\right), \mathsf{+.f64}\left(b, a\right)\right) \]
    8. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{PI}\left(\right), \left(\frac{a}{\frac{1}{2}}\right)\right), b\right), \mathsf{+.f64}\left(b, a\right)\right) \]
    9. PI-lowering-PI.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \left(\frac{a}{\frac{1}{2}}\right)\right), b\right), \mathsf{+.f64}\left(b, a\right)\right) \]
    10. /-lowering-/.f6499.6%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{/.f64}\left(a, \frac{1}{2}\right)\right), b\right), \mathsf{+.f64}\left(b, a\right)\right) \]
  9. Applied egg-rr99.6%

    \[\leadsto \frac{\color{blue}{\frac{\frac{\pi}{\frac{a}{0.5}}}{b}}}{b + a} \]
  10. Final simplification99.6%

    \[\leadsto \frac{\frac{\frac{\pi}{\frac{a}{0.5}}}{b}}{a + b} \]
  11. Add Preprocessing

Alternative 2: 89.5% accurate, 1.5× speedup?

\[\begin{array}{l} [a, b] = \mathsf{sort}([a, b])\\ \\ \begin{array}{l} \mathbf{if}\;a \leq -4.4 \cdot 10^{-104}:\\ \;\;\;\;\frac{\frac{\pi}{a \cdot b}}{\frac{a}{0.5}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\pi}{b}}{a} \cdot \frac{0.5}{b}\\ \end{array} \end{array} \]
NOTE: a and b should be sorted in increasing order before calling this function.
(FPCore (a b)
 :precision binary64
 (if (<= a -4.4e-104)
   (/ (/ PI (* a b)) (/ a 0.5))
   (* (/ (/ PI b) a) (/ 0.5 b))))
assert(a < b);
double code(double a, double b) {
	double tmp;
	if (a <= -4.4e-104) {
		tmp = (((double) M_PI) / (a * b)) / (a / 0.5);
	} else {
		tmp = ((((double) M_PI) / b) / a) * (0.5 / b);
	}
	return tmp;
}
assert a < b;
public static double code(double a, double b) {
	double tmp;
	if (a <= -4.4e-104) {
		tmp = (Math.PI / (a * b)) / (a / 0.5);
	} else {
		tmp = ((Math.PI / b) / a) * (0.5 / b);
	}
	return tmp;
}
[a, b] = sort([a, b])
def code(a, b):
	tmp = 0
	if a <= -4.4e-104:
		tmp = (math.pi / (a * b)) / (a / 0.5)
	else:
		tmp = ((math.pi / b) / a) * (0.5 / b)
	return tmp
a, b = sort([a, b])
function code(a, b)
	tmp = 0.0
	if (a <= -4.4e-104)
		tmp = Float64(Float64(pi / Float64(a * b)) / Float64(a / 0.5));
	else
		tmp = Float64(Float64(Float64(pi / b) / a) * Float64(0.5 / b));
	end
	return tmp
end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (a <= -4.4e-104)
		tmp = (pi / (a * b)) / (a / 0.5);
	else
		tmp = ((pi / b) / a) * (0.5 / b);
	end
	tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function.
code[a_, b_] := If[LessEqual[a, -4.4e-104], N[(N[(Pi / N[(a * b), $MachinePrecision]), $MachinePrecision] / N[(a / 0.5), $MachinePrecision]), $MachinePrecision], N[(N[(N[(Pi / b), $MachinePrecision] / a), $MachinePrecision] * N[(0.5 / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -4.4 \cdot 10^{-104}:\\
\;\;\;\;\frac{\frac{\pi}{a \cdot b}}{\frac{a}{0.5}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\pi}{b}}{a} \cdot \frac{0.5}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -4.40000000000000023e-104

    1. Initial program 80.7%

      \[\left(\frac{\pi}{2} \cdot \frac{1}{b \cdot b - a \cdot a}\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right) \]
    2. Add Preprocessing
    3. Taylor expanded in b around 0

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{{a}^{2} \cdot b}} \]
    4. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{\color{blue}{{a}^{2} \cdot b}} \]
      2. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot \mathsf{PI}\left(\right)\right), \color{blue}{\left({a}^{2} \cdot b\right)}\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI}\left(\right)\right), \left(\color{blue}{{a}^{2}} \cdot b\right)\right) \]
      4. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI.f64}\left(\right)\right), \left({a}^{\color{blue}{2}} \cdot b\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI.f64}\left(\right)\right), \mathsf{*.f64}\left(\left({a}^{2}\right), \color{blue}{b}\right)\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI.f64}\left(\right)\right), \mathsf{*.f64}\left(\left(a \cdot a\right), b\right)\right) \]
      7. *-lowering-*.f6472.1%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI.f64}\left(\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(a, a\right), b\right)\right) \]
    5. Simplified72.1%

      \[\leadsto \color{blue}{\frac{0.5 \cdot \pi}{\left(a \cdot a\right) \cdot b}} \]
    6. Step-by-step derivation
      1. associate-*l*N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{a \cdot \color{blue}{\left(a \cdot b\right)}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{a \cdot \left(b \cdot \color{blue}{a}\right)} \]
      3. times-fracN/A

        \[\leadsto \frac{\frac{1}{2}}{a} \cdot \color{blue}{\frac{\mathsf{PI}\left(\right)}{b \cdot a}} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\frac{1}{2}}{a}\right), \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{b \cdot a}\right)}\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \left(\frac{\color{blue}{\mathsf{PI}\left(\right)}}{b \cdot a}\right)\right) \]
      6. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{PI}\left(\right), \color{blue}{\left(b \cdot a\right)}\right)\right) \]
      7. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \left(\color{blue}{b} \cdot a\right)\right)\right) \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \left(a \cdot \color{blue}{b}\right)\right)\right) \]
      9. *-lowering-*.f6483.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{*.f64}\left(a, \color{blue}{b}\right)\right)\right) \]
    7. Applied egg-rr83.8%

      \[\leadsto \color{blue}{\frac{0.5}{a} \cdot \frac{\pi}{a \cdot b}} \]
    8. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{\mathsf{PI}\left(\right)}{a \cdot b} \cdot \color{blue}{\frac{\frac{1}{2}}{a}} \]
      2. clear-numN/A

        \[\leadsto \frac{\mathsf{PI}\left(\right)}{a \cdot b} \cdot \frac{1}{\color{blue}{\frac{a}{\frac{1}{2}}}} \]
      3. un-div-invN/A

        \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a \cdot b}}{\color{blue}{\frac{a}{\frac{1}{2}}}} \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{a \cdot b}\right), \color{blue}{\left(\frac{a}{\frac{1}{2}}\right)}\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{PI}\left(\right), \left(a \cdot b\right)\right), \left(\frac{\color{blue}{a}}{\frac{1}{2}}\right)\right) \]
      6. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \left(a \cdot b\right)\right), \left(\frac{a}{\frac{1}{2}}\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{*.f64}\left(a, b\right)\right), \left(\frac{a}{\frac{1}{2}}\right)\right) \]
      8. /-lowering-/.f6483.9%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{*.f64}\left(a, b\right)\right), \mathsf{/.f64}\left(a, \color{blue}{\frac{1}{2}}\right)\right) \]
    9. Applied egg-rr83.9%

      \[\leadsto \color{blue}{\frac{\frac{\pi}{a \cdot b}}{\frac{a}{0.5}}} \]

    if -4.40000000000000023e-104 < a

    1. Initial program 79.2%

      \[\left(\frac{\pi}{2} \cdot \frac{1}{b \cdot b - a \cdot a}\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right) \]
    2. Add Preprocessing
    3. Taylor expanded in b around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{a \cdot {b}^{2}}} \]
    4. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{\color{blue}{a \cdot {b}^{2}}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{{b}^{2} \cdot \color{blue}{a}} \]
      3. associate-/r*N/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{{b}^{2}}}{\color{blue}{a}} \]
      4. associate-*r/N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{{b}^{2}}}{a} \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{{b}^{2}}\right), \color{blue}{a}\right) \]
      6. associate-*r/N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{{b}^{2}}\right), a\right) \]
      7. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{b \cdot b}\right), a\right) \]
      8. associate-/r*N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{b}}{b}\right), a\right) \]
      9. associate-*r/N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{b}}{b}\right), a\right) \]
      10. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\left(\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{b}\right), b\right), a\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(\frac{\mathsf{PI}\left(\right)}{b}\right)\right), b\right), a\right) \]
      12. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{PI}\left(\right), b\right)\right), b\right), a\right) \]
      13. PI-lowering-PI.f6460.3%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), b\right)\right), b\right), a\right) \]
    5. Simplified60.3%

      \[\leadsto \color{blue}{\frac{\frac{0.5 \cdot \frac{\pi}{b}}{b}}{a}} \]
    6. Step-by-step derivation
      1. associate-/l/N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{b}}{\color{blue}{a \cdot b}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{b} \cdot \frac{1}{2}}{\color{blue}{a} \cdot b} \]
      3. times-fracN/A

        \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{b}}{a} \cdot \color{blue}{\frac{\frac{1}{2}}{b}} \]
      4. associate-/r*N/A

        \[\leadsto \frac{\mathsf{PI}\left(\right)}{b \cdot a} \cdot \frac{\color{blue}{\frac{1}{2}}}{b} \]
      5. *-commutativeN/A

        \[\leadsto \frac{\mathsf{PI}\left(\right)}{a \cdot b} \cdot \frac{\frac{1}{2}}{b} \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{a \cdot b}\right), \color{blue}{\left(\frac{\frac{1}{2}}{b}\right)}\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{PI}\left(\right), \left(a \cdot b\right)\right), \left(\frac{\color{blue}{\frac{1}{2}}}{b}\right)\right) \]
      8. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \left(a \cdot b\right)\right), \left(\frac{\frac{1}{2}}{b}\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{*.f64}\left(a, b\right)\right), \left(\frac{\frac{1}{2}}{b}\right)\right) \]
      10. /-lowering-/.f6467.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{*.f64}\left(a, b\right)\right), \mathsf{/.f64}\left(\frac{1}{2}, \color{blue}{b}\right)\right) \]
    7. Applied egg-rr67.1%

      \[\leadsto \color{blue}{\frac{\pi}{a \cdot b} \cdot \frac{0.5}{b}} \]
    8. Step-by-step derivation
      1. associate-/l/N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\frac{\mathsf{PI}\left(\right)}{b}}{a}\right), \mathsf{/.f64}\left(\color{blue}{\frac{1}{2}}, b\right)\right) \]
      2. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{b}\right), a\right), \mathsf{/.f64}\left(\color{blue}{\frac{1}{2}}, b\right)\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{PI}\left(\right), b\right), a\right), \mathsf{/.f64}\left(\frac{1}{2}, b\right)\right) \]
      4. PI-lowering-PI.f6467.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), b\right), a\right), \mathsf{/.f64}\left(\frac{1}{2}, b\right)\right) \]
    9. Applied egg-rr67.1%

      \[\leadsto \color{blue}{\frac{\frac{\pi}{b}}{a}} \cdot \frac{0.5}{b} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 89.5% accurate, 1.5× speedup?

\[\begin{array}{l} [a, b] = \mathsf{sort}([a, b])\\ \\ \begin{array}{l} \mathbf{if}\;a \leq -4.4 \cdot 10^{-104}:\\ \;\;\;\;\frac{\frac{0.5}{a}}{b \cdot \frac{a}{\pi}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\pi}{b}}{a} \cdot \frac{0.5}{b}\\ \end{array} \end{array} \]
NOTE: a and b should be sorted in increasing order before calling this function.
(FPCore (a b)
 :precision binary64
 (if (<= a -4.4e-104)
   (/ (/ 0.5 a) (* b (/ a PI)))
   (* (/ (/ PI b) a) (/ 0.5 b))))
assert(a < b);
double code(double a, double b) {
	double tmp;
	if (a <= -4.4e-104) {
		tmp = (0.5 / a) / (b * (a / ((double) M_PI)));
	} else {
		tmp = ((((double) M_PI) / b) / a) * (0.5 / b);
	}
	return tmp;
}
assert a < b;
public static double code(double a, double b) {
	double tmp;
	if (a <= -4.4e-104) {
		tmp = (0.5 / a) / (b * (a / Math.PI));
	} else {
		tmp = ((Math.PI / b) / a) * (0.5 / b);
	}
	return tmp;
}
[a, b] = sort([a, b])
def code(a, b):
	tmp = 0
	if a <= -4.4e-104:
		tmp = (0.5 / a) / (b * (a / math.pi))
	else:
		tmp = ((math.pi / b) / a) * (0.5 / b)
	return tmp
a, b = sort([a, b])
function code(a, b)
	tmp = 0.0
	if (a <= -4.4e-104)
		tmp = Float64(Float64(0.5 / a) / Float64(b * Float64(a / pi)));
	else
		tmp = Float64(Float64(Float64(pi / b) / a) * Float64(0.5 / b));
	end
	return tmp
end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (a <= -4.4e-104)
		tmp = (0.5 / a) / (b * (a / pi));
	else
		tmp = ((pi / b) / a) * (0.5 / b);
	end
	tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function.
code[a_, b_] := If[LessEqual[a, -4.4e-104], N[(N[(0.5 / a), $MachinePrecision] / N[(b * N[(a / Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(Pi / b), $MachinePrecision] / a), $MachinePrecision] * N[(0.5 / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -4.4 \cdot 10^{-104}:\\
\;\;\;\;\frac{\frac{0.5}{a}}{b \cdot \frac{a}{\pi}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\pi}{b}}{a} \cdot \frac{0.5}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -4.40000000000000023e-104

    1. Initial program 80.7%

      \[\left(\frac{\pi}{2} \cdot \frac{1}{b \cdot b - a \cdot a}\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right) \]
    2. Add Preprocessing
    3. Taylor expanded in b around 0

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{{a}^{2} \cdot b}} \]
    4. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{\color{blue}{{a}^{2} \cdot b}} \]
      2. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot \mathsf{PI}\left(\right)\right), \color{blue}{\left({a}^{2} \cdot b\right)}\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI}\left(\right)\right), \left(\color{blue}{{a}^{2}} \cdot b\right)\right) \]
      4. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI.f64}\left(\right)\right), \left({a}^{\color{blue}{2}} \cdot b\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI.f64}\left(\right)\right), \mathsf{*.f64}\left(\left({a}^{2}\right), \color{blue}{b}\right)\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI.f64}\left(\right)\right), \mathsf{*.f64}\left(\left(a \cdot a\right), b\right)\right) \]
      7. *-lowering-*.f6472.1%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI.f64}\left(\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(a, a\right), b\right)\right) \]
    5. Simplified72.1%

      \[\leadsto \color{blue}{\frac{0.5 \cdot \pi}{\left(a \cdot a\right) \cdot b}} \]
    6. Step-by-step derivation
      1. associate-*l*N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{a \cdot \color{blue}{\left(a \cdot b\right)}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{a \cdot \left(b \cdot \color{blue}{a}\right)} \]
      3. times-fracN/A

        \[\leadsto \frac{\frac{1}{2}}{a} \cdot \color{blue}{\frac{\mathsf{PI}\left(\right)}{b \cdot a}} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\frac{1}{2}}{a}\right), \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{b \cdot a}\right)}\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \left(\frac{\color{blue}{\mathsf{PI}\left(\right)}}{b \cdot a}\right)\right) \]
      6. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{PI}\left(\right), \color{blue}{\left(b \cdot a\right)}\right)\right) \]
      7. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \left(\color{blue}{b} \cdot a\right)\right)\right) \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \left(a \cdot \color{blue}{b}\right)\right)\right) \]
      9. *-lowering-*.f6483.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{*.f64}\left(a, \color{blue}{b}\right)\right)\right) \]
    7. Applied egg-rr83.8%

      \[\leadsto \color{blue}{\frac{0.5}{a} \cdot \frac{\pi}{a \cdot b}} \]
    8. Step-by-step derivation
      1. clear-numN/A

        \[\leadsto \frac{\frac{1}{2}}{a} \cdot \frac{1}{\color{blue}{\frac{a \cdot b}{\mathsf{PI}\left(\right)}}} \]
      2. un-div-invN/A

        \[\leadsto \frac{\frac{\frac{1}{2}}{a}}{\color{blue}{\frac{a \cdot b}{\mathsf{PI}\left(\right)}}} \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{1}{2}}{a}\right), \color{blue}{\left(\frac{a \cdot b}{\mathsf{PI}\left(\right)}\right)}\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \left(\frac{\color{blue}{a \cdot b}}{\mathsf{PI}\left(\right)}\right)\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\left(a \cdot b\right), \color{blue}{\mathsf{PI}\left(\right)}\right)\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, b\right), \mathsf{PI}\left(\right)\right)\right) \]
      7. PI-lowering-PI.f6483.9%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, b\right), \mathsf{PI.f64}\left(\right)\right)\right) \]
    9. Applied egg-rr83.9%

      \[\leadsto \color{blue}{\frac{\frac{0.5}{a}}{\frac{a \cdot b}{\pi}}} \]
    10. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \left(\frac{b \cdot a}{\mathsf{PI}\left(\right)}\right)\right) \]
      2. associate-/l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \left(b \cdot \color{blue}{\frac{a}{\mathsf{PI}\left(\right)}}\right)\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \left(\frac{a}{\mathsf{PI}\left(\right)} \cdot \color{blue}{b}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{*.f64}\left(\left(\frac{a}{\mathsf{PI}\left(\right)}\right), \color{blue}{b}\right)\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{*.f64}\left(\mathsf{/.f64}\left(a, \mathsf{PI}\left(\right)\right), b\right)\right) \]
      6. PI-lowering-PI.f6483.9%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{*.f64}\left(\mathsf{/.f64}\left(a, \mathsf{PI.f64}\left(\right)\right), b\right)\right) \]
    11. Applied egg-rr83.9%

      \[\leadsto \frac{\frac{0.5}{a}}{\color{blue}{\frac{a}{\pi} \cdot b}} \]

    if -4.40000000000000023e-104 < a

    1. Initial program 79.2%

      \[\left(\frac{\pi}{2} \cdot \frac{1}{b \cdot b - a \cdot a}\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right) \]
    2. Add Preprocessing
    3. Taylor expanded in b around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{a \cdot {b}^{2}}} \]
    4. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{\color{blue}{a \cdot {b}^{2}}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{{b}^{2} \cdot \color{blue}{a}} \]
      3. associate-/r*N/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{{b}^{2}}}{\color{blue}{a}} \]
      4. associate-*r/N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{{b}^{2}}}{a} \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{{b}^{2}}\right), \color{blue}{a}\right) \]
      6. associate-*r/N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{{b}^{2}}\right), a\right) \]
      7. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{b \cdot b}\right), a\right) \]
      8. associate-/r*N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{b}}{b}\right), a\right) \]
      9. associate-*r/N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{b}}{b}\right), a\right) \]
      10. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\left(\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{b}\right), b\right), a\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(\frac{\mathsf{PI}\left(\right)}{b}\right)\right), b\right), a\right) \]
      12. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{PI}\left(\right), b\right)\right), b\right), a\right) \]
      13. PI-lowering-PI.f6460.3%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), b\right)\right), b\right), a\right) \]
    5. Simplified60.3%

      \[\leadsto \color{blue}{\frac{\frac{0.5 \cdot \frac{\pi}{b}}{b}}{a}} \]
    6. Step-by-step derivation
      1. associate-/l/N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{b}}{\color{blue}{a \cdot b}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{b} \cdot \frac{1}{2}}{\color{blue}{a} \cdot b} \]
      3. times-fracN/A

        \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{b}}{a} \cdot \color{blue}{\frac{\frac{1}{2}}{b}} \]
      4. associate-/r*N/A

        \[\leadsto \frac{\mathsf{PI}\left(\right)}{b \cdot a} \cdot \frac{\color{blue}{\frac{1}{2}}}{b} \]
      5. *-commutativeN/A

        \[\leadsto \frac{\mathsf{PI}\left(\right)}{a \cdot b} \cdot \frac{\frac{1}{2}}{b} \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{a \cdot b}\right), \color{blue}{\left(\frac{\frac{1}{2}}{b}\right)}\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{PI}\left(\right), \left(a \cdot b\right)\right), \left(\frac{\color{blue}{\frac{1}{2}}}{b}\right)\right) \]
      8. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \left(a \cdot b\right)\right), \left(\frac{\frac{1}{2}}{b}\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{*.f64}\left(a, b\right)\right), \left(\frac{\frac{1}{2}}{b}\right)\right) \]
      10. /-lowering-/.f6467.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{*.f64}\left(a, b\right)\right), \mathsf{/.f64}\left(\frac{1}{2}, \color{blue}{b}\right)\right) \]
    7. Applied egg-rr67.1%

      \[\leadsto \color{blue}{\frac{\pi}{a \cdot b} \cdot \frac{0.5}{b}} \]
    8. Step-by-step derivation
      1. associate-/l/N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\frac{\mathsf{PI}\left(\right)}{b}}{a}\right), \mathsf{/.f64}\left(\color{blue}{\frac{1}{2}}, b\right)\right) \]
      2. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{b}\right), a\right), \mathsf{/.f64}\left(\color{blue}{\frac{1}{2}}, b\right)\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{PI}\left(\right), b\right), a\right), \mathsf{/.f64}\left(\frac{1}{2}, b\right)\right) \]
      4. PI-lowering-PI.f6467.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), b\right), a\right), \mathsf{/.f64}\left(\frac{1}{2}, b\right)\right) \]
    9. Applied egg-rr67.1%

      \[\leadsto \color{blue}{\frac{\frac{\pi}{b}}{a}} \cdot \frac{0.5}{b} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification73.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -4.4 \cdot 10^{-104}:\\ \;\;\;\;\frac{\frac{0.5}{a}}{b \cdot \frac{a}{\pi}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\pi}{b}}{a} \cdot \frac{0.5}{b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 89.5% accurate, 1.5× speedup?

\[\begin{array}{l} [a, b] = \mathsf{sort}([a, b])\\ \\ \begin{array}{l} \mathbf{if}\;a \leq -4.4 \cdot 10^{-104}:\\ \;\;\;\;\frac{\pi}{a \cdot b} \cdot \frac{0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\pi}{b}}{a} \cdot \frac{0.5}{b}\\ \end{array} \end{array} \]
NOTE: a and b should be sorted in increasing order before calling this function.
(FPCore (a b)
 :precision binary64
 (if (<= a -4.4e-104)
   (* (/ PI (* a b)) (/ 0.5 a))
   (* (/ (/ PI b) a) (/ 0.5 b))))
assert(a < b);
double code(double a, double b) {
	double tmp;
	if (a <= -4.4e-104) {
		tmp = (((double) M_PI) / (a * b)) * (0.5 / a);
	} else {
		tmp = ((((double) M_PI) / b) / a) * (0.5 / b);
	}
	return tmp;
}
assert a < b;
public static double code(double a, double b) {
	double tmp;
	if (a <= -4.4e-104) {
		tmp = (Math.PI / (a * b)) * (0.5 / a);
	} else {
		tmp = ((Math.PI / b) / a) * (0.5 / b);
	}
	return tmp;
}
[a, b] = sort([a, b])
def code(a, b):
	tmp = 0
	if a <= -4.4e-104:
		tmp = (math.pi / (a * b)) * (0.5 / a)
	else:
		tmp = ((math.pi / b) / a) * (0.5 / b)
	return tmp
a, b = sort([a, b])
function code(a, b)
	tmp = 0.0
	if (a <= -4.4e-104)
		tmp = Float64(Float64(pi / Float64(a * b)) * Float64(0.5 / a));
	else
		tmp = Float64(Float64(Float64(pi / b) / a) * Float64(0.5 / b));
	end
	return tmp
end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (a <= -4.4e-104)
		tmp = (pi / (a * b)) * (0.5 / a);
	else
		tmp = ((pi / b) / a) * (0.5 / b);
	end
	tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function.
code[a_, b_] := If[LessEqual[a, -4.4e-104], N[(N[(Pi / N[(a * b), $MachinePrecision]), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(N[(N[(Pi / b), $MachinePrecision] / a), $MachinePrecision] * N[(0.5 / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -4.4 \cdot 10^{-104}:\\
\;\;\;\;\frac{\pi}{a \cdot b} \cdot \frac{0.5}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\pi}{b}}{a} \cdot \frac{0.5}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -4.40000000000000023e-104

    1. Initial program 80.7%

      \[\left(\frac{\pi}{2} \cdot \frac{1}{b \cdot b - a \cdot a}\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right) \]
    2. Add Preprocessing
    3. Taylor expanded in b around 0

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{{a}^{2} \cdot b}} \]
    4. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{\color{blue}{{a}^{2} \cdot b}} \]
      2. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot \mathsf{PI}\left(\right)\right), \color{blue}{\left({a}^{2} \cdot b\right)}\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI}\left(\right)\right), \left(\color{blue}{{a}^{2}} \cdot b\right)\right) \]
      4. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI.f64}\left(\right)\right), \left({a}^{\color{blue}{2}} \cdot b\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI.f64}\left(\right)\right), \mathsf{*.f64}\left(\left({a}^{2}\right), \color{blue}{b}\right)\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI.f64}\left(\right)\right), \mathsf{*.f64}\left(\left(a \cdot a\right), b\right)\right) \]
      7. *-lowering-*.f6472.1%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI.f64}\left(\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(a, a\right), b\right)\right) \]
    5. Simplified72.1%

      \[\leadsto \color{blue}{\frac{0.5 \cdot \pi}{\left(a \cdot a\right) \cdot b}} \]
    6. Step-by-step derivation
      1. associate-*l*N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{a \cdot \color{blue}{\left(a \cdot b\right)}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{a \cdot \left(b \cdot \color{blue}{a}\right)} \]
      3. times-fracN/A

        \[\leadsto \frac{\frac{1}{2}}{a} \cdot \color{blue}{\frac{\mathsf{PI}\left(\right)}{b \cdot a}} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\frac{1}{2}}{a}\right), \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{b \cdot a}\right)}\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \left(\frac{\color{blue}{\mathsf{PI}\left(\right)}}{b \cdot a}\right)\right) \]
      6. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{PI}\left(\right), \color{blue}{\left(b \cdot a\right)}\right)\right) \]
      7. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \left(\color{blue}{b} \cdot a\right)\right)\right) \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \left(a \cdot \color{blue}{b}\right)\right)\right) \]
      9. *-lowering-*.f6483.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{*.f64}\left(a, \color{blue}{b}\right)\right)\right) \]
    7. Applied egg-rr83.8%

      \[\leadsto \color{blue}{\frac{0.5}{a} \cdot \frac{\pi}{a \cdot b}} \]

    if -4.40000000000000023e-104 < a

    1. Initial program 79.2%

      \[\left(\frac{\pi}{2} \cdot \frac{1}{b \cdot b - a \cdot a}\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right) \]
    2. Add Preprocessing
    3. Taylor expanded in b around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{a \cdot {b}^{2}}} \]
    4. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{\color{blue}{a \cdot {b}^{2}}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{{b}^{2} \cdot \color{blue}{a}} \]
      3. associate-/r*N/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{{b}^{2}}}{\color{blue}{a}} \]
      4. associate-*r/N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{{b}^{2}}}{a} \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{{b}^{2}}\right), \color{blue}{a}\right) \]
      6. associate-*r/N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{{b}^{2}}\right), a\right) \]
      7. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{b \cdot b}\right), a\right) \]
      8. associate-/r*N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{b}}{b}\right), a\right) \]
      9. associate-*r/N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{b}}{b}\right), a\right) \]
      10. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\left(\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{b}\right), b\right), a\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(\frac{\mathsf{PI}\left(\right)}{b}\right)\right), b\right), a\right) \]
      12. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{PI}\left(\right), b\right)\right), b\right), a\right) \]
      13. PI-lowering-PI.f6460.3%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), b\right)\right), b\right), a\right) \]
    5. Simplified60.3%

      \[\leadsto \color{blue}{\frac{\frac{0.5 \cdot \frac{\pi}{b}}{b}}{a}} \]
    6. Step-by-step derivation
      1. associate-/l/N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{b}}{\color{blue}{a \cdot b}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{b} \cdot \frac{1}{2}}{\color{blue}{a} \cdot b} \]
      3. times-fracN/A

        \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{b}}{a} \cdot \color{blue}{\frac{\frac{1}{2}}{b}} \]
      4. associate-/r*N/A

        \[\leadsto \frac{\mathsf{PI}\left(\right)}{b \cdot a} \cdot \frac{\color{blue}{\frac{1}{2}}}{b} \]
      5. *-commutativeN/A

        \[\leadsto \frac{\mathsf{PI}\left(\right)}{a \cdot b} \cdot \frac{\frac{1}{2}}{b} \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{a \cdot b}\right), \color{blue}{\left(\frac{\frac{1}{2}}{b}\right)}\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{PI}\left(\right), \left(a \cdot b\right)\right), \left(\frac{\color{blue}{\frac{1}{2}}}{b}\right)\right) \]
      8. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \left(a \cdot b\right)\right), \left(\frac{\frac{1}{2}}{b}\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{*.f64}\left(a, b\right)\right), \left(\frac{\frac{1}{2}}{b}\right)\right) \]
      10. /-lowering-/.f6467.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{*.f64}\left(a, b\right)\right), \mathsf{/.f64}\left(\frac{1}{2}, \color{blue}{b}\right)\right) \]
    7. Applied egg-rr67.1%

      \[\leadsto \color{blue}{\frac{\pi}{a \cdot b} \cdot \frac{0.5}{b}} \]
    8. Step-by-step derivation
      1. associate-/l/N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\frac{\mathsf{PI}\left(\right)}{b}}{a}\right), \mathsf{/.f64}\left(\color{blue}{\frac{1}{2}}, b\right)\right) \]
      2. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{b}\right), a\right), \mathsf{/.f64}\left(\color{blue}{\frac{1}{2}}, b\right)\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{PI}\left(\right), b\right), a\right), \mathsf{/.f64}\left(\frac{1}{2}, b\right)\right) \]
      4. PI-lowering-PI.f6467.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), b\right), a\right), \mathsf{/.f64}\left(\frac{1}{2}, b\right)\right) \]
    9. Applied egg-rr67.1%

      \[\leadsto \color{blue}{\frac{\frac{\pi}{b}}{a}} \cdot \frac{0.5}{b} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification73.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -4.4 \cdot 10^{-104}:\\ \;\;\;\;\frac{\pi}{a \cdot b} \cdot \frac{0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\pi}{b}}{a} \cdot \frac{0.5}{b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 89.5% accurate, 1.5× speedup?

\[\begin{array}{l} [a, b] = \mathsf{sort}([a, b])\\ \\ \begin{array}{l} t_0 := \frac{\pi}{a \cdot b}\\ \mathbf{if}\;a \leq -1.2 \cdot 10^{-104}:\\ \;\;\;\;t\_0 \cdot \frac{0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;t\_0 \cdot \frac{0.5}{b}\\ \end{array} \end{array} \]
NOTE: a and b should be sorted in increasing order before calling this function.
(FPCore (a b)
 :precision binary64
 (let* ((t_0 (/ PI (* a b))))
   (if (<= a -1.2e-104) (* t_0 (/ 0.5 a)) (* t_0 (/ 0.5 b)))))
assert(a < b);
double code(double a, double b) {
	double t_0 = ((double) M_PI) / (a * b);
	double tmp;
	if (a <= -1.2e-104) {
		tmp = t_0 * (0.5 / a);
	} else {
		tmp = t_0 * (0.5 / b);
	}
	return tmp;
}
assert a < b;
public static double code(double a, double b) {
	double t_0 = Math.PI / (a * b);
	double tmp;
	if (a <= -1.2e-104) {
		tmp = t_0 * (0.5 / a);
	} else {
		tmp = t_0 * (0.5 / b);
	}
	return tmp;
}
[a, b] = sort([a, b])
def code(a, b):
	t_0 = math.pi / (a * b)
	tmp = 0
	if a <= -1.2e-104:
		tmp = t_0 * (0.5 / a)
	else:
		tmp = t_0 * (0.5 / b)
	return tmp
a, b = sort([a, b])
function code(a, b)
	t_0 = Float64(pi / Float64(a * b))
	tmp = 0.0
	if (a <= -1.2e-104)
		tmp = Float64(t_0 * Float64(0.5 / a));
	else
		tmp = Float64(t_0 * Float64(0.5 / b));
	end
	return tmp
end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
	t_0 = pi / (a * b);
	tmp = 0.0;
	if (a <= -1.2e-104)
		tmp = t_0 * (0.5 / a);
	else
		tmp = t_0 * (0.5 / b);
	end
	tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function.
code[a_, b_] := Block[{t$95$0 = N[(Pi / N[(a * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -1.2e-104], N[(t$95$0 * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(0.5 / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
t_0 := \frac{\pi}{a \cdot b}\\
\mathbf{if}\;a \leq -1.2 \cdot 10^{-104}:\\
\;\;\;\;t\_0 \cdot \frac{0.5}{a}\\

\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \frac{0.5}{b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -1.2e-104

    1. Initial program 80.7%

      \[\left(\frac{\pi}{2} \cdot \frac{1}{b \cdot b - a \cdot a}\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right) \]
    2. Add Preprocessing
    3. Taylor expanded in b around 0

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{{a}^{2} \cdot b}} \]
    4. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{\color{blue}{{a}^{2} \cdot b}} \]
      2. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot \mathsf{PI}\left(\right)\right), \color{blue}{\left({a}^{2} \cdot b\right)}\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI}\left(\right)\right), \left(\color{blue}{{a}^{2}} \cdot b\right)\right) \]
      4. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI.f64}\left(\right)\right), \left({a}^{\color{blue}{2}} \cdot b\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI.f64}\left(\right)\right), \mathsf{*.f64}\left(\left({a}^{2}\right), \color{blue}{b}\right)\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI.f64}\left(\right)\right), \mathsf{*.f64}\left(\left(a \cdot a\right), b\right)\right) \]
      7. *-lowering-*.f6472.1%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI.f64}\left(\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(a, a\right), b\right)\right) \]
    5. Simplified72.1%

      \[\leadsto \color{blue}{\frac{0.5 \cdot \pi}{\left(a \cdot a\right) \cdot b}} \]
    6. Step-by-step derivation
      1. associate-*l*N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{a \cdot \color{blue}{\left(a \cdot b\right)}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{a \cdot \left(b \cdot \color{blue}{a}\right)} \]
      3. times-fracN/A

        \[\leadsto \frac{\frac{1}{2}}{a} \cdot \color{blue}{\frac{\mathsf{PI}\left(\right)}{b \cdot a}} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\frac{1}{2}}{a}\right), \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{b \cdot a}\right)}\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \left(\frac{\color{blue}{\mathsf{PI}\left(\right)}}{b \cdot a}\right)\right) \]
      6. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{PI}\left(\right), \color{blue}{\left(b \cdot a\right)}\right)\right) \]
      7. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \left(\color{blue}{b} \cdot a\right)\right)\right) \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \left(a \cdot \color{blue}{b}\right)\right)\right) \]
      9. *-lowering-*.f6483.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{*.f64}\left(a, \color{blue}{b}\right)\right)\right) \]
    7. Applied egg-rr83.8%

      \[\leadsto \color{blue}{\frac{0.5}{a} \cdot \frac{\pi}{a \cdot b}} \]

    if -1.2e-104 < a

    1. Initial program 79.2%

      \[\left(\frac{\pi}{2} \cdot \frac{1}{b \cdot b - a \cdot a}\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right) \]
    2. Add Preprocessing
    3. Taylor expanded in b around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{a \cdot {b}^{2}}} \]
    4. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{\color{blue}{a \cdot {b}^{2}}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{{b}^{2} \cdot \color{blue}{a}} \]
      3. associate-/r*N/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{{b}^{2}}}{\color{blue}{a}} \]
      4. associate-*r/N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{{b}^{2}}}{a} \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{{b}^{2}}\right), \color{blue}{a}\right) \]
      6. associate-*r/N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{{b}^{2}}\right), a\right) \]
      7. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{b \cdot b}\right), a\right) \]
      8. associate-/r*N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{b}}{b}\right), a\right) \]
      9. associate-*r/N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{b}}{b}\right), a\right) \]
      10. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\left(\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{b}\right), b\right), a\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(\frac{\mathsf{PI}\left(\right)}{b}\right)\right), b\right), a\right) \]
      12. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{PI}\left(\right), b\right)\right), b\right), a\right) \]
      13. PI-lowering-PI.f6460.3%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), b\right)\right), b\right), a\right) \]
    5. Simplified60.3%

      \[\leadsto \color{blue}{\frac{\frac{0.5 \cdot \frac{\pi}{b}}{b}}{a}} \]
    6. Step-by-step derivation
      1. associate-/l/N/A

        \[\leadsto \frac{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{b}}{\color{blue}{a \cdot b}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{b} \cdot \frac{1}{2}}{\color{blue}{a} \cdot b} \]
      3. times-fracN/A

        \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{b}}{a} \cdot \color{blue}{\frac{\frac{1}{2}}{b}} \]
      4. associate-/r*N/A

        \[\leadsto \frac{\mathsf{PI}\left(\right)}{b \cdot a} \cdot \frac{\color{blue}{\frac{1}{2}}}{b} \]
      5. *-commutativeN/A

        \[\leadsto \frac{\mathsf{PI}\left(\right)}{a \cdot b} \cdot \frac{\frac{1}{2}}{b} \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{a \cdot b}\right), \color{blue}{\left(\frac{\frac{1}{2}}{b}\right)}\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{PI}\left(\right), \left(a \cdot b\right)\right), \left(\frac{\color{blue}{\frac{1}{2}}}{b}\right)\right) \]
      8. PI-lowering-PI.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \left(a \cdot b\right)\right), \left(\frac{\frac{1}{2}}{b}\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{*.f64}\left(a, b\right)\right), \left(\frac{\frac{1}{2}}{b}\right)\right) \]
      10. /-lowering-/.f6467.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{*.f64}\left(a, b\right)\right), \mathsf{/.f64}\left(\frac{1}{2}, \color{blue}{b}\right)\right) \]
    7. Applied egg-rr67.1%

      \[\leadsto \color{blue}{\frac{\pi}{a \cdot b} \cdot \frac{0.5}{b}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification72.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -1.2 \cdot 10^{-104}:\\ \;\;\;\;\frac{\pi}{a \cdot b} \cdot \frac{0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\pi}{a \cdot b} \cdot \frac{0.5}{b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 99.7% accurate, 1.9× speedup?

\[\begin{array}{l} [a, b] = \mathsf{sort}([a, b])\\ \\ \frac{0.5 \cdot \frac{\pi}{a \cdot b}}{a + b} \end{array} \]
NOTE: a and b should be sorted in increasing order before calling this function.
(FPCore (a b) :precision binary64 (/ (* 0.5 (/ PI (* a b))) (+ a b)))
assert(a < b);
double code(double a, double b) {
	return (0.5 * (((double) M_PI) / (a * b))) / (a + b);
}
assert a < b;
public static double code(double a, double b) {
	return (0.5 * (Math.PI / (a * b))) / (a + b);
}
[a, b] = sort([a, b])
def code(a, b):
	return (0.5 * (math.pi / (a * b))) / (a + b)
a, b = sort([a, b])
function code(a, b)
	return Float64(Float64(0.5 * Float64(pi / Float64(a * b))) / Float64(a + b))
end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
	tmp = (0.5 * (pi / (a * b))) / (a + b);
end
NOTE: a and b should be sorted in increasing order before calling this function.
code[a_, b_] := N[(N[(0.5 * N[(Pi / N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a + b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{0.5 \cdot \frac{\pi}{a \cdot b}}{a + b}
\end{array}
Derivation
  1. Initial program 79.7%

    \[\left(\frac{\pi}{2} \cdot \frac{1}{b \cdot b - a \cdot a}\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. un-div-invN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{2}}{b \cdot b - a \cdot a} \cdot \left(\color{blue}{\frac{1}{a}} - \frac{1}{b}\right) \]
    2. associate-/r*N/A

      \[\leadsto \frac{\mathsf{PI}\left(\right)}{2 \cdot \left(b \cdot b - a \cdot a\right)} \cdot \left(\color{blue}{\frac{1}{a}} - \frac{1}{b}\right) \]
    3. associate-*l/N/A

      \[\leadsto \frac{\mathsf{PI}\left(\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right)}{\color{blue}{2 \cdot \left(b \cdot b - a \cdot a\right)}} \]
    4. distribute-lft-out--N/A

      \[\leadsto \frac{\mathsf{PI}\left(\right) \cdot \frac{1}{a} - \mathsf{PI}\left(\right) \cdot \frac{1}{b}}{\color{blue}{2} \cdot \left(b \cdot b - a \cdot a\right)} \]
    5. div-invN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \mathsf{PI}\left(\right) \cdot \frac{1}{b}}{2 \cdot \left(b \cdot b - a \cdot a\right)} \]
    6. div-invN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{2 \cdot \left(b \cdot b - a \cdot a\right)} \]
    7. *-commutativeN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{\left(b \cdot b - a \cdot a\right) \cdot \color{blue}{2}} \]
    8. difference-of-squaresN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{\left(\left(b + a\right) \cdot \left(b - a\right)\right) \cdot 2} \]
    9. associate-*r*N/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{\left(b + a\right) \cdot \color{blue}{\left(\left(b - a\right) \cdot 2\right)}} \]
    10. *-commutativeN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{\left(b + a\right) \cdot \left(2 \cdot \color{blue}{\left(b - a\right)}\right)} \]
    11. *-commutativeN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{\left(2 \cdot \left(b - a\right)\right) \cdot \color{blue}{\left(b + a\right)}} \]
    12. associate-/r*N/A

      \[\leadsto \frac{\frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{2 \cdot \left(b - a\right)}}{\color{blue}{b + a}} \]
    13. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{2 \cdot \left(b - a\right)}\right), \color{blue}{\left(b + a\right)}\right) \]
  4. Applied egg-rr99.6%

    \[\leadsto \color{blue}{\frac{\frac{\frac{\pi}{a} - \frac{\pi}{b}}{2 \cdot \left(b - a\right)}}{b + a}} \]
  5. Taylor expanded in a around 0

    \[\leadsto \mathsf{/.f64}\left(\color{blue}{\left(\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{a \cdot b}\right)}, \mathsf{+.f64}\left(b, a\right)\right) \]
  6. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(\frac{\mathsf{PI}\left(\right)}{a \cdot b}\right)\right), \mathsf{+.f64}\left(\color{blue}{b}, a\right)\right) \]
    2. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{PI}\left(\right), \left(a \cdot b\right)\right)\right), \mathsf{+.f64}\left(b, a\right)\right) \]
    3. PI-lowering-PI.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \left(a \cdot b\right)\right)\right), \mathsf{+.f64}\left(b, a\right)\right) \]
    4. *-lowering-*.f6499.7%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{*.f64}\left(a, b\right)\right)\right), \mathsf{+.f64}\left(b, a\right)\right) \]
  7. Simplified99.7%

    \[\leadsto \frac{\color{blue}{0.5 \cdot \frac{\pi}{a \cdot b}}}{b + a} \]
  8. Final simplification99.7%

    \[\leadsto \frac{0.5 \cdot \frac{\pi}{a \cdot b}}{a + b} \]
  9. Add Preprocessing

Alternative 7: 99.0% accurate, 1.9× speedup?

\[\begin{array}{l} [a, b] = \mathsf{sort}([a, b])\\ \\ \frac{0.5}{\left(a + b\right) \cdot \frac{a}{\frac{\pi}{b}}} \end{array} \]
NOTE: a and b should be sorted in increasing order before calling this function.
(FPCore (a b) :precision binary64 (/ 0.5 (* (+ a b) (/ a (/ PI b)))))
assert(a < b);
double code(double a, double b) {
	return 0.5 / ((a + b) * (a / (((double) M_PI) / b)));
}
assert a < b;
public static double code(double a, double b) {
	return 0.5 / ((a + b) * (a / (Math.PI / b)));
}
[a, b] = sort([a, b])
def code(a, b):
	return 0.5 / ((a + b) * (a / (math.pi / b)))
a, b = sort([a, b])
function code(a, b)
	return Float64(0.5 / Float64(Float64(a + b) * Float64(a / Float64(pi / b))))
end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
	tmp = 0.5 / ((a + b) * (a / (pi / b)));
end
NOTE: a and b should be sorted in increasing order before calling this function.
code[a_, b_] := N[(0.5 / N[(N[(a + b), $MachinePrecision] * N[(a / N[(Pi / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{0.5}{\left(a + b\right) \cdot \frac{a}{\frac{\pi}{b}}}
\end{array}
Derivation
  1. Initial program 79.7%

    \[\left(\frac{\pi}{2} \cdot \frac{1}{b \cdot b - a \cdot a}\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. un-div-invN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{2}}{b \cdot b - a \cdot a} \cdot \left(\color{blue}{\frac{1}{a}} - \frac{1}{b}\right) \]
    2. associate-/r*N/A

      \[\leadsto \frac{\mathsf{PI}\left(\right)}{2 \cdot \left(b \cdot b - a \cdot a\right)} \cdot \left(\color{blue}{\frac{1}{a}} - \frac{1}{b}\right) \]
    3. associate-*l/N/A

      \[\leadsto \frac{\mathsf{PI}\left(\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right)}{\color{blue}{2 \cdot \left(b \cdot b - a \cdot a\right)}} \]
    4. distribute-lft-out--N/A

      \[\leadsto \frac{\mathsf{PI}\left(\right) \cdot \frac{1}{a} - \mathsf{PI}\left(\right) \cdot \frac{1}{b}}{\color{blue}{2} \cdot \left(b \cdot b - a \cdot a\right)} \]
    5. div-invN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \mathsf{PI}\left(\right) \cdot \frac{1}{b}}{2 \cdot \left(b \cdot b - a \cdot a\right)} \]
    6. div-invN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{2 \cdot \left(b \cdot b - a \cdot a\right)} \]
    7. *-commutativeN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{\left(b \cdot b - a \cdot a\right) \cdot \color{blue}{2}} \]
    8. difference-of-squaresN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{\left(\left(b + a\right) \cdot \left(b - a\right)\right) \cdot 2} \]
    9. associate-*r*N/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{\left(b + a\right) \cdot \color{blue}{\left(\left(b - a\right) \cdot 2\right)}} \]
    10. *-commutativeN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{\left(b + a\right) \cdot \left(2 \cdot \color{blue}{\left(b - a\right)}\right)} \]
    11. *-commutativeN/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{\left(2 \cdot \left(b - a\right)\right) \cdot \color{blue}{\left(b + a\right)}} \]
    12. associate-/r*N/A

      \[\leadsto \frac{\frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{2 \cdot \left(b - a\right)}}{\color{blue}{b + a}} \]
    13. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{\mathsf{PI}\left(\right)}{a} - \frac{\mathsf{PI}\left(\right)}{b}}{2 \cdot \left(b - a\right)}\right), \color{blue}{\left(b + a\right)}\right) \]
  4. Applied egg-rr99.6%

    \[\leadsto \color{blue}{\frac{\frac{\frac{\pi}{a} - \frac{\pi}{b}}{2 \cdot \left(b - a\right)}}{b + a}} \]
  5. Taylor expanded in a around 0

    \[\leadsto \mathsf{/.f64}\left(\color{blue}{\left(\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{a \cdot b}\right)}, \mathsf{+.f64}\left(b, a\right)\right) \]
  6. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(\frac{\mathsf{PI}\left(\right)}{a \cdot b}\right)\right), \mathsf{+.f64}\left(\color{blue}{b}, a\right)\right) \]
    2. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{PI}\left(\right), \left(a \cdot b\right)\right)\right), \mathsf{+.f64}\left(b, a\right)\right) \]
    3. PI-lowering-PI.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \left(a \cdot b\right)\right)\right), \mathsf{+.f64}\left(b, a\right)\right) \]
    4. *-lowering-*.f6499.7%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{*.f64}\left(a, b\right)\right)\right), \mathsf{+.f64}\left(b, a\right)\right) \]
  7. Simplified99.7%

    \[\leadsto \frac{\color{blue}{0.5 \cdot \frac{\pi}{a \cdot b}}}{b + a} \]
  8. Step-by-step derivation
    1. associate-*r/N/A

      \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{a \cdot b}\right), \mathsf{+.f64}\left(\color{blue}{b}, a\right)\right) \]
    2. associate-/r*N/A

      \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{a}}{b}\right), \mathsf{+.f64}\left(\color{blue}{b}, a\right)\right) \]
    3. associate-*l/N/A

      \[\leadsto \mathsf{/.f64}\left(\left(\frac{\frac{\frac{1}{2}}{a} \cdot \mathsf{PI}\left(\right)}{b}\right), \mathsf{+.f64}\left(b, a\right)\right) \]
    4. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\left(\frac{\frac{1}{2}}{a} \cdot \mathsf{PI}\left(\right)\right), b\right), \mathsf{+.f64}\left(\color{blue}{b}, a\right)\right) \]
    5. clear-numN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\left(\frac{1}{\frac{a}{\frac{1}{2}}} \cdot \mathsf{PI}\left(\right)\right), b\right), \mathsf{+.f64}\left(b, a\right)\right) \]
    6. associate-*l/N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\left(\frac{1 \cdot \mathsf{PI}\left(\right)}{\frac{a}{\frac{1}{2}}}\right), b\right), \mathsf{+.f64}\left(b, a\right)\right) \]
    7. *-un-lft-identityN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{\frac{a}{\frac{1}{2}}}\right), b\right), \mathsf{+.f64}\left(b, a\right)\right) \]
    8. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{PI}\left(\right), \left(\frac{a}{\frac{1}{2}}\right)\right), b\right), \mathsf{+.f64}\left(b, a\right)\right) \]
    9. PI-lowering-PI.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \left(\frac{a}{\frac{1}{2}}\right)\right), b\right), \mathsf{+.f64}\left(b, a\right)\right) \]
    10. /-lowering-/.f6499.6%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{/.f64}\left(a, \frac{1}{2}\right)\right), b\right), \mathsf{+.f64}\left(b, a\right)\right) \]
  9. Applied egg-rr99.6%

    \[\leadsto \frac{\color{blue}{\frac{\frac{\pi}{\frac{a}{0.5}}}{b}}}{b + a} \]
  10. Step-by-step derivation
    1. associate-/r/N/A

      \[\leadsto \frac{\frac{\frac{\mathsf{PI}\left(\right)}{a} \cdot \frac{1}{2}}{b}}{b + a} \]
    2. associate-*l/N/A

      \[\leadsto \frac{\frac{\frac{\mathsf{PI}\left(\right)}{a}}{b} \cdot \frac{1}{2}}{\color{blue}{b} + a} \]
    3. associate-/r*N/A

      \[\leadsto \frac{\frac{\mathsf{PI}\left(\right)}{a \cdot b} \cdot \frac{1}{2}}{b + a} \]
    4. clear-numN/A

      \[\leadsto \frac{\frac{1}{\frac{a \cdot b}{\mathsf{PI}\left(\right)}} \cdot \frac{1}{2}}{b + a} \]
    5. associate-*l/N/A

      \[\leadsto \frac{\frac{1 \cdot \frac{1}{2}}{\frac{a \cdot b}{\mathsf{PI}\left(\right)}}}{\color{blue}{b} + a} \]
    6. metadata-evalN/A

      \[\leadsto \frac{\frac{\frac{1}{2}}{\frac{a \cdot b}{\mathsf{PI}\left(\right)}}}{b + a} \]
    7. associate-/l/N/A

      \[\leadsto \frac{\frac{1}{2}}{\color{blue}{\left(b + a\right) \cdot \frac{a \cdot b}{\mathsf{PI}\left(\right)}}} \]
    8. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\frac{1}{2}, \color{blue}{\left(\left(b + a\right) \cdot \frac{a \cdot b}{\mathsf{PI}\left(\right)}\right)}\right) \]
    9. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\left(b + a\right), \color{blue}{\left(\frac{a \cdot b}{\mathsf{PI}\left(\right)}\right)}\right)\right) \]
    10. +-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\left(a + b\right), \left(\frac{\color{blue}{a \cdot b}}{\mathsf{PI}\left(\right)}\right)\right)\right) \]
    11. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{+.f64}\left(a, b\right), \left(\frac{\color{blue}{a \cdot b}}{\mathsf{PI}\left(\right)}\right)\right)\right) \]
    12. associate-/l*N/A

      \[\leadsto \mathsf{/.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{+.f64}\left(a, b\right), \left(a \cdot \color{blue}{\frac{b}{\mathsf{PI}\left(\right)}}\right)\right)\right) \]
    13. clear-numN/A

      \[\leadsto \mathsf{/.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{+.f64}\left(a, b\right), \left(a \cdot \frac{1}{\color{blue}{\frac{\mathsf{PI}\left(\right)}{b}}}\right)\right)\right) \]
    14. un-div-invN/A

      \[\leadsto \mathsf{/.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{+.f64}\left(a, b\right), \left(\frac{a}{\color{blue}{\frac{\mathsf{PI}\left(\right)}{b}}}\right)\right)\right) \]
    15. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{+.f64}\left(a, b\right), \mathsf{/.f64}\left(a, \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{b}\right)}\right)\right)\right) \]
    16. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{+.f64}\left(a, b\right), \mathsf{/.f64}\left(a, \mathsf{/.f64}\left(\mathsf{PI}\left(\right), \color{blue}{b}\right)\right)\right)\right) \]
    17. PI-lowering-PI.f6499.1%

      \[\leadsto \mathsf{/.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{+.f64}\left(a, b\right), \mathsf{/.f64}\left(a, \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), b\right)\right)\right)\right) \]
  11. Applied egg-rr99.1%

    \[\leadsto \color{blue}{\frac{0.5}{\left(a + b\right) \cdot \frac{a}{\frac{\pi}{b}}}} \]
  12. Add Preprocessing

Alternative 8: 63.3% accurate, 2.3× speedup?

\[\begin{array}{l} [a, b] = \mathsf{sort}([a, b])\\ \\ \frac{\pi}{a \cdot b} \cdot \frac{0.5}{a} \end{array} \]
NOTE: a and b should be sorted in increasing order before calling this function.
(FPCore (a b) :precision binary64 (* (/ PI (* a b)) (/ 0.5 a)))
assert(a < b);
double code(double a, double b) {
	return (((double) M_PI) / (a * b)) * (0.5 / a);
}
assert a < b;
public static double code(double a, double b) {
	return (Math.PI / (a * b)) * (0.5 / a);
}
[a, b] = sort([a, b])
def code(a, b):
	return (math.pi / (a * b)) * (0.5 / a)
a, b = sort([a, b])
function code(a, b)
	return Float64(Float64(pi / Float64(a * b)) * Float64(0.5 / a))
end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
	tmp = (pi / (a * b)) * (0.5 / a);
end
NOTE: a and b should be sorted in increasing order before calling this function.
code[a_, b_] := N[(N[(Pi / N[(a * b), $MachinePrecision]), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\pi}{a \cdot b} \cdot \frac{0.5}{a}
\end{array}
Derivation
  1. Initial program 79.7%

    \[\left(\frac{\pi}{2} \cdot \frac{1}{b \cdot b - a \cdot a}\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right) \]
  2. Add Preprocessing
  3. Taylor expanded in b around 0

    \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{{a}^{2} \cdot b}} \]
  4. Step-by-step derivation
    1. associate-*r/N/A

      \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{\color{blue}{{a}^{2} \cdot b}} \]
    2. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot \mathsf{PI}\left(\right)\right), \color{blue}{\left({a}^{2} \cdot b\right)}\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI}\left(\right)\right), \left(\color{blue}{{a}^{2}} \cdot b\right)\right) \]
    4. PI-lowering-PI.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI.f64}\left(\right)\right), \left({a}^{\color{blue}{2}} \cdot b\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI.f64}\left(\right)\right), \mathsf{*.f64}\left(\left({a}^{2}\right), \color{blue}{b}\right)\right) \]
    6. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI.f64}\left(\right)\right), \mathsf{*.f64}\left(\left(a \cdot a\right), b\right)\right) \]
    7. *-lowering-*.f6456.9%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{PI.f64}\left(\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(a, a\right), b\right)\right) \]
  5. Simplified56.9%

    \[\leadsto \color{blue}{\frac{0.5 \cdot \pi}{\left(a \cdot a\right) \cdot b}} \]
  6. Step-by-step derivation
    1. associate-*l*N/A

      \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{a \cdot \color{blue}{\left(a \cdot b\right)}} \]
    2. *-commutativeN/A

      \[\leadsto \frac{\frac{1}{2} \cdot \mathsf{PI}\left(\right)}{a \cdot \left(b \cdot \color{blue}{a}\right)} \]
    3. times-fracN/A

      \[\leadsto \frac{\frac{1}{2}}{a} \cdot \color{blue}{\frac{\mathsf{PI}\left(\right)}{b \cdot a}} \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{\frac{1}{2}}{a}\right), \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{b \cdot a}\right)}\right) \]
    5. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \left(\frac{\color{blue}{\mathsf{PI}\left(\right)}}{b \cdot a}\right)\right) \]
    6. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{PI}\left(\right), \color{blue}{\left(b \cdot a\right)}\right)\right) \]
    7. PI-lowering-PI.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \left(\color{blue}{b} \cdot a\right)\right)\right) \]
    8. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \left(a \cdot \color{blue}{b}\right)\right)\right) \]
    9. *-lowering-*.f6464.4%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\frac{1}{2}, a\right), \mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{*.f64}\left(a, \color{blue}{b}\right)\right)\right) \]
  7. Applied egg-rr64.4%

    \[\leadsto \color{blue}{\frac{0.5}{a} \cdot \frac{\pi}{a \cdot b}} \]
  8. Final simplification64.4%

    \[\leadsto \frac{\pi}{a \cdot b} \cdot \frac{0.5}{a} \]
  9. Add Preprocessing

Reproduce

?
herbie shell --seed 2024161 
(FPCore (a b)
  :name "NMSE Section 6.1 mentioned, B"
  :precision binary64
  (* (* (/ PI 2.0) (/ 1.0 (- (* b b) (* a a)))) (- (/ 1.0 a) (/ 1.0 b))))