
(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 8 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 0.5) (+ b a)) (- (/ 1.0 a) (/ 1.0 b))) (- b a)))
double code(double a, double b) {
return (((((double) M_PI) * 0.5) / (b + a)) * ((1.0 / a) - (1.0 / b))) / (b - a);
}
public static double code(double a, double b) {
return (((Math.PI * 0.5) / (b + a)) * ((1.0 / a) - (1.0 / b))) / (b - a);
}
def code(a, b): return (((math.pi * 0.5) / (b + a)) * ((1.0 / a) - (1.0 / b))) / (b - a)
function code(a, b) return Float64(Float64(Float64(Float64(pi * 0.5) / Float64(b + a)) * Float64(Float64(1.0 / a) - Float64(1.0 / b))) / Float64(b - a)) end
function tmp = code(a, b) tmp = (((pi * 0.5) / (b + a)) * ((1.0 / a) - (1.0 / b))) / (b - a); end
code[a_, b_] := N[(N[(N[(N[(Pi * 0.5), $MachinePrecision] / N[(b + a), $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 / a), $MachinePrecision] - N[(1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(b - a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\pi \cdot 0.5}{b + a} \cdot \left(\frac{1}{a} - \frac{1}{b}\right)}{b - a}
\end{array}
Initial program 83.3%
un-div-inv83.4%
difference-of-squares92.0%
associate-/r*92.1%
div-inv92.1%
metadata-eval92.1%
Applied egg-rr92.1%
associate-*l/99.7%
Applied egg-rr99.7%
(FPCore (a b) :precision binary64 (* (* 0.5 (/ PI (+ b a))) (/ (- (/ 1.0 a) (/ 1.0 b)) (- b a))))
double code(double a, double b) {
return (0.5 * (((double) M_PI) / (b + a))) * (((1.0 / a) - (1.0 / b)) / (b - a));
}
public static double code(double a, double b) {
return (0.5 * (Math.PI / (b + a))) * (((1.0 / a) - (1.0 / b)) / (b - a));
}
def code(a, b): return (0.5 * (math.pi / (b + a))) * (((1.0 / a) - (1.0 / b)) / (b - a))
function code(a, b) return Float64(Float64(0.5 * Float64(pi / Float64(b + a))) * Float64(Float64(Float64(1.0 / a) - Float64(1.0 / b)) / Float64(b - a))) end
function tmp = code(a, b) tmp = (0.5 * (pi / (b + a))) * (((1.0 / a) - (1.0 / b)) / (b - a)); end
code[a_, b_] := N[(N[(0.5 * N[(Pi / N[(b + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(1.0 / a), $MachinePrecision] - N[(1.0 / b), $MachinePrecision]), $MachinePrecision] / N[(b - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \frac{\pi}{b + a}\right) \cdot \frac{\frac{1}{a} - \frac{1}{b}}{b - a}
\end{array}
Initial program 83.3%
un-div-inv83.4%
difference-of-squares92.0%
associate-/r*92.1%
div-inv92.1%
metadata-eval92.1%
Applied egg-rr92.1%
associate-*l/99.7%
Applied egg-rr99.7%
associate-/l*99.6%
*-commutative99.6%
associate-*r/99.6%
+-commutative99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (a b) :precision binary64 (if (<= a -4.4e-70) (* (/ -0.5 a) (/ (/ PI b) (- b a))) (/ (/ (* PI (/ 0.5 a)) (+ b a)) (- b a))))
double code(double a, double b) {
double tmp;
if (a <= -4.4e-70) {
tmp = (-0.5 / a) * ((((double) M_PI) / b) / (b - a));
} else {
tmp = ((((double) M_PI) * (0.5 / a)) / (b + a)) / (b - a);
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (a <= -4.4e-70) {
tmp = (-0.5 / a) * ((Math.PI / b) / (b - a));
} else {
tmp = ((Math.PI * (0.5 / a)) / (b + a)) / (b - a);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -4.4e-70: tmp = (-0.5 / a) * ((math.pi / b) / (b - a)) else: tmp = ((math.pi * (0.5 / a)) / (b + a)) / (b - a) return tmp
function code(a, b) tmp = 0.0 if (a <= -4.4e-70) tmp = Float64(Float64(-0.5 / a) * Float64(Float64(pi / b) / Float64(b - a))); else tmp = Float64(Float64(Float64(pi * Float64(0.5 / a)) / Float64(b + a)) / Float64(b - a)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -4.4e-70) tmp = (-0.5 / a) * ((pi / b) / (b - a)); else tmp = ((pi * (0.5 / a)) / (b + a)) / (b - a); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -4.4e-70], N[(N[(-0.5 / a), $MachinePrecision] * N[(N[(Pi / b), $MachinePrecision] / N[(b - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(Pi * N[(0.5 / a), $MachinePrecision]), $MachinePrecision] / N[(b + a), $MachinePrecision]), $MachinePrecision] / N[(b - a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -4.4 \cdot 10^{-70}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \frac{\frac{\pi}{b}}{b - a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\pi \cdot \frac{0.5}{a}}{b + a}}{b - a}\\
\end{array}
\end{array}
if a < -4.3999999999999998e-70Initial program 86.2%
un-div-inv86.2%
difference-of-squares97.2%
associate-/r*97.2%
div-inv97.2%
metadata-eval97.2%
Applied egg-rr97.2%
associate-*l/99.7%
Applied egg-rr99.7%
Taylor expanded in b around 0 87.1%
*-un-lft-identity87.1%
associate-*r/87.1%
times-frac87.1%
Applied egg-rr87.1%
*-lft-identity87.1%
associate-/l*87.2%
Simplified87.2%
if -4.3999999999999998e-70 < a Initial program 82.2%
associate-*l*82.2%
*-rgt-identity82.2%
associate-/l*82.2%
metadata-eval82.2%
associate-*l/82.2%
*-lft-identity82.2%
sub-neg82.2%
distribute-neg-frac82.2%
metadata-eval82.2%
Simplified82.2%
metadata-eval82.2%
div-inv82.2%
associate-*r/82.2%
*-commutative82.2%
difference-of-squares89.9%
associate-/r*99.6%
Applied egg-rr71.9%
Taylor expanded in a around 0 77.8%
(FPCore (a b) :precision binary64 (if (<= a -2.7e-92) (* (/ -0.5 a) (/ (/ PI b) (- b a))) (/ (/ (* PI 0.5) (* b a)) b)))
double code(double a, double b) {
double tmp;
if (a <= -2.7e-92) {
tmp = (-0.5 / a) * ((((double) M_PI) / b) / (b - a));
} else {
tmp = ((((double) M_PI) * 0.5) / (b * a)) / b;
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (a <= -2.7e-92) {
tmp = (-0.5 / a) * ((Math.PI / b) / (b - a));
} else {
tmp = ((Math.PI * 0.5) / (b * a)) / b;
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -2.7e-92: tmp = (-0.5 / a) * ((math.pi / b) / (b - a)) else: tmp = ((math.pi * 0.5) / (b * a)) / b return tmp
function code(a, b) tmp = 0.0 if (a <= -2.7e-92) tmp = Float64(Float64(-0.5 / a) * Float64(Float64(pi / b) / Float64(b - a))); else tmp = Float64(Float64(Float64(pi * 0.5) / Float64(b * a)) / b); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -2.7e-92) tmp = (-0.5 / a) * ((pi / b) / (b - a)); else tmp = ((pi * 0.5) / (b * a)) / b; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -2.7e-92], N[(N[(-0.5 / a), $MachinePrecision] * N[(N[(Pi / b), $MachinePrecision] / N[(b - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(Pi * 0.5), $MachinePrecision] / N[(b * a), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.7 \cdot 10^{-92}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \frac{\frac{\pi}{b}}{b - a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\pi \cdot 0.5}{b \cdot a}}{b}\\
\end{array}
\end{array}
if a < -2.69999999999999995e-92Initial program 86.5%
un-div-inv86.5%
difference-of-squares97.2%
associate-/r*97.2%
div-inv97.2%
metadata-eval97.2%
Applied egg-rr97.2%
associate-*l/99.7%
Applied egg-rr99.7%
Taylor expanded in b around 0 86.1%
*-un-lft-identity86.1%
associate-*r/86.1%
times-frac86.1%
Applied egg-rr86.1%
*-lft-identity86.1%
associate-/l*86.2%
Simplified86.2%
if -2.69999999999999995e-92 < a Initial program 82.0%
associate-*l*82.0%
*-rgt-identity82.0%
associate-/l*82.0%
metadata-eval82.0%
associate-*l/82.0%
*-lft-identity82.0%
sub-neg82.0%
distribute-neg-frac82.0%
metadata-eval82.0%
Simplified82.0%
Taylor expanded in a around 0 59.5%
associate-*r/59.5%
Simplified59.5%
pow259.5%
associate-/r*59.1%
associate-*r/59.1%
*-un-lft-identity59.1%
times-frac68.5%
Applied egg-rr68.5%
associate-*l/68.6%
*-lft-identity68.6%
associate-/l*68.6%
associate-*l/68.5%
associate-/r*68.6%
Simplified68.6%
*-commutative68.6%
frac-times68.7%
*-un-lft-identity68.7%
frac-times68.5%
*-commutative68.5%
associate-/l/68.5%
associate-*l/68.6%
frac-times68.6%
*-un-lft-identity68.6%
*-commutative68.6%
Applied egg-rr68.6%
(FPCore (a b) :precision binary64 (if (<= a -2.7e-92) (* -0.5 (/ (/ (/ PI a) b) (- b a))) (/ (/ (* PI 0.5) (* b a)) b)))
double code(double a, double b) {
double tmp;
if (a <= -2.7e-92) {
tmp = -0.5 * (((((double) M_PI) / a) / b) / (b - a));
} else {
tmp = ((((double) M_PI) * 0.5) / (b * a)) / b;
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (a <= -2.7e-92) {
tmp = -0.5 * (((Math.PI / a) / b) / (b - a));
} else {
tmp = ((Math.PI * 0.5) / (b * a)) / b;
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -2.7e-92: tmp = -0.5 * (((math.pi / a) / b) / (b - a)) else: tmp = ((math.pi * 0.5) / (b * a)) / b return tmp
function code(a, b) tmp = 0.0 if (a <= -2.7e-92) tmp = Float64(-0.5 * Float64(Float64(Float64(pi / a) / b) / Float64(b - a))); else tmp = Float64(Float64(Float64(pi * 0.5) / Float64(b * a)) / b); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -2.7e-92) tmp = -0.5 * (((pi / a) / b) / (b - a)); else tmp = ((pi * 0.5) / (b * a)) / b; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -2.7e-92], N[(-0.5 * N[(N[(N[(Pi / a), $MachinePrecision] / b), $MachinePrecision] / N[(b - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(Pi * 0.5), $MachinePrecision] / N[(b * a), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.7 \cdot 10^{-92}:\\
\;\;\;\;-0.5 \cdot \frac{\frac{\frac{\pi}{a}}{b}}{b - a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\pi \cdot 0.5}{b \cdot a}}{b}\\
\end{array}
\end{array}
if a < -2.69999999999999995e-92Initial program 86.5%
un-div-inv86.5%
difference-of-squares97.2%
associate-/r*97.2%
div-inv97.2%
metadata-eval97.2%
Applied egg-rr97.2%
associate-*l/99.7%
Applied egg-rr99.7%
Taylor expanded in b around 0 86.1%
associate-/r*86.2%
associate-/l*86.2%
Applied egg-rr86.2%
if -2.69999999999999995e-92 < a Initial program 82.0%
associate-*l*82.0%
*-rgt-identity82.0%
associate-/l*82.0%
metadata-eval82.0%
associate-*l/82.0%
*-lft-identity82.0%
sub-neg82.0%
distribute-neg-frac82.0%
metadata-eval82.0%
Simplified82.0%
Taylor expanded in a around 0 59.5%
associate-*r/59.5%
Simplified59.5%
pow259.5%
associate-/r*59.1%
associate-*r/59.1%
*-un-lft-identity59.1%
times-frac68.5%
Applied egg-rr68.5%
associate-*l/68.6%
*-lft-identity68.6%
associate-/l*68.6%
associate-*l/68.5%
associate-/r*68.6%
Simplified68.6%
*-commutative68.6%
frac-times68.7%
*-un-lft-identity68.7%
frac-times68.5%
*-commutative68.5%
associate-/l/68.5%
associate-*l/68.6%
frac-times68.6%
*-un-lft-identity68.6%
*-commutative68.6%
Applied egg-rr68.6%
(FPCore (a b) :precision binary64 (/ (/ (* PI 0.5) (* b a)) b))
double code(double a, double b) {
return ((((double) M_PI) * 0.5) / (b * a)) / b;
}
public static double code(double a, double b) {
return ((Math.PI * 0.5) / (b * a)) / b;
}
def code(a, b): return ((math.pi * 0.5) / (b * a)) / b
function code(a, b) return Float64(Float64(Float64(pi * 0.5) / Float64(b * a)) / b) end
function tmp = code(a, b) tmp = ((pi * 0.5) / (b * a)) / b; end
code[a_, b_] := N[(N[(N[(Pi * 0.5), $MachinePrecision] / N[(b * a), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\pi \cdot 0.5}{b \cdot a}}{b}
\end{array}
Initial program 83.3%
associate-*l*83.3%
*-rgt-identity83.3%
associate-/l*83.3%
metadata-eval83.3%
associate-*l/83.4%
*-lft-identity83.4%
sub-neg83.4%
distribute-neg-frac83.4%
metadata-eval83.4%
Simplified83.4%
Taylor expanded in a around 0 58.3%
associate-*r/58.3%
Simplified58.3%
pow258.3%
associate-/r*58.0%
associate-*r/58.0%
*-un-lft-identity58.0%
times-frac64.7%
Applied egg-rr64.7%
associate-*l/64.7%
*-lft-identity64.7%
associate-/l*64.7%
associate-*l/64.7%
associate-/r*64.7%
Simplified64.7%
*-commutative64.7%
frac-times64.8%
*-un-lft-identity64.8%
frac-times64.7%
*-commutative64.7%
associate-/l/64.6%
associate-*l/64.7%
frac-times64.7%
*-un-lft-identity64.7%
*-commutative64.7%
Applied egg-rr64.7%
(FPCore (a b) :precision binary64 (/ (* 0.5 (/ (/ PI a) b)) b))
double code(double a, double b) {
return (0.5 * ((((double) M_PI) / a) / b)) / b;
}
public static double code(double a, double b) {
return (0.5 * ((Math.PI / a) / b)) / b;
}
def code(a, b): return (0.5 * ((math.pi / a) / b)) / b
function code(a, b) return Float64(Float64(0.5 * Float64(Float64(pi / a) / b)) / b) end
function tmp = code(a, b) tmp = (0.5 * ((pi / a) / b)) / b; end
code[a_, b_] := N[(N[(0.5 * N[(N[(Pi / a), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot \frac{\frac{\pi}{a}}{b}}{b}
\end{array}
Initial program 83.3%
associate-*l*83.3%
*-rgt-identity83.3%
associate-/l*83.3%
metadata-eval83.3%
associate-*l/83.4%
*-lft-identity83.4%
sub-neg83.4%
distribute-neg-frac83.4%
metadata-eval83.4%
Simplified83.4%
Taylor expanded in a around 0 58.3%
associate-*r/58.3%
Simplified58.3%
pow258.3%
associate-/r*58.0%
associate-*r/58.0%
*-un-lft-identity58.0%
times-frac64.7%
Applied egg-rr64.7%
associate-*l/64.7%
*-lft-identity64.7%
associate-/l*64.7%
associate-*l/64.7%
associate-/r*64.7%
Simplified64.7%
associate-*l/64.7%
associate-/r*64.7%
Applied egg-rr64.7%
(FPCore (a b) :precision binary64 (* (/ 0.5 b) (/ PI (* b a))))
double code(double a, double b) {
return (0.5 / b) * (((double) M_PI) / (b * a));
}
public static double code(double a, double b) {
return (0.5 / b) * (Math.PI / (b * a));
}
def code(a, b): return (0.5 / b) * (math.pi / (b * a))
function code(a, b) return Float64(Float64(0.5 / b) * Float64(pi / Float64(b * a))) end
function tmp = code(a, b) tmp = (0.5 / b) * (pi / (b * a)); end
code[a_, b_] := N[(N[(0.5 / b), $MachinePrecision] * N[(Pi / N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5}{b} \cdot \frac{\pi}{b \cdot a}
\end{array}
Initial program 83.3%
associate-*l*83.3%
*-rgt-identity83.3%
associate-/l*83.3%
metadata-eval83.3%
associate-*l/83.4%
*-lft-identity83.4%
sub-neg83.4%
distribute-neg-frac83.4%
metadata-eval83.4%
Simplified83.4%
Taylor expanded in a around 0 58.3%
associate-*r/58.3%
Simplified58.3%
pow258.3%
associate-/r*58.0%
associate-*r/58.0%
*-un-lft-identity58.0%
times-frac64.7%
Applied egg-rr64.7%
associate-*l/64.7%
*-lft-identity64.7%
associate-/l*64.7%
associate-*l/64.7%
associate-/r*64.7%
Simplified64.7%
Final simplification64.7%
herbie shell --seed 2024188
(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))))