
(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 (* (/ 0.5 (+ a b)) (/ PI (* a b))))
double code(double a, double b) {
return (0.5 / (a + b)) * (((double) M_PI) / (a * b));
}
public static double code(double a, double b) {
return (0.5 / (a + b)) * (Math.PI / (a * b));
}
def code(a, b): return (0.5 / (a + b)) * (math.pi / (a * b))
function code(a, b) return Float64(Float64(0.5 / Float64(a + b)) * Float64(pi / Float64(a * b))) end
function tmp = code(a, b) tmp = (0.5 / (a + b)) * (pi / (a * b)); end
code[a_, b_] := N[(N[(0.5 / N[(a + b), $MachinePrecision]), $MachinePrecision] * N[(Pi / N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5}{a + b} \cdot \frac{\pi}{a \cdot b}
\end{array}
Initial program 78.3%
*-commutative78.3%
*-commutative78.3%
associate-*l/78.3%
*-lft-identity78.3%
sub-neg78.3%
distribute-neg-frac78.3%
metadata-eval78.3%
Simplified78.3%
Taylor expanded in a around 0 57.4%
div-inv57.4%
metadata-eval57.4%
*-commutative57.4%
difference-of-squares63.3%
frac-times63.3%
associate-*r/63.3%
+-commutative63.3%
*-commutative63.3%
frac-times69.3%
*-un-lft-identity69.3%
*-commutative69.3%
Applied egg-rr69.3%
Taylor expanded in a around 0 99.6%
add099.6%
associate-/l*99.6%
Applied egg-rr99.6%
add099.6%
Simplified99.6%
Final simplification99.6%
(FPCore (a b) :precision binary64 (if (<= a -2.1e-114) (* (/ PI (- b a)) (/ -0.5 (* a b))) (/ (/ (* 0.5 PI) b) (* a b))))
double code(double a, double b) {
double tmp;
if (a <= -2.1e-114) {
tmp = (((double) M_PI) / (b - a)) * (-0.5 / (a * b));
} else {
tmp = ((0.5 * ((double) M_PI)) / b) / (a * b);
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (a <= -2.1e-114) {
tmp = (Math.PI / (b - a)) * (-0.5 / (a * b));
} else {
tmp = ((0.5 * Math.PI) / b) / (a * b);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -2.1e-114: tmp = (math.pi / (b - a)) * (-0.5 / (a * b)) else: tmp = ((0.5 * math.pi) / b) / (a * b) return tmp
function code(a, b) tmp = 0.0 if (a <= -2.1e-114) tmp = Float64(Float64(pi / Float64(b - a)) * Float64(-0.5 / Float64(a * b))); else tmp = Float64(Float64(Float64(0.5 * pi) / b) / Float64(a * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -2.1e-114) tmp = (pi / (b - a)) * (-0.5 / (a * b)); else tmp = ((0.5 * pi) / b) / (a * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -2.1e-114], N[(N[(Pi / N[(b - a), $MachinePrecision]), $MachinePrecision] * N[(-0.5 / N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.5 * Pi), $MachinePrecision] / b), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.1 \cdot 10^{-114}:\\
\;\;\;\;\frac{\pi}{b - a} \cdot \frac{-0.5}{a \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5 \cdot \pi}{b}}{a \cdot b}\\
\end{array}
\end{array}
if a < -2.09999999999999993e-114Initial program 80.7%
*-commutative80.7%
*-commutative80.7%
associate-*l/80.7%
*-lft-identity80.7%
sub-neg80.7%
distribute-neg-frac80.7%
metadata-eval80.7%
Simplified80.7%
div-inv80.7%
metadata-eval80.7%
*-commutative80.7%
difference-of-squares92.9%
times-frac93.6%
Applied egg-rr93.6%
add093.6%
associate-*r*99.6%
fma-define99.6%
+-commutative99.6%
Applied egg-rr99.6%
fma-undefine99.6%
+-rgt-identity99.6%
Simplified99.6%
Taylor expanded in a around inf 91.6%
if -2.09999999999999993e-114 < a Initial program 77.2%
*-commutative77.2%
*-commutative77.2%
associate-*l/77.2%
*-lft-identity77.2%
sub-neg77.2%
distribute-neg-frac77.2%
metadata-eval77.2%
Simplified77.2%
Taylor expanded in a around 0 62.4%
div-inv62.4%
metadata-eval62.4%
*-commutative62.4%
difference-of-squares65.3%
frac-times65.4%
associate-*r/65.3%
+-commutative65.3%
*-commutative65.3%
frac-times74.1%
*-un-lft-identity74.1%
*-commutative74.1%
Applied egg-rr74.1%
Taylor expanded in a around 0 99.6%
Taylor expanded in a around 0 69.6%
associate-*r/69.6%
Simplified69.6%
Final simplification76.6%
(FPCore (a b) :precision binary64 (if (<= b 8.8e-82) (/ (* 0.5 (/ PI a)) (* a b)) (* (/ 0.5 (* a b)) (/ PI (- b a)))))
double code(double a, double b) {
double tmp;
if (b <= 8.8e-82) {
tmp = (0.5 * (((double) M_PI) / a)) / (a * b);
} else {
tmp = (0.5 / (a * b)) * (((double) M_PI) / (b - a));
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (b <= 8.8e-82) {
tmp = (0.5 * (Math.PI / a)) / (a * b);
} else {
tmp = (0.5 / (a * b)) * (Math.PI / (b - a));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 8.8e-82: tmp = (0.5 * (math.pi / a)) / (a * b) else: tmp = (0.5 / (a * b)) * (math.pi / (b - a)) return tmp
function code(a, b) tmp = 0.0 if (b <= 8.8e-82) tmp = Float64(Float64(0.5 * Float64(pi / a)) / Float64(a * b)); else tmp = Float64(Float64(0.5 / Float64(a * b)) * Float64(pi / Float64(b - a))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 8.8e-82) tmp = (0.5 * (pi / a)) / (a * b); else tmp = (0.5 / (a * b)) * (pi / (b - a)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 8.8e-82], N[(N[(0.5 * N[(Pi / a), $MachinePrecision]), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 / N[(a * b), $MachinePrecision]), $MachinePrecision] * N[(Pi / N[(b - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 8.8 \cdot 10^{-82}:\\
\;\;\;\;\frac{0.5 \cdot \frac{\pi}{a}}{a \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{a \cdot b} \cdot \frac{\pi}{b - a}\\
\end{array}
\end{array}
if b < 8.79999999999999943e-82Initial program 80.0%
*-commutative80.0%
*-commutative80.0%
associate-*l/79.9%
*-lft-identity79.9%
sub-neg79.9%
distribute-neg-frac79.9%
metadata-eval79.9%
Simplified79.9%
Taylor expanded in a around 0 53.7%
div-inv53.7%
metadata-eval53.7%
*-commutative53.7%
difference-of-squares57.5%
frac-times57.6%
associate-*r/57.6%
+-commutative57.6%
*-commutative57.6%
frac-times61.0%
*-un-lft-identity61.0%
*-commutative61.0%
Applied egg-rr61.0%
Taylor expanded in a around 0 99.6%
Taylor expanded in a around inf 73.2%
if 8.79999999999999943e-82 < b Initial program 73.9%
*-commutative73.9%
*-commutative73.9%
associate-*l/73.9%
*-lft-identity73.9%
sub-neg73.9%
distribute-neg-frac73.9%
metadata-eval73.9%
Simplified73.9%
div-inv73.9%
metadata-eval73.9%
*-commutative73.9%
difference-of-squares85.5%
times-frac85.5%
Applied egg-rr85.5%
add085.5%
associate-*r*99.6%
fma-define99.6%
+-commutative99.6%
Applied egg-rr99.6%
fma-undefine99.6%
+-rgt-identity99.6%
Simplified99.6%
Taylor expanded in a around 0 91.6%
Final simplification78.1%
(FPCore (a b) :precision binary64 (if (<= a -1.32e-83) (/ (* 0.5 (/ PI a)) (* a b)) (/ (* PI (/ 0.5 b)) (* a b))))
double code(double a, double b) {
double tmp;
if (a <= -1.32e-83) {
tmp = (0.5 * (((double) M_PI) / a)) / (a * b);
} else {
tmp = (((double) M_PI) * (0.5 / b)) / (a * b);
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (a <= -1.32e-83) {
tmp = (0.5 * (Math.PI / a)) / (a * b);
} else {
tmp = (Math.PI * (0.5 / b)) / (a * b);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.32e-83: tmp = (0.5 * (math.pi / a)) / (a * b) else: tmp = (math.pi * (0.5 / b)) / (a * b) return tmp
function code(a, b) tmp = 0.0 if (a <= -1.32e-83) tmp = Float64(Float64(0.5 * Float64(pi / a)) / Float64(a * b)); else tmp = Float64(Float64(pi * Float64(0.5 / b)) / Float64(a * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1.32e-83) tmp = (0.5 * (pi / a)) / (a * b); else tmp = (pi * (0.5 / b)) / (a * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.32e-83], N[(N[(0.5 * N[(Pi / a), $MachinePrecision]), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision], N[(N[(Pi * N[(0.5 / b), $MachinePrecision]), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.32 \cdot 10^{-83}:\\
\;\;\;\;\frac{0.5 \cdot \frac{\pi}{a}}{a \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\pi \cdot \frac{0.5}{b}}{a \cdot b}\\
\end{array}
\end{array}
if a < -1.31999999999999994e-83Initial program 79.7%
*-commutative79.7%
*-commutative79.7%
associate-*l/79.7%
*-lft-identity79.7%
sub-neg79.7%
distribute-neg-frac79.7%
metadata-eval79.7%
Simplified79.7%
Taylor expanded in a around 0 45.4%
div-inv45.4%
metadata-eval45.4%
*-commutative45.4%
difference-of-squares58.2%
frac-times58.2%
associate-*r/58.2%
+-commutative58.2%
*-commutative58.2%
frac-times58.2%
*-un-lft-identity58.2%
*-commutative58.2%
Applied egg-rr58.2%
Taylor expanded in a around 0 99.5%
Taylor expanded in a around inf 88.8%
if -1.31999999999999994e-83 < a Initial program 77.7%
*-commutative77.7%
*-commutative77.7%
associate-*l/77.7%
*-lft-identity77.7%
sub-neg77.7%
distribute-neg-frac77.7%
metadata-eval77.7%
Simplified77.7%
Taylor expanded in a around 0 62.7%
div-inv62.7%
metadata-eval62.7%
*-commutative62.7%
difference-of-squares65.5%
frac-times65.6%
associate-*r/65.5%
+-commutative65.5%
*-commutative65.5%
frac-times74.1%
*-un-lft-identity74.1%
*-commutative74.1%
Applied egg-rr74.1%
Taylor expanded in a around 0 99.6%
Taylor expanded in a around 0 69.6%
Final simplification75.5%
(FPCore (a b) :precision binary64 (if (<= a -1.32e-83) (/ (* 0.5 (/ PI a)) (* a b)) (/ (/ (* 0.5 PI) b) (* a b))))
double code(double a, double b) {
double tmp;
if (a <= -1.32e-83) {
tmp = (0.5 * (((double) M_PI) / a)) / (a * b);
} else {
tmp = ((0.5 * ((double) M_PI)) / b) / (a * b);
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (a <= -1.32e-83) {
tmp = (0.5 * (Math.PI / a)) / (a * b);
} else {
tmp = ((0.5 * Math.PI) / b) / (a * b);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.32e-83: tmp = (0.5 * (math.pi / a)) / (a * b) else: tmp = ((0.5 * math.pi) / b) / (a * b) return tmp
function code(a, b) tmp = 0.0 if (a <= -1.32e-83) tmp = Float64(Float64(0.5 * Float64(pi / a)) / Float64(a * b)); else tmp = Float64(Float64(Float64(0.5 * pi) / b) / Float64(a * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1.32e-83) tmp = (0.5 * (pi / a)) / (a * b); else tmp = ((0.5 * pi) / b) / (a * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.32e-83], N[(N[(0.5 * N[(Pi / a), $MachinePrecision]), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.5 * Pi), $MachinePrecision] / b), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.32 \cdot 10^{-83}:\\
\;\;\;\;\frac{0.5 \cdot \frac{\pi}{a}}{a \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5 \cdot \pi}{b}}{a \cdot b}\\
\end{array}
\end{array}
if a < -1.31999999999999994e-83Initial program 79.7%
*-commutative79.7%
*-commutative79.7%
associate-*l/79.7%
*-lft-identity79.7%
sub-neg79.7%
distribute-neg-frac79.7%
metadata-eval79.7%
Simplified79.7%
Taylor expanded in a around 0 45.4%
div-inv45.4%
metadata-eval45.4%
*-commutative45.4%
difference-of-squares58.2%
frac-times58.2%
associate-*r/58.2%
+-commutative58.2%
*-commutative58.2%
frac-times58.2%
*-un-lft-identity58.2%
*-commutative58.2%
Applied egg-rr58.2%
Taylor expanded in a around 0 99.5%
Taylor expanded in a around inf 88.8%
if -1.31999999999999994e-83 < a Initial program 77.7%
*-commutative77.7%
*-commutative77.7%
associate-*l/77.7%
*-lft-identity77.7%
sub-neg77.7%
distribute-neg-frac77.7%
metadata-eval77.7%
Simplified77.7%
Taylor expanded in a around 0 62.7%
div-inv62.7%
metadata-eval62.7%
*-commutative62.7%
difference-of-squares65.5%
frac-times65.6%
associate-*r/65.5%
+-commutative65.5%
*-commutative65.5%
frac-times74.1%
*-un-lft-identity74.1%
*-commutative74.1%
Applied egg-rr74.1%
Taylor expanded in a around 0 99.6%
Taylor expanded in a around 0 69.7%
associate-*r/69.7%
Simplified69.7%
Final simplification75.5%
(FPCore (a b) :precision binary64 (/ (* 0.5 (/ PI a)) (* a b)))
double code(double a, double b) {
return (0.5 * (((double) M_PI) / a)) / (a * b);
}
public static double code(double a, double b) {
return (0.5 * (Math.PI / a)) / (a * b);
}
def code(a, b): return (0.5 * (math.pi / a)) / (a * b)
function code(a, b) return Float64(Float64(0.5 * Float64(pi / a)) / Float64(a * b)) end
function tmp = code(a, b) tmp = (0.5 * (pi / a)) / (a * b); end
code[a_, b_] := N[(N[(0.5 * N[(Pi / a), $MachinePrecision]), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot \frac{\pi}{a}}{a \cdot b}
\end{array}
Initial program 78.3%
*-commutative78.3%
*-commutative78.3%
associate-*l/78.3%
*-lft-identity78.3%
sub-neg78.3%
distribute-neg-frac78.3%
metadata-eval78.3%
Simplified78.3%
Taylor expanded in a around 0 57.4%
div-inv57.4%
metadata-eval57.4%
*-commutative57.4%
difference-of-squares63.3%
frac-times63.3%
associate-*r/63.3%
+-commutative63.3%
*-commutative63.3%
frac-times69.3%
*-un-lft-identity69.3%
*-commutative69.3%
Applied egg-rr69.3%
Taylor expanded in a around 0 99.6%
Taylor expanded in a around inf 66.0%
Final simplification66.0%
herbie shell --seed 2024046
(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))))