
(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 5 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}
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(Float64(pi / 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[(N[(Pi / a), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] / N[(a + b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{0.5 \cdot \frac{\frac{\pi}{a}}{b}}{a + b}
\end{array}
Initial program 78.9%
un-div-inv79.0%
difference-of-squares89.1%
associate-/r*89.8%
div-inv89.8%
metadata-eval89.8%
Applied egg-rr89.8%
associate-*l/99.7%
associate-/l*99.6%
Applied egg-rr99.6%
associate-/l*99.6%
associate-*r/99.6%
*-commutative99.6%
+-commutative99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
associate-*l/99.7%
Applied egg-rr99.7%
Taylor expanded in a around 0 99.7%
associate-/r*99.8%
Simplified99.8%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -3.05e+103) (/ (* 0.5 PI) (* (* a b) (- b a))) (* (/ 0.5 (* a b)) (/ PI b))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -3.05e+103) {
tmp = (0.5 * ((double) M_PI)) / ((a * b) * (b - a));
} else {
tmp = (0.5 / (a * b)) * (((double) M_PI) / b);
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -3.05e+103) {
tmp = (0.5 * Math.PI) / ((a * b) * (b - a));
} else {
tmp = (0.5 / (a * b)) * (Math.PI / b);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -3.05e+103: tmp = (0.5 * math.pi) / ((a * b) * (b - a)) else: tmp = (0.5 / (a * b)) * (math.pi / b) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -3.05e+103) tmp = Float64(Float64(0.5 * pi) / Float64(Float64(a * b) * Float64(b - a))); else tmp = Float64(Float64(0.5 / Float64(a * b)) * Float64(pi / b)); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -3.05e+103)
tmp = (0.5 * pi) / ((a * b) * (b - a));
else
tmp = (0.5 / (a * b)) * (pi / 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, -3.05e+103], N[(N[(0.5 * Pi), $MachinePrecision] / N[(N[(a * b), $MachinePrecision] * N[(b - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 / N[(a * b), $MachinePrecision]), $MachinePrecision] * N[(Pi / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -3.05 \cdot 10^{+103}:\\
\;\;\;\;\frac{0.5 \cdot \pi}{\left(a \cdot b\right) \cdot \left(b - a\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{a \cdot b} \cdot \frac{\pi}{b}\\
\end{array}
\end{array}
if a < -3.0500000000000001e103Initial program 62.1%
*-commutative62.1%
associate-*r*62.1%
associate-*r/62.1%
associate-*r*62.1%
*-rgt-identity62.1%
sub-neg62.1%
distribute-neg-frac62.1%
metadata-eval62.1%
Simplified62.1%
difference-of-squares80.3%
times-frac99.8%
add-sqr-sqrt47.5%
sqrt-unprod57.7%
frac-times57.7%
metadata-eval57.7%
metadata-eval57.7%
frac-times57.7%
sqrt-unprod32.5%
add-sqr-sqrt62.5%
div-inv62.5%
metadata-eval62.5%
Applied egg-rr62.5%
+-commutative62.5%
+-commutative62.5%
*-commutative62.5%
Simplified62.5%
Taylor expanded in b around 0 62.5%
frac-times62.6%
*-un-lft-identity62.6%
Applied egg-rr62.6%
if -3.0500000000000001e103 < a Initial program 82.4%
*-commutative82.4%
associate-*r*82.4%
associate-*r/82.5%
associate-*r*82.5%
*-rgt-identity82.5%
sub-neg82.5%
distribute-neg-frac82.5%
metadata-eval82.5%
Simplified82.5%
difference-of-squares91.0%
times-frac99.6%
add-sqr-sqrt50.2%
sqrt-unprod81.1%
frac-times81.0%
metadata-eval81.0%
metadata-eval81.0%
frac-times81.1%
sqrt-unprod34.5%
add-sqr-sqrt71.5%
div-inv71.5%
metadata-eval71.5%
Applied egg-rr71.5%
+-commutative71.5%
+-commutative71.5%
*-commutative71.5%
Simplified71.5%
Taylor expanded in b around 0 71.5%
frac-times70.9%
*-un-lft-identity70.9%
Applied egg-rr70.9%
times-frac71.5%
Simplified71.5%
Taylor expanded in b around inf 72.8%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -3.75e+99) (/ (* (/ PI a) -0.5) (* a b)) (* (/ 0.5 (* a b)) (/ PI b))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -3.75e+99) {
tmp = ((((double) M_PI) / a) * -0.5) / (a * b);
} else {
tmp = (0.5 / (a * b)) * (((double) M_PI) / b);
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -3.75e+99) {
tmp = ((Math.PI / a) * -0.5) / (a * b);
} else {
tmp = (0.5 / (a * b)) * (Math.PI / b);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -3.75e+99: tmp = ((math.pi / a) * -0.5) / (a * b) else: tmp = (0.5 / (a * b)) * (math.pi / b) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -3.75e+99) tmp = Float64(Float64(Float64(pi / a) * -0.5) / Float64(a * b)); else tmp = Float64(Float64(0.5 / Float64(a * b)) * Float64(pi / b)); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -3.75e+99)
tmp = ((pi / a) * -0.5) / (a * b);
else
tmp = (0.5 / (a * b)) * (pi / 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, -3.75e+99], N[(N[(N[(Pi / a), $MachinePrecision] * -0.5), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 / N[(a * b), $MachinePrecision]), $MachinePrecision] * N[(Pi / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -3.75 \cdot 10^{+99}:\\
\;\;\;\;\frac{\frac{\pi}{a} \cdot -0.5}{a \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{a \cdot b} \cdot \frac{\pi}{b}\\
\end{array}
\end{array}
if a < -3.74999999999999982e99Initial program 62.1%
*-commutative62.1%
associate-*r*62.1%
associate-*r/62.1%
associate-*r*62.1%
*-rgt-identity62.1%
sub-neg62.1%
distribute-neg-frac62.1%
metadata-eval62.1%
Simplified62.1%
difference-of-squares80.3%
times-frac99.8%
add-sqr-sqrt47.5%
sqrt-unprod57.7%
frac-times57.7%
metadata-eval57.7%
metadata-eval57.7%
frac-times57.7%
sqrt-unprod32.5%
add-sqr-sqrt62.5%
div-inv62.5%
metadata-eval62.5%
Applied egg-rr62.5%
+-commutative62.5%
+-commutative62.5%
*-commutative62.5%
Simplified62.5%
Taylor expanded in b around 0 62.5%
associate-*l/62.5%
*-un-lft-identity62.5%
Applied egg-rr62.5%
Taylor expanded in b around 0 62.5%
if -3.74999999999999982e99 < a Initial program 82.4%
*-commutative82.4%
associate-*r*82.4%
associate-*r/82.5%
associate-*r*82.5%
*-rgt-identity82.5%
sub-neg82.5%
distribute-neg-frac82.5%
metadata-eval82.5%
Simplified82.5%
difference-of-squares91.0%
times-frac99.6%
add-sqr-sqrt50.2%
sqrt-unprod81.1%
frac-times81.0%
metadata-eval81.0%
metadata-eval81.0%
frac-times81.1%
sqrt-unprod34.5%
add-sqr-sqrt71.5%
div-inv71.5%
metadata-eval71.5%
Applied egg-rr71.5%
+-commutative71.5%
+-commutative71.5%
*-commutative71.5%
Simplified71.5%
Taylor expanded in b around 0 71.5%
frac-times70.9%
*-un-lft-identity70.9%
Applied egg-rr70.9%
times-frac71.5%
Simplified71.5%
Taylor expanded in b around inf 72.8%
Final simplification71.0%
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}
Initial program 78.9%
un-div-inv79.0%
difference-of-squares89.1%
associate-/r*89.8%
div-inv89.8%
metadata-eval89.8%
Applied egg-rr89.8%
associate-*l/99.7%
associate-/l*99.6%
Applied egg-rr99.6%
associate-/l*99.6%
associate-*r/99.6%
*-commutative99.6%
+-commutative99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
associate-*l/99.7%
Applied egg-rr99.7%
Taylor expanded in a around 0 99.7%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (* (/ 0.5 (* a b)) (/ PI b)))
assert(a < b);
double code(double a, double b) {
return (0.5 / (a * b)) * (((double) M_PI) / b);
}
assert a < b;
public static double code(double a, double b) {
return (0.5 / (a * b)) * (Math.PI / b);
}
[a, b] = sort([a, b]) def code(a, b): return (0.5 / (a * b)) * (math.pi / b)
a, b = sort([a, b]) function code(a, b) return Float64(Float64(0.5 / Float64(a * b)) * Float64(pi / b)) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = (0.5 / (a * b)) * (pi / b);
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(0.5 / N[(a * b), $MachinePrecision]), $MachinePrecision] * N[(Pi / b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{0.5}{a \cdot b} \cdot \frac{\pi}{b}
\end{array}
Initial program 78.9%
*-commutative78.9%
associate-*r*78.9%
associate-*r/79.0%
associate-*r*79.0%
*-rgt-identity79.0%
sub-neg79.0%
distribute-neg-frac79.0%
metadata-eval79.0%
Simplified79.0%
difference-of-squares89.1%
times-frac99.6%
add-sqr-sqrt49.8%
sqrt-unprod77.0%
frac-times77.0%
metadata-eval77.0%
metadata-eval77.0%
frac-times77.0%
sqrt-unprod34.2%
add-sqr-sqrt70.0%
div-inv70.0%
metadata-eval70.0%
Applied egg-rr70.0%
+-commutative70.0%
+-commutative70.0%
*-commutative70.0%
Simplified70.0%
Taylor expanded in b around 0 70.0%
frac-times69.5%
*-un-lft-identity69.5%
Applied egg-rr69.5%
times-frac70.0%
Simplified70.0%
Taylor expanded in b around inf 67.6%
herbie shell --seed 2024160
(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))))