
(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}
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (/ (* 0.5 (/ (/ PI b) a)) (+ b a)))
assert(a < b);
double code(double a, double b) {
return (0.5 * ((((double) M_PI) / b) / a)) / (b + a);
}
assert a < b;
public static double code(double a, double b) {
return (0.5 * ((Math.PI / b) / a)) / (b + a);
}
[a, b] = sort([a, b]) def code(a, b): return (0.5 * ((math.pi / b) / a)) / (b + a)
a, b = sort([a, b]) function code(a, b) return Float64(Float64(0.5 * Float64(Float64(pi / b) / a)) / Float64(b + a)) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = (0.5 * ((pi / b) / a)) / (b + a);
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 / b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] / N[(b + a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{0.5 \cdot \frac{\frac{\pi}{b}}{a}}{b + a}
\end{array}
Initial program 78.5%
*-commutative78.5%
associate-*r*78.6%
associate-*r/78.6%
associate-*r*78.6%
*-rgt-identity78.6%
sub-neg78.6%
distribute-neg-frac78.6%
metadata-eval78.6%
Simplified78.6%
*-un-lft-identity78.6%
difference-of-squares88.4%
times-frac99.6%
add-sqr-sqrt49.8%
sqrt-unprod74.4%
frac-times74.4%
metadata-eval74.4%
metadata-eval74.4%
frac-times74.4%
sqrt-unprod32.2%
add-sqr-sqrt65.5%
div-inv65.5%
metadata-eval65.5%
Applied egg-rr65.5%
associate-*l/65.5%
associate-/l*65.5%
+-commutative65.5%
*-commutative65.5%
+-commutative65.5%
Simplified65.5%
Taylor expanded in b around inf 99.7%
associate-/r*99.7%
clear-num99.6%
inv-pow99.6%
Applied egg-rr99.6%
unpow-199.6%
associate-/r/99.7%
Simplified99.7%
associate-/r*99.7%
div-inv99.6%
clear-num99.7%
Applied egg-rr99.7%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
Final simplification99.7%
NOTE: a and b should be sorted in increasing order before calling this function.
(FPCore (a b)
:precision binary64
(let* ((t_0 (/ PI (* b a))))
(if (or (<= a -1.1e-26) (and (not (<= a -2.35e-61)) (<= a -7e-117)))
(* t_0 (/ 0.5 a))
(* t_0 (/ 0.5 b)))))assert(a < b);
double code(double a, double b) {
double t_0 = ((double) M_PI) / (b * a);
double tmp;
if ((a <= -1.1e-26) || (!(a <= -2.35e-61) && (a <= -7e-117))) {
tmp = t_0 * (0.5 / a);
} else {
tmp = t_0 * (0.5 / b);
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double t_0 = Math.PI / (b * a);
double tmp;
if ((a <= -1.1e-26) || (!(a <= -2.35e-61) && (a <= -7e-117))) {
tmp = t_0 * (0.5 / a);
} else {
tmp = t_0 * (0.5 / b);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): t_0 = math.pi / (b * a) tmp = 0 if (a <= -1.1e-26) or (not (a <= -2.35e-61) and (a <= -7e-117)): tmp = t_0 * (0.5 / a) else: tmp = t_0 * (0.5 / b) return tmp
a, b = sort([a, b]) function code(a, b) t_0 = Float64(pi / Float64(b * a)) tmp = 0.0 if ((a <= -1.1e-26) || (!(a <= -2.35e-61) && (a <= -7e-117))) tmp = Float64(t_0 * Float64(0.5 / a)); else tmp = Float64(t_0 * Float64(0.5 / b)); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
t_0 = pi / (b * a);
tmp = 0.0;
if ((a <= -1.1e-26) || (~((a <= -2.35e-61)) && (a <= -7e-117)))
tmp = t_0 * (0.5 / a);
else
tmp = t_0 * (0.5 / b);
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function.
code[a_, b_] := Block[{t$95$0 = N[(Pi / N[(b * a), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[a, -1.1e-26], And[N[Not[LessEqual[a, -2.35e-61]], $MachinePrecision], LessEqual[a, -7e-117]]], N[(t$95$0 * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(0.5 / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
t_0 := \frac{\pi}{b \cdot a}\\
\mathbf{if}\;a \leq -1.1 \cdot 10^{-26} \lor \neg \left(a \leq -2.35 \cdot 10^{-61}\right) \land a \leq -7 \cdot 10^{-117}:\\
\;\;\;\;t\_0 \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \frac{0.5}{b}\\
\end{array}
\end{array}
if a < -1.1e-26 or -2.3499999999999998e-61 < a < -6.9999999999999997e-117Initial program 79.6%
*-commutative79.6%
associate-*r*79.7%
associate-*r/79.7%
associate-*r*79.7%
*-rgt-identity79.7%
sub-neg79.7%
distribute-neg-frac79.7%
metadata-eval79.7%
Simplified79.7%
*-un-lft-identity79.7%
difference-of-squares89.1%
times-frac99.5%
add-sqr-sqrt42.0%
sqrt-unprod62.7%
frac-times62.7%
metadata-eval62.7%
metadata-eval62.7%
frac-times62.7%
sqrt-unprod29.7%
add-sqr-sqrt51.2%
div-inv51.2%
metadata-eval51.2%
Applied egg-rr51.2%
associate-*l/51.2%
associate-/l*51.2%
+-commutative51.2%
*-commutative51.2%
+-commutative51.2%
Simplified51.2%
Taylor expanded in b around inf 99.6%
associate-/r*99.6%
*-un-lft-identity99.6%
*-un-lft-identity99.6%
associate-/r*99.6%
*-commutative99.6%
associate-/r*99.6%
Applied egg-rr99.6%
*-lft-identity99.6%
associate-/l*99.5%
associate-/r*99.5%
Simplified99.5%
Taylor expanded in a around inf 84.4%
if -1.1e-26 < a < -2.3499999999999998e-61 or -6.9999999999999997e-117 < a Initial program 78.0%
*-commutative78.0%
associate-*r*78.0%
associate-*r/78.0%
associate-*r*78.0%
*-rgt-identity78.0%
sub-neg78.0%
distribute-neg-frac78.0%
metadata-eval78.0%
Simplified78.0%
*-un-lft-identity78.0%
difference-of-squares88.0%
times-frac99.7%
add-sqr-sqrt53.6%
sqrt-unprod80.3%
frac-times80.3%
metadata-eval80.3%
metadata-eval80.3%
frac-times80.3%
sqrt-unprod33.5%
add-sqr-sqrt72.6%
div-inv72.6%
metadata-eval72.6%
Applied egg-rr72.6%
associate-*l/72.7%
associate-/l*72.7%
+-commutative72.7%
*-commutative72.7%
+-commutative72.7%
Simplified72.7%
Taylor expanded in b around inf 99.8%
associate-/r*99.8%
*-un-lft-identity99.8%
*-un-lft-identity99.8%
associate-/r*99.8%
*-commutative99.8%
associate-/r*99.8%
Applied egg-rr99.8%
*-lft-identity99.8%
associate-/l*99.7%
associate-/r*99.7%
Simplified99.7%
Taylor expanded in a around 0 73.0%
Final simplification76.8%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (if (<= a -1.5e+153) (* (/ PI (* b a)) (/ 0.5 a)) (* (/ PI b) (/ (/ 0.5 (+ b a)) a))))
assert(a < b);
double code(double a, double b) {
double tmp;
if (a <= -1.5e+153) {
tmp = (((double) M_PI) / (b * a)) * (0.5 / a);
} else {
tmp = (((double) M_PI) / b) * ((0.5 / (b + a)) / a);
}
return tmp;
}
assert a < b;
public static double code(double a, double b) {
double tmp;
if (a <= -1.5e+153) {
tmp = (Math.PI / (b * a)) * (0.5 / a);
} else {
tmp = (Math.PI / b) * ((0.5 / (b + a)) / a);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b): tmp = 0 if a <= -1.5e+153: tmp = (math.pi / (b * a)) * (0.5 / a) else: tmp = (math.pi / b) * ((0.5 / (b + a)) / a) return tmp
a, b = sort([a, b]) function code(a, b) tmp = 0.0 if (a <= -1.5e+153) tmp = Float64(Float64(pi / Float64(b * a)) * Float64(0.5 / a)); else tmp = Float64(Float64(pi / b) * Float64(Float64(0.5 / Float64(b + a)) / a)); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b)
tmp = 0.0;
if (a <= -1.5e+153)
tmp = (pi / (b * a)) * (0.5 / a);
else
tmp = (pi / b) * ((0.5 / (b + a)) / a);
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, -1.5e+153], N[(N[(Pi / N[(b * a), $MachinePrecision]), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(N[(Pi / b), $MachinePrecision] * N[(N[(0.5 / N[(b + a), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.5 \cdot 10^{+153}:\\
\;\;\;\;\frac{\pi}{b \cdot a} \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\pi}{b} \cdot \frac{\frac{0.5}{b + a}}{a}\\
\end{array}
\end{array}
if a < -1.50000000000000009e153Initial program 46.6%
*-commutative46.6%
associate-*r*46.6%
associate-*r/46.6%
associate-*r*46.6%
*-rgt-identity46.6%
sub-neg46.6%
distribute-neg-frac46.6%
metadata-eval46.6%
Simplified46.6%
*-un-lft-identity46.6%
difference-of-squares73.2%
times-frac99.8%
add-sqr-sqrt43.2%
sqrt-unprod75.6%
frac-times75.6%
metadata-eval75.6%
metadata-eval75.6%
frac-times75.6%
sqrt-unprod45.5%
add-sqr-sqrt72.8%
div-inv72.8%
metadata-eval72.8%
Applied egg-rr72.8%
associate-*l/72.8%
associate-/l*72.8%
+-commutative72.8%
*-commutative72.8%
+-commutative72.8%
Simplified72.8%
Taylor expanded in b around inf 99.9%
associate-/r*99.8%
*-un-lft-identity99.8%
*-un-lft-identity99.8%
associate-/r*99.9%
*-commutative99.9%
associate-/r*99.8%
Applied egg-rr99.8%
*-lft-identity99.8%
associate-/l*99.8%
associate-/r*99.8%
Simplified99.8%
Taylor expanded in a around inf 99.8%
if -1.50000000000000009e153 < a Initial program 82.8%
*-commutative82.8%
associate-*r*82.8%
associate-*r/82.8%
associate-*r*82.8%
*-rgt-identity82.8%
sub-neg82.8%
distribute-neg-frac82.8%
metadata-eval82.8%
Simplified82.8%
*-un-lft-identity82.8%
difference-of-squares90.4%
times-frac99.6%
add-sqr-sqrt50.6%
sqrt-unprod74.3%
frac-times74.3%
metadata-eval74.3%
metadata-eval74.3%
frac-times74.3%
sqrt-unprod30.4%
add-sqr-sqrt64.6%
div-inv64.6%
metadata-eval64.6%
Applied egg-rr64.6%
associate-*l/64.6%
associate-/l*64.6%
+-commutative64.6%
*-commutative64.6%
+-commutative64.6%
Simplified64.6%
Taylor expanded in b around inf 99.7%
associate-/r*99.7%
*-un-lft-identity99.7%
*-un-lft-identity99.7%
associate-/r*99.7%
*-commutative99.7%
associate-/r*99.7%
Applied egg-rr99.7%
*-lft-identity99.7%
*-commutative99.7%
associate-/r*99.7%
Simplified99.7%
*-commutative99.7%
associate-*r/99.6%
associate-*l/99.5%
*-commutative99.5%
times-frac96.3%
Applied egg-rr96.3%
Final simplification96.7%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (* (/ PI (* b a)) (/ 0.5 (+ b a))))
assert(a < b);
double code(double a, double b) {
return (((double) M_PI) / (b * a)) * (0.5 / (b + a));
}
assert a < b;
public static double code(double a, double b) {
return (Math.PI / (b * a)) * (0.5 / (b + a));
}
[a, b] = sort([a, b]) def code(a, b): return (math.pi / (b * a)) * (0.5 / (b + a))
a, b = sort([a, b]) function code(a, b) return Float64(Float64(pi / Float64(b * a)) * Float64(0.5 / Float64(b + a))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = (pi / (b * a)) * (0.5 / (b + a));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(Pi / N[(b * a), $MachinePrecision]), $MachinePrecision] * N[(0.5 / N[(b + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\pi}{b \cdot a} \cdot \frac{0.5}{b + a}
\end{array}
Initial program 78.5%
*-commutative78.5%
associate-*r*78.6%
associate-*r/78.6%
associate-*r*78.6%
*-rgt-identity78.6%
sub-neg78.6%
distribute-neg-frac78.6%
metadata-eval78.6%
Simplified78.6%
*-un-lft-identity78.6%
difference-of-squares88.4%
times-frac99.6%
add-sqr-sqrt49.8%
sqrt-unprod74.4%
frac-times74.4%
metadata-eval74.4%
metadata-eval74.4%
frac-times74.4%
sqrt-unprod32.2%
add-sqr-sqrt65.5%
div-inv65.5%
metadata-eval65.5%
Applied egg-rr65.5%
associate-*l/65.5%
associate-/l*65.5%
+-commutative65.5%
*-commutative65.5%
+-commutative65.5%
Simplified65.5%
Taylor expanded in b around inf 99.7%
associate-/r*99.7%
*-un-lft-identity99.7%
*-un-lft-identity99.7%
associate-/r*99.7%
*-commutative99.7%
associate-/r*99.7%
Applied egg-rr99.7%
*-lft-identity99.7%
associate-/l*99.6%
associate-/r*99.6%
Simplified99.6%
Final simplification99.6%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (/ (* 0.5 (/ PI (* b a))) (+ b a)))
assert(a < b);
double code(double a, double b) {
return (0.5 * (((double) M_PI) / (b * a))) / (b + a);
}
assert a < b;
public static double code(double a, double b) {
return (0.5 * (Math.PI / (b * a))) / (b + a);
}
[a, b] = sort([a, b]) def code(a, b): return (0.5 * (math.pi / (b * a))) / (b + a)
a, b = sort([a, b]) function code(a, b) return Float64(Float64(0.5 * Float64(pi / Float64(b * a))) / Float64(b + a)) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = (0.5 * (pi / (b * a))) / (b + a);
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[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(b + a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{0.5 \cdot \frac{\pi}{b \cdot a}}{b + a}
\end{array}
Initial program 78.5%
*-commutative78.5%
associate-*r*78.6%
associate-*r/78.6%
associate-*r*78.6%
*-rgt-identity78.6%
sub-neg78.6%
distribute-neg-frac78.6%
metadata-eval78.6%
Simplified78.6%
*-un-lft-identity78.6%
difference-of-squares88.4%
times-frac99.6%
add-sqr-sqrt49.8%
sqrt-unprod74.4%
frac-times74.4%
metadata-eval74.4%
metadata-eval74.4%
frac-times74.4%
sqrt-unprod32.2%
add-sqr-sqrt65.5%
div-inv65.5%
metadata-eval65.5%
Applied egg-rr65.5%
associate-*l/65.5%
associate-/l*65.5%
+-commutative65.5%
*-commutative65.5%
+-commutative65.5%
Simplified65.5%
Taylor expanded in b around inf 99.7%
associate-/r*99.7%
*-un-lft-identity99.7%
*-un-lft-identity99.7%
associate-/r*99.7%
*-commutative99.7%
associate-/r*99.7%
Applied egg-rr99.7%
*-lft-identity99.7%
*-commutative99.7%
associate-/r*99.7%
Simplified99.7%
Final simplification99.7%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (* (/ PI (* b a)) (/ 0.5 a)))
assert(a < b);
double code(double a, double b) {
return (((double) M_PI) / (b * a)) * (0.5 / a);
}
assert a < b;
public static double code(double a, double b) {
return (Math.PI / (b * a)) * (0.5 / a);
}
[a, b] = sort([a, b]) def code(a, b): return (math.pi / (b * a)) * (0.5 / a)
a, b = sort([a, b]) function code(a, b) return Float64(Float64(pi / Float64(b * a)) * Float64(0.5 / a)) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = (pi / (b * a)) * (0.5 / a);
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(Pi / N[(b * a), $MachinePrecision]), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\pi}{b \cdot a} \cdot \frac{0.5}{a}
\end{array}
Initial program 78.5%
*-commutative78.5%
associate-*r*78.6%
associate-*r/78.6%
associate-*r*78.6%
*-rgt-identity78.6%
sub-neg78.6%
distribute-neg-frac78.6%
metadata-eval78.6%
Simplified78.6%
*-un-lft-identity78.6%
difference-of-squares88.4%
times-frac99.6%
add-sqr-sqrt49.8%
sqrt-unprod74.4%
frac-times74.4%
metadata-eval74.4%
metadata-eval74.4%
frac-times74.4%
sqrt-unprod32.2%
add-sqr-sqrt65.5%
div-inv65.5%
metadata-eval65.5%
Applied egg-rr65.5%
associate-*l/65.5%
associate-/l*65.5%
+-commutative65.5%
*-commutative65.5%
+-commutative65.5%
Simplified65.5%
Taylor expanded in b around inf 99.7%
associate-/r*99.7%
*-un-lft-identity99.7%
*-un-lft-identity99.7%
associate-/r*99.7%
*-commutative99.7%
associate-/r*99.7%
Applied egg-rr99.7%
*-lft-identity99.7%
associate-/l*99.6%
associate-/r*99.6%
Simplified99.6%
Taylor expanded in a around inf 61.7%
Final simplification61.7%
herbie shell --seed 2024072
(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))))