
(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 7 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 b) 0.5) a) (+ b a)))
double code(double a, double b) {
return (((((double) M_PI) / b) * 0.5) / a) / (b + a);
}
public static double code(double a, double b) {
return (((Math.PI / b) * 0.5) / a) / (b + a);
}
def code(a, b): return (((math.pi / b) * 0.5) / a) / (b + a)
function code(a, b) return Float64(Float64(Float64(Float64(pi / b) * 0.5) / a) / Float64(b + a)) end
function tmp = code(a, b) tmp = (((pi / b) * 0.5) / a) / (b + a); end
code[a_, b_] := N[(N[(N[(N[(Pi / b), $MachinePrecision] * 0.5), $MachinePrecision] / a), $MachinePrecision] / N[(b + a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\frac{\pi}{b} \cdot 0.5}{a}}{b + a}
\end{array}
Initial program 79.2%
associate-*r/79.2%
*-rgt-identity79.2%
associate-*l/79.2%
difference-of-squares90.9%
*-commutative90.9%
times-frac99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
associate-*r/99.6%
associate-/l/99.6%
Applied egg-rr99.6%
Taylor expanded in b around 0 99.7%
expm1-log1p-u68.6%
expm1-udef58.9%
associate-*r/58.9%
times-frac58.9%
Applied egg-rr58.9%
expm1-def68.6%
expm1-log1p99.6%
*-commutative99.6%
Simplified99.6%
associate-*r/99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (a b) :precision binary64 (if (or (<= a -1.7e+115) (and (not (<= a -5.2e-204)) (<= a -1.58e-291))) (* (/ PI a) (/ -0.5 (* b a))) (* (/ PI (* b a)) (/ -0.5 b))))
double code(double a, double b) {
double tmp;
if ((a <= -1.7e+115) || (!(a <= -5.2e-204) && (a <= -1.58e-291))) {
tmp = (((double) M_PI) / a) * (-0.5 / (b * a));
} else {
tmp = (((double) M_PI) / (b * a)) * (-0.5 / b);
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if ((a <= -1.7e+115) || (!(a <= -5.2e-204) && (a <= -1.58e-291))) {
tmp = (Math.PI / a) * (-0.5 / (b * a));
} else {
tmp = (Math.PI / (b * a)) * (-0.5 / b);
}
return tmp;
}
def code(a, b): tmp = 0 if (a <= -1.7e+115) or (not (a <= -5.2e-204) and (a <= -1.58e-291)): tmp = (math.pi / a) * (-0.5 / (b * a)) else: tmp = (math.pi / (b * a)) * (-0.5 / b) return tmp
function code(a, b) tmp = 0.0 if ((a <= -1.7e+115) || (!(a <= -5.2e-204) && (a <= -1.58e-291))) tmp = Float64(Float64(pi / a) * Float64(-0.5 / Float64(b * a))); else tmp = Float64(Float64(pi / Float64(b * a)) * Float64(-0.5 / b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((a <= -1.7e+115) || (~((a <= -5.2e-204)) && (a <= -1.58e-291))) tmp = (pi / a) * (-0.5 / (b * a)); else tmp = (pi / (b * a)) * (-0.5 / b); end tmp_2 = tmp; end
code[a_, b_] := If[Or[LessEqual[a, -1.7e+115], And[N[Not[LessEqual[a, -5.2e-204]], $MachinePrecision], LessEqual[a, -1.58e-291]]], N[(N[(Pi / a), $MachinePrecision] * N[(-0.5 / N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(Pi / N[(b * a), $MachinePrecision]), $MachinePrecision] * N[(-0.5 / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.7 \cdot 10^{+115} \lor \neg \left(a \leq -5.2 \cdot 10^{-204}\right) \land a \leq -1.58 \cdot 10^{-291}:\\
\;\;\;\;\frac{\pi}{a} \cdot \frac{-0.5}{b \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\pi}{b \cdot a} \cdot \frac{-0.5}{b}\\
\end{array}
\end{array}
if a < -1.7e115 or -5.19999999999999965e-204 < a < -1.58000000000000004e-291Initial program 65.5%
associate-*r/65.4%
*-rgt-identity65.4%
associate-*l/65.4%
difference-of-squares89.3%
*-commutative89.3%
times-frac99.7%
sub-neg99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in a around inf 68.5%
Taylor expanded in b around 0 73.8%
associate-*r/73.8%
Simplified73.8%
*-commutative73.8%
frac-2neg73.8%
metadata-eval73.8%
frac-times73.3%
*-un-lft-identity73.3%
*-commutative73.3%
Applied egg-rr73.3%
*-commutative73.3%
times-frac73.8%
add-sqr-sqrt35.2%
sqrt-unprod60.4%
sqr-neg60.4%
sqrt-unprod25.2%
add-sqr-sqrt59.5%
*-commutative59.5%
Applied egg-rr59.5%
if -1.7e115 < a < -5.19999999999999965e-204 or -1.58000000000000004e-291 < a Initial program 84.5%
associate-*r/84.5%
*-rgt-identity84.5%
associate-*l/84.5%
difference-of-squares91.5%
*-commutative91.5%
times-frac99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in a around inf 60.4%
*-commutative60.4%
clear-num60.4%
frac-times60.4%
metadata-eval60.4%
*-commutative60.4%
div-inv60.4%
metadata-eval60.4%
Applied egg-rr60.4%
associate-*r/60.5%
associate-/l*60.4%
neg-mul-160.4%
distribute-rgt-neg-in60.4%
metadata-eval60.4%
*-commutative60.4%
*-commutative60.4%
Simplified60.4%
associate-*r*58.4%
times-frac58.3%
Applied egg-rr58.3%
Taylor expanded in b around inf 26.0%
Final simplification35.3%
(FPCore (a b) :precision binary64 (if (<= b 5.8e+102) (/ 0.5 (* a (* a (/ b PI)))) (* (/ PI (* b a)) (/ -0.5 b))))
double code(double a, double b) {
double tmp;
if (b <= 5.8e+102) {
tmp = 0.5 / (a * (a * (b / ((double) M_PI))));
} else {
tmp = (((double) M_PI) / (b * a)) * (-0.5 / b);
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (b <= 5.8e+102) {
tmp = 0.5 / (a * (a * (b / Math.PI)));
} else {
tmp = (Math.PI / (b * a)) * (-0.5 / b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 5.8e+102: tmp = 0.5 / (a * (a * (b / math.pi))) else: tmp = (math.pi / (b * a)) * (-0.5 / b) return tmp
function code(a, b) tmp = 0.0 if (b <= 5.8e+102) tmp = Float64(0.5 / Float64(a * Float64(a * Float64(b / pi)))); else tmp = Float64(Float64(pi / Float64(b * a)) * Float64(-0.5 / b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 5.8e+102) tmp = 0.5 / (a * (a * (b / pi))); else tmp = (pi / (b * a)) * (-0.5 / b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 5.8e+102], N[(0.5 / N[(a * N[(a * N[(b / Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(Pi / N[(b * a), $MachinePrecision]), $MachinePrecision] * N[(-0.5 / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5.8 \cdot 10^{+102}:\\
\;\;\;\;\frac{0.5}{a \cdot \left(a \cdot \frac{b}{\pi}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\pi}{b \cdot a} \cdot \frac{-0.5}{b}\\
\end{array}
\end{array}
if b < 5.8000000000000005e102Initial program 83.9%
associate-*r/83.9%
*-rgt-identity83.9%
associate-*l/83.9%
difference-of-squares92.1%
*-commutative92.1%
times-frac99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in a around inf 62.8%
Taylor expanded in b around 0 62.6%
associate-*r/62.6%
Simplified62.6%
associate-/l*62.5%
frac-times62.3%
metadata-eval62.3%
Applied egg-rr62.3%
expm1-log1p-u39.3%
expm1-udef23.5%
*-commutative23.5%
Applied egg-rr23.5%
expm1-def39.3%
expm1-log1p62.3%
associate-*r*62.3%
associate-*l/62.4%
associate-*r/62.3%
Simplified62.3%
if 5.8000000000000005e102 < b Initial program 58.1%
associate-*r/58.2%
*-rgt-identity58.2%
associate-*l/58.1%
difference-of-squares85.8%
*-commutative85.8%
times-frac99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in a around inf 62.3%
*-commutative62.3%
clear-num62.3%
frac-times62.4%
metadata-eval62.4%
*-commutative62.4%
div-inv62.4%
metadata-eval62.4%
Applied egg-rr62.4%
associate-*r/62.4%
associate-/l*62.4%
neg-mul-162.4%
distribute-rgt-neg-in62.4%
metadata-eval62.4%
*-commutative62.4%
*-commutative62.4%
Simplified62.4%
associate-*r*62.4%
times-frac62.3%
Applied egg-rr62.3%
Taylor expanded in b around inf 62.3%
Final simplification62.3%
(FPCore (a b) :precision binary64 (if (<= b 2.4e+101) (/ 0.5 (/ (* a (* b a)) PI)) (* (/ PI (* b a)) (/ -0.5 b))))
double code(double a, double b) {
double tmp;
if (b <= 2.4e+101) {
tmp = 0.5 / ((a * (b * a)) / ((double) M_PI));
} else {
tmp = (((double) M_PI) / (b * a)) * (-0.5 / b);
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (b <= 2.4e+101) {
tmp = 0.5 / ((a * (b * a)) / Math.PI);
} else {
tmp = (Math.PI / (b * a)) * (-0.5 / b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 2.4e+101: tmp = 0.5 / ((a * (b * a)) / math.pi) else: tmp = (math.pi / (b * a)) * (-0.5 / b) return tmp
function code(a, b) tmp = 0.0 if (b <= 2.4e+101) tmp = Float64(0.5 / Float64(Float64(a * Float64(b * a)) / pi)); else tmp = Float64(Float64(pi / Float64(b * a)) * Float64(-0.5 / b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 2.4e+101) tmp = 0.5 / ((a * (b * a)) / pi); else tmp = (pi / (b * a)) * (-0.5 / b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 2.4e+101], N[(0.5 / N[(N[(a * N[(b * a), $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision], N[(N[(Pi / N[(b * a), $MachinePrecision]), $MachinePrecision] * N[(-0.5 / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.4 \cdot 10^{+101}:\\
\;\;\;\;\frac{0.5}{\frac{a \cdot \left(b \cdot a\right)}{\pi}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\pi}{b \cdot a} \cdot \frac{-0.5}{b}\\
\end{array}
\end{array}
if b < 2.39999999999999988e101Initial program 83.9%
associate-*r/83.9%
*-rgt-identity83.9%
associate-*l/83.9%
difference-of-squares92.1%
*-commutative92.1%
times-frac99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in a around inf 62.8%
Taylor expanded in b around 0 62.6%
associate-*r/62.6%
Simplified62.6%
associate-/l*62.5%
frac-times62.3%
metadata-eval62.3%
Applied egg-rr62.3%
associate-*l/62.4%
*-commutative62.4%
Applied egg-rr62.4%
if 2.39999999999999988e101 < b Initial program 58.1%
associate-*r/58.2%
*-rgt-identity58.2%
associate-*l/58.1%
difference-of-squares85.8%
*-commutative85.8%
times-frac99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in a around inf 62.3%
*-commutative62.3%
clear-num62.3%
frac-times62.4%
metadata-eval62.4%
*-commutative62.4%
div-inv62.4%
metadata-eval62.4%
Applied egg-rr62.4%
associate-*r/62.4%
associate-/l*62.4%
neg-mul-162.4%
distribute-rgt-neg-in62.4%
metadata-eval62.4%
*-commutative62.4%
*-commutative62.4%
Simplified62.4%
associate-*r*62.4%
times-frac62.3%
Applied egg-rr62.3%
Taylor expanded in b around inf 62.3%
Final simplification62.4%
(FPCore (a b) :precision binary64 (* 0.5 (/ (/ PI a) (* b (+ b a)))))
double code(double a, double b) {
return 0.5 * ((((double) M_PI) / a) / (b * (b + a)));
}
public static double code(double a, double b) {
return 0.5 * ((Math.PI / a) / (b * (b + a)));
}
def code(a, b): return 0.5 * ((math.pi / a) / (b * (b + a)))
function code(a, b) return Float64(0.5 * Float64(Float64(pi / a) / Float64(b * Float64(b + a)))) end
function tmp = code(a, b) tmp = 0.5 * ((pi / a) / (b * (b + a))); end
code[a_, b_] := N[(0.5 * N[(N[(Pi / a), $MachinePrecision] / N[(b * N[(b + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \frac{\frac{\pi}{a}}{b \cdot \left(b + a\right)}
\end{array}
Initial program 79.2%
associate-*r/79.2%
*-rgt-identity79.2%
associate-*l/79.2%
difference-of-squares90.9%
*-commutative90.9%
times-frac99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
associate-*r/99.6%
associate-/l/99.6%
Applied egg-rr99.6%
Taylor expanded in b around 0 99.7%
expm1-log1p-u80.6%
expm1-udef56.9%
associate-*r/56.9%
times-frac56.9%
+-commutative56.9%
Applied egg-rr56.9%
expm1-def80.6%
expm1-log1p99.6%
times-frac99.7%
associate-*r/99.7%
associate-*r/99.7%
associate-/r*99.6%
associate-/l/93.6%
Simplified93.6%
Final simplification93.6%
(FPCore (a b) :precision binary64 (/ (* 0.5 (/ PI (* b a))) (+ b a)))
double code(double a, double b) {
return (0.5 * (((double) M_PI) / (b * a))) / (b + a);
}
public static double code(double a, double b) {
return (0.5 * (Math.PI / (b * a))) / (b + a);
}
def code(a, b): return (0.5 * (math.pi / (b * a))) / (b + a)
function code(a, b) return Float64(Float64(0.5 * Float64(pi / Float64(b * a))) / Float64(b + a)) end
function tmp = code(a, b) tmp = (0.5 * (pi / (b * a))) / (b + a); end
code[a_, b_] := N[(N[(0.5 * N[(Pi / N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(b + a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot \frac{\pi}{b \cdot a}}{b + a}
\end{array}
Initial program 79.2%
associate-*r/79.2%
*-rgt-identity79.2%
associate-*l/79.2%
difference-of-squares90.9%
*-commutative90.9%
times-frac99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
associate-*r/99.6%
associate-/l/99.6%
Applied egg-rr99.6%
Taylor expanded in b around 0 99.7%
Final simplification99.7%
(FPCore (a b) :precision binary64 (* (/ PI a) (/ -0.5 (* b a))))
double code(double a, double b) {
return (((double) M_PI) / a) * (-0.5 / (b * a));
}
public static double code(double a, double b) {
return (Math.PI / a) * (-0.5 / (b * a));
}
def code(a, b): return (math.pi / a) * (-0.5 / (b * a))
function code(a, b) return Float64(Float64(pi / a) * Float64(-0.5 / Float64(b * a))) end
function tmp = code(a, b) tmp = (pi / a) * (-0.5 / (b * a)); end
code[a_, b_] := N[(N[(Pi / a), $MachinePrecision] * N[(-0.5 / N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi}{a} \cdot \frac{-0.5}{b \cdot a}
\end{array}
Initial program 79.2%
associate-*r/79.2%
*-rgt-identity79.2%
associate-*l/79.2%
difference-of-squares90.9%
*-commutative90.9%
times-frac99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in a around inf 62.7%
Taylor expanded in b around 0 60.9%
associate-*r/60.9%
Simplified60.9%
*-commutative60.9%
frac-2neg60.9%
metadata-eval60.9%
frac-times60.8%
*-un-lft-identity60.8%
*-commutative60.8%
Applied egg-rr60.8%
*-commutative60.8%
times-frac60.9%
add-sqr-sqrt28.9%
sqrt-unprod41.4%
sqr-neg41.4%
sqrt-unprod16.2%
add-sqr-sqrt33.3%
*-commutative33.3%
Applied egg-rr33.3%
Final simplification33.3%
herbie shell --seed 2023332
(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))))