
(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:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(FPCore (a b) :precision binary64 (* (/ PI (+ a b)) (/ 0.5 (* a b))))
double code(double a, double b) {
return (((double) M_PI) / (a + b)) * (0.5 / (a * b));
}
public static double code(double a, double b) {
return (Math.PI / (a + b)) * (0.5 / (a * b));
}
def code(a, b): return (math.pi / (a + b)) * (0.5 / (a * b))
function code(a, b) return Float64(Float64(pi / Float64(a + b)) * Float64(0.5 / Float64(a * b))) end
function tmp = code(a, b) tmp = (pi / (a + b)) * (0.5 / (a * b)); end
code[a_, b_] := N[(N[(Pi / N[(a + b), $MachinePrecision]), $MachinePrecision] * N[(0.5 / N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi}{a + b} \cdot \frac{0.5}{a \cdot b}
\end{array}
Initial program 79.9%
associate-*l*79.9%
associate-*l/79.9%
*-lft-identity79.9%
difference-of-squares87.4%
associate-/l/99.2%
sub-neg99.2%
distribute-neg-frac99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in a around 0 99.5%
expm1-log1p-u80.9%
expm1-udef47.8%
div-inv47.8%
metadata-eval47.8%
associate-/l/47.8%
+-commutative47.8%
Applied egg-rr47.8%
expm1-def79.1%
expm1-log1p97.8%
associate-*r/97.8%
*-rgt-identity97.8%
/-rgt-identity97.8%
times-frac99.5%
/-rgt-identity99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (a b) :precision binary64 (let* ((t_0 (/ 0.5 (* a b)))) (if (<= b 1.7e-39) (* t_0 (/ PI a)) (* t_0 (/ PI b)))))
double code(double a, double b) {
double t_0 = 0.5 / (a * b);
double tmp;
if (b <= 1.7e-39) {
tmp = t_0 * (((double) M_PI) / a);
} else {
tmp = t_0 * (((double) M_PI) / b);
}
return tmp;
}
public static double code(double a, double b) {
double t_0 = 0.5 / (a * b);
double tmp;
if (b <= 1.7e-39) {
tmp = t_0 * (Math.PI / a);
} else {
tmp = t_0 * (Math.PI / b);
}
return tmp;
}
def code(a, b): t_0 = 0.5 / (a * b) tmp = 0 if b <= 1.7e-39: tmp = t_0 * (math.pi / a) else: tmp = t_0 * (math.pi / b) return tmp
function code(a, b) t_0 = Float64(0.5 / Float64(a * b)) tmp = 0.0 if (b <= 1.7e-39) tmp = Float64(t_0 * Float64(pi / a)); else tmp = Float64(t_0 * Float64(pi / b)); end return tmp end
function tmp_2 = code(a, b) t_0 = 0.5 / (a * b); tmp = 0.0; if (b <= 1.7e-39) tmp = t_0 * (pi / a); else tmp = t_0 * (pi / b); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(0.5 / N[(a * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 1.7e-39], N[(t$95$0 * N[(Pi / a), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(Pi / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{0.5}{a \cdot b}\\
\mathbf{if}\;b \leq 1.7 \cdot 10^{-39}:\\
\;\;\;\;t\_0 \cdot \frac{\pi}{a}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \frac{\pi}{b}\\
\end{array}
\end{array}
if b < 1.7e-39Initial program 77.5%
associate-*l*77.5%
associate-*l/77.5%
*-lft-identity77.5%
difference-of-squares85.6%
associate-/l/99.5%
sub-neg99.5%
distribute-neg-frac99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in a around 0 99.5%
expm1-log1p-u76.4%
expm1-udef43.9%
div-inv43.9%
metadata-eval43.9%
associate-/l/43.9%
+-commutative43.9%
Applied egg-rr43.9%
expm1-def75.2%
expm1-log1p98.3%
associate-*r/98.4%
*-rgt-identity98.4%
/-rgt-identity98.4%
times-frac99.5%
/-rgt-identity99.5%
Simplified99.5%
Taylor expanded in a around inf 73.4%
if 1.7e-39 < b Initial program 85.0%
associate-*l*85.0%
associate-*l/85.0%
*-lft-identity85.0%
difference-of-squares91.0%
associate-/l/98.4%
sub-neg98.4%
distribute-neg-frac98.4%
metadata-eval98.4%
Simplified98.4%
Taylor expanded in a around 0 99.6%
expm1-log1p-u90.1%
expm1-udef56.0%
div-inv56.0%
metadata-eval56.0%
associate-/l/56.0%
+-commutative56.0%
Applied egg-rr56.0%
expm1-def87.1%
expm1-log1p96.6%
associate-*r/96.6%
*-rgt-identity96.6%
/-rgt-identity96.6%
times-frac99.6%
/-rgt-identity99.6%
Simplified99.6%
Taylor expanded in a around 0 89.2%
Final simplification78.5%
(FPCore (a b) :precision binary64 (if (<= b 3.2e-39) (/ (* PI (/ 0.5 a)) (* a b)) (* (/ 0.5 (* a b)) (/ PI b))))
double code(double a, double b) {
double tmp;
if (b <= 3.2e-39) {
tmp = (((double) M_PI) * (0.5 / a)) / (a * b);
} else {
tmp = (0.5 / (a * b)) * (((double) M_PI) / b);
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (b <= 3.2e-39) {
tmp = (Math.PI * (0.5 / a)) / (a * b);
} else {
tmp = (0.5 / (a * b)) * (Math.PI / b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 3.2e-39: tmp = (math.pi * (0.5 / a)) / (a * b) else: tmp = (0.5 / (a * b)) * (math.pi / b) return tmp
function code(a, b) tmp = 0.0 if (b <= 3.2e-39) tmp = Float64(Float64(pi * Float64(0.5 / a)) / Float64(a * b)); else tmp = Float64(Float64(0.5 / Float64(a * b)) * Float64(pi / b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 3.2e-39) tmp = (pi * (0.5 / a)) / (a * b); else tmp = (0.5 / (a * b)) * (pi / b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 3.2e-39], N[(N[(Pi * N[(0.5 / a), $MachinePrecision]), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 / N[(a * b), $MachinePrecision]), $MachinePrecision] * N[(Pi / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.2 \cdot 10^{-39}:\\
\;\;\;\;\frac{\pi \cdot \frac{0.5}{a}}{a \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{a \cdot b} \cdot \frac{\pi}{b}\\
\end{array}
\end{array}
if b < 3.1999999999999998e-39Initial program 77.5%
associate-*l*77.5%
associate-*l/77.5%
*-lft-identity77.5%
difference-of-squares85.6%
associate-/l/99.5%
sub-neg99.5%
distribute-neg-frac99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in a around 0 99.5%
expm1-log1p-u76.4%
expm1-udef43.9%
div-inv43.9%
metadata-eval43.9%
associate-/l/43.9%
+-commutative43.9%
Applied egg-rr43.9%
expm1-def75.2%
expm1-log1p98.3%
associate-*r/98.4%
*-rgt-identity98.4%
/-rgt-identity98.4%
times-frac99.5%
/-rgt-identity99.5%
Simplified99.5%
*-commutative99.5%
associate-/r*99.5%
frac-times97.8%
Applied egg-rr97.8%
Taylor expanded in b around 0 73.5%
if 3.1999999999999998e-39 < b Initial program 85.0%
associate-*l*85.0%
associate-*l/85.0%
*-lft-identity85.0%
difference-of-squares91.0%
associate-/l/98.4%
sub-neg98.4%
distribute-neg-frac98.4%
metadata-eval98.4%
Simplified98.4%
Taylor expanded in a around 0 99.6%
expm1-log1p-u90.1%
expm1-udef56.0%
div-inv56.0%
metadata-eval56.0%
associate-/l/56.0%
+-commutative56.0%
Applied egg-rr56.0%
expm1-def87.1%
expm1-log1p96.6%
associate-*r/96.6%
*-rgt-identity96.6%
/-rgt-identity96.6%
times-frac99.6%
/-rgt-identity99.6%
Simplified99.6%
Taylor expanded in a around 0 89.2%
Final simplification78.6%
(FPCore (a b) :precision binary64 (if (<= b 3.8e-39) (/ (/ 0.5 a) (* b (/ a PI))) (* (/ 0.5 (* a b)) (/ PI b))))
double code(double a, double b) {
double tmp;
if (b <= 3.8e-39) {
tmp = (0.5 / a) / (b * (a / ((double) M_PI)));
} else {
tmp = (0.5 / (a * b)) * (((double) M_PI) / b);
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (b <= 3.8e-39) {
tmp = (0.5 / a) / (b * (a / Math.PI));
} else {
tmp = (0.5 / (a * b)) * (Math.PI / b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 3.8e-39: tmp = (0.5 / a) / (b * (a / math.pi)) else: tmp = (0.5 / (a * b)) * (math.pi / b) return tmp
function code(a, b) tmp = 0.0 if (b <= 3.8e-39) tmp = Float64(Float64(0.5 / a) / Float64(b * Float64(a / pi))); else tmp = Float64(Float64(0.5 / Float64(a * b)) * Float64(pi / b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 3.8e-39) tmp = (0.5 / a) / (b * (a / pi)); else tmp = (0.5 / (a * b)) * (pi / b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 3.8e-39], N[(N[(0.5 / a), $MachinePrecision] / N[(b * N[(a / Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 / N[(a * b), $MachinePrecision]), $MachinePrecision] * N[(Pi / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.8 \cdot 10^{-39}:\\
\;\;\;\;\frac{\frac{0.5}{a}}{b \cdot \frac{a}{\pi}}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{a \cdot b} \cdot \frac{\pi}{b}\\
\end{array}
\end{array}
if b < 3.8000000000000002e-39Initial program 77.5%
associate-*l*77.5%
associate-*l/77.5%
*-lft-identity77.5%
difference-of-squares85.6%
associate-/l/99.5%
sub-neg99.5%
distribute-neg-frac99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in a around 0 99.5%
expm1-log1p-u76.4%
expm1-udef43.9%
div-inv43.9%
metadata-eval43.9%
associate-/l/43.9%
+-commutative43.9%
Applied egg-rr43.9%
expm1-def75.2%
expm1-log1p98.3%
associate-*r/98.4%
*-rgt-identity98.4%
/-rgt-identity98.4%
times-frac99.5%
/-rgt-identity99.5%
Simplified99.5%
Taylor expanded in a around inf 73.4%
clear-num73.4%
associate-/r*73.4%
frac-times73.5%
*-un-lft-identity73.5%
Applied egg-rr73.5%
if 3.8000000000000002e-39 < b Initial program 85.0%
associate-*l*85.0%
associate-*l/85.0%
*-lft-identity85.0%
difference-of-squares91.0%
associate-/l/98.4%
sub-neg98.4%
distribute-neg-frac98.4%
metadata-eval98.4%
Simplified98.4%
Taylor expanded in a around 0 99.6%
expm1-log1p-u90.1%
expm1-udef56.0%
div-inv56.0%
metadata-eval56.0%
associate-/l/56.0%
+-commutative56.0%
Applied egg-rr56.0%
expm1-def87.1%
expm1-log1p96.6%
associate-*r/96.6%
*-rgt-identity96.6%
/-rgt-identity96.6%
times-frac99.6%
/-rgt-identity99.6%
Simplified99.6%
Taylor expanded in a around 0 89.2%
Final simplification78.6%
(FPCore (a b) :precision binary64 (if (<= b 4e-39) (/ (/ PI (* b (* a 2.0))) a) (* (/ 0.5 (* a b)) (/ PI b))))
double code(double a, double b) {
double tmp;
if (b <= 4e-39) {
tmp = (((double) M_PI) / (b * (a * 2.0))) / a;
} else {
tmp = (0.5 / (a * b)) * (((double) M_PI) / b);
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (b <= 4e-39) {
tmp = (Math.PI / (b * (a * 2.0))) / a;
} else {
tmp = (0.5 / (a * b)) * (Math.PI / b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 4e-39: tmp = (math.pi / (b * (a * 2.0))) / a else: tmp = (0.5 / (a * b)) * (math.pi / b) return tmp
function code(a, b) tmp = 0.0 if (b <= 4e-39) tmp = Float64(Float64(pi / Float64(b * Float64(a * 2.0))) / a); else tmp = Float64(Float64(0.5 / Float64(a * b)) * Float64(pi / b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 4e-39) tmp = (pi / (b * (a * 2.0))) / a; else tmp = (0.5 / (a * b)) * (pi / b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 4e-39], N[(N[(Pi / N[(b * N[(a * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(N[(0.5 / N[(a * b), $MachinePrecision]), $MachinePrecision] * N[(Pi / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4 \cdot 10^{-39}:\\
\;\;\;\;\frac{\frac{\pi}{b \cdot \left(a \cdot 2\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{a \cdot b} \cdot \frac{\pi}{b}\\
\end{array}
\end{array}
if b < 3.99999999999999972e-39Initial program 77.5%
associate-*l*77.5%
associate-*l/77.5%
*-lft-identity77.5%
difference-of-squares85.6%
associate-/l/99.5%
sub-neg99.5%
distribute-neg-frac99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in a around 0 99.5%
expm1-log1p-u76.4%
expm1-udef43.9%
div-inv43.9%
metadata-eval43.9%
associate-/l/43.9%
+-commutative43.9%
Applied egg-rr43.9%
expm1-def75.2%
expm1-log1p98.3%
associate-*r/98.4%
*-rgt-identity98.4%
/-rgt-identity98.4%
times-frac99.5%
/-rgt-identity99.5%
Simplified99.5%
Taylor expanded in a around inf 73.4%
associate-*l/73.5%
associate-/r*73.5%
clear-num73.4%
un-div-inv73.5%
div-inv73.5%
clear-num73.5%
div-inv73.5%
metadata-eval73.5%
Applied egg-rr73.5%
if 3.99999999999999972e-39 < b Initial program 85.0%
associate-*l*85.0%
associate-*l/85.0%
*-lft-identity85.0%
difference-of-squares91.0%
associate-/l/98.4%
sub-neg98.4%
distribute-neg-frac98.4%
metadata-eval98.4%
Simplified98.4%
Taylor expanded in a around 0 99.6%
expm1-log1p-u90.1%
expm1-udef56.0%
div-inv56.0%
metadata-eval56.0%
associate-/l/56.0%
+-commutative56.0%
Applied egg-rr56.0%
expm1-def87.1%
expm1-log1p96.6%
associate-*r/96.6%
*-rgt-identity96.6%
/-rgt-identity96.6%
times-frac99.6%
/-rgt-identity99.6%
Simplified99.6%
Taylor expanded in a around 0 89.2%
Final simplification78.6%
(FPCore (a b) :precision binary64 (* (/ 0.5 (* a b)) (/ PI a)))
double code(double a, double b) {
return (0.5 / (a * b)) * (((double) M_PI) / a);
}
public static double code(double a, double b) {
return (0.5 / (a * b)) * (Math.PI / a);
}
def code(a, b): return (0.5 / (a * b)) * (math.pi / a)
function code(a, b) return Float64(Float64(0.5 / Float64(a * b)) * Float64(pi / a)) end
function tmp = code(a, b) tmp = (0.5 / (a * b)) * (pi / a); end
code[a_, b_] := N[(N[(0.5 / N[(a * b), $MachinePrecision]), $MachinePrecision] * N[(Pi / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5}{a \cdot b} \cdot \frac{\pi}{a}
\end{array}
Initial program 79.9%
associate-*l*79.9%
associate-*l/79.9%
*-lft-identity79.9%
difference-of-squares87.4%
associate-/l/99.2%
sub-neg99.2%
distribute-neg-frac99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in a around 0 99.5%
expm1-log1p-u80.9%
expm1-udef47.8%
div-inv47.8%
metadata-eval47.8%
associate-/l/47.8%
+-commutative47.8%
Applied egg-rr47.8%
expm1-def79.1%
expm1-log1p97.8%
associate-*r/97.8%
*-rgt-identity97.8%
/-rgt-identity97.8%
times-frac99.5%
/-rgt-identity99.5%
Simplified99.5%
Taylor expanded in a around inf 60.1%
Final simplification60.1%
herbie shell --seed 2024027
(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))))