
(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 (/ (/ (/ 1.0 a) b) (/ (+ a b) (* 0.5 PI))))
assert(a < b);
double code(double a, double b) {
return ((1.0 / a) / b) / ((a + b) / (0.5 * ((double) M_PI)));
}
assert a < b;
public static double code(double a, double b) {
return ((1.0 / a) / b) / ((a + b) / (0.5 * Math.PI));
}
[a, b] = sort([a, b]) def code(a, b): return ((1.0 / a) / b) / ((a + b) / (0.5 * math.pi))
a, b = sort([a, b]) function code(a, b) return Float64(Float64(Float64(1.0 / a) / b) / Float64(Float64(a + b) / Float64(0.5 * pi))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = ((1.0 / a) / b) / ((a + b) / (0.5 * pi));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(N[(1.0 / a), $MachinePrecision] / b), $MachinePrecision] / N[(N[(a + b), $MachinePrecision] / N[(0.5 * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\frac{\frac{1}{a}}{b}}{\frac{a + b}{0.5 \cdot \pi}}
\end{array}
Initial program 76.5%
un-div-inv76.6%
difference-of-squares86.0%
associate-/r*86.3%
div-inv86.3%
metadata-eval86.3%
Applied egg-rr86.3%
frac-sub86.3%
frac-times98.9%
*-un-lft-identity98.9%
*-commutative98.9%
Applied egg-rr98.9%
*-rgt-identity98.9%
associate-/l*98.8%
associate-*r/98.8%
+-commutative98.8%
*-commutative98.8%
Simplified98.8%
associate-*r/98.8%
+-commutative98.8%
associate-/r*99.6%
pow199.6%
pow199.6%
pow-div99.6%
metadata-eval99.6%
metadata-eval99.6%
clear-num99.6%
frac-times98.9%
metadata-eval98.9%
*-commutative98.9%
Applied egg-rr98.9%
*-commutative98.9%
associate-/r*99.6%
*-commutative99.6%
associate-/r*99.7%
+-commutative99.7%
*-commutative99.7%
Simplified99.7%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (* (/ PI (* a b)) (/ 0.5 (+ a b))))
assert(a < b);
double code(double a, double b) {
return (((double) M_PI) / (a * b)) * (0.5 / (a + b));
}
assert a < b;
public static double code(double a, double b) {
return (Math.PI / (a * b)) * (0.5 / (a + b));
}
[a, b] = sort([a, b]) def code(a, b): return (math.pi / (a * b)) * (0.5 / (a + b))
a, b = sort([a, b]) function code(a, b) return Float64(Float64(pi / Float64(a * b)) * Float64(0.5 / Float64(a + b))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = (pi / (a * b)) * (0.5 / (a + b));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(Pi / N[(a * b), $MachinePrecision]), $MachinePrecision] * N[(0.5 / N[(a + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\pi}{a \cdot b} \cdot \frac{0.5}{a + b}
\end{array}
Initial program 76.5%
un-div-inv76.6%
difference-of-squares86.0%
associate-/r*86.3%
div-inv86.3%
metadata-eval86.3%
Applied egg-rr86.3%
frac-sub86.3%
frac-times98.9%
*-un-lft-identity98.9%
*-commutative98.9%
Applied egg-rr98.9%
*-rgt-identity98.9%
associate-/l*98.8%
associate-*r/98.8%
+-commutative98.8%
*-commutative98.8%
Simplified98.8%
*-commutative98.8%
associate-/r*99.6%
pow199.6%
pow199.6%
pow-div99.6%
metadata-eval99.6%
metadata-eval99.6%
associate-*r/99.6%
+-commutative99.6%
frac-times98.9%
*-un-lft-identity98.9%
*-commutative98.9%
Applied egg-rr98.9%
times-frac99.6%
*-commutative99.6%
+-commutative99.6%
Applied egg-rr99.6%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (* (/ PI b) (/ 0.5 (* a (+ a b)))))
assert(a < b);
double code(double a, double b) {
return (((double) M_PI) / b) * (0.5 / (a * (a + b)));
}
assert a < b;
public static double code(double a, double b) {
return (Math.PI / b) * (0.5 / (a * (a + b)));
}
[a, b] = sort([a, b]) def code(a, b): return (math.pi / b) * (0.5 / (a * (a + b)))
a, b = sort([a, b]) function code(a, b) return Float64(Float64(pi / b) * Float64(0.5 / Float64(a * Float64(a + b)))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = (pi / b) * (0.5 / (a * (a + b)));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(Pi / b), $MachinePrecision] * N[(0.5 / N[(a * N[(a + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\pi}{b} \cdot \frac{0.5}{a \cdot \left(a + b\right)}
\end{array}
Initial program 76.5%
un-div-inv76.6%
difference-of-squares86.0%
associate-/r*86.3%
div-inv86.3%
metadata-eval86.3%
Applied egg-rr86.3%
frac-sub86.3%
frac-times98.9%
*-un-lft-identity98.9%
*-commutative98.9%
Applied egg-rr98.9%
*-rgt-identity98.9%
associate-/l*98.8%
associate-*r/98.8%
+-commutative98.8%
*-commutative98.8%
Simplified98.8%
*-commutative98.8%
associate-/r*99.6%
pow199.6%
pow199.6%
pow-div99.6%
metadata-eval99.6%
metadata-eval99.6%
associate-*r/99.6%
+-commutative99.6%
frac-times98.9%
*-un-lft-identity98.9%
*-commutative98.9%
Applied egg-rr98.9%
associate-*l*91.7%
+-commutative91.7%
times-frac92.4%
Applied egg-rr92.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (* PI (/ 0.5 (* b (* a (+ a b))))))
assert(a < b);
double code(double a, double b) {
return ((double) M_PI) * (0.5 / (b * (a * (a + b))));
}
assert a < b;
public static double code(double a, double b) {
return Math.PI * (0.5 / (b * (a * (a + b))));
}
[a, b] = sort([a, b]) def code(a, b): return math.pi * (0.5 / (b * (a * (a + b))))
a, b = sort([a, b]) function code(a, b) return Float64(pi * Float64(0.5 / Float64(b * Float64(a * Float64(a + b))))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = pi * (0.5 / (b * (a * (a + b))));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(Pi * N[(0.5 / N[(b * N[(a * N[(a + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\pi \cdot \frac{0.5}{b \cdot \left(a \cdot \left(a + b\right)\right)}
\end{array}
Initial program 76.5%
un-div-inv76.6%
difference-of-squares86.0%
associate-/r*86.3%
div-inv86.3%
metadata-eval86.3%
Applied egg-rr86.3%
frac-sub86.3%
frac-times98.9%
*-un-lft-identity98.9%
*-commutative98.9%
Applied egg-rr98.9%
*-rgt-identity98.9%
associate-/l*98.8%
associate-*r/98.8%
+-commutative98.8%
*-commutative98.8%
Simplified98.8%
*-commutative98.8%
associate-/r*99.6%
pow199.6%
pow199.6%
pow-div99.6%
metadata-eval99.6%
metadata-eval99.6%
associate-*r/99.6%
+-commutative99.6%
frac-times98.9%
*-un-lft-identity98.9%
*-commutative98.9%
Applied egg-rr98.9%
associate-/l*98.9%
associate-*l*91.6%
+-commutative91.6%
Simplified91.6%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (/ (* PI -0.5) (* b (* a (- b)))))
assert(a < b);
double code(double a, double b) {
return (((double) M_PI) * -0.5) / (b * (a * -b));
}
assert a < b;
public static double code(double a, double b) {
return (Math.PI * -0.5) / (b * (a * -b));
}
[a, b] = sort([a, b]) def code(a, b): return (math.pi * -0.5) / (b * (a * -b))
a, b = sort([a, b]) function code(a, b) return Float64(Float64(pi * -0.5) / Float64(b * Float64(a * Float64(-b)))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = (pi * -0.5) / (b * (a * -b));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(Pi * -0.5), $MachinePrecision] / N[(b * N[(a * (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\pi \cdot -0.5}{b \cdot \left(a \cdot \left(-b\right)\right)}
\end{array}
Initial program 76.5%
un-div-inv76.6%
difference-of-squares86.0%
associate-/r*86.3%
div-inv86.3%
metadata-eval86.3%
Applied egg-rr86.3%
frac-sub86.3%
frac-times98.9%
*-un-lft-identity98.9%
*-commutative98.9%
Applied egg-rr98.9%
*-rgt-identity98.9%
associate-/l*98.8%
associate-*r/98.8%
+-commutative98.8%
*-commutative98.8%
Simplified98.8%
associate-*r/98.8%
+-commutative98.8%
associate-/r*99.6%
pow199.6%
pow199.6%
pow-div99.6%
metadata-eval99.6%
metadata-eval99.6%
frac-2neg99.6%
frac-times98.9%
*-commutative98.9%
Applied egg-rr98.9%
*-rgt-identity98.9%
distribute-rgt-neg-in98.9%
metadata-eval98.9%
*-commutative98.9%
associate-*l*91.7%
+-commutative91.7%
Simplified91.7%
Taylor expanded in a around 0 60.5%
mul-1-neg60.5%
distribute-rgt-neg-in60.5%
Simplified60.5%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (* PI (/ 0.5 (* b (* a b)))))
assert(a < b);
double code(double a, double b) {
return ((double) M_PI) * (0.5 / (b * (a * b)));
}
assert a < b;
public static double code(double a, double b) {
return Math.PI * (0.5 / (b * (a * b)));
}
[a, b] = sort([a, b]) def code(a, b): return math.pi * (0.5 / (b * (a * b)))
a, b = sort([a, b]) function code(a, b) return Float64(pi * Float64(0.5 / Float64(b * Float64(a * b)))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = pi * (0.5 / (b * (a * b)));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(Pi * N[(0.5 / N[(b * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\pi \cdot \frac{0.5}{b \cdot \left(a \cdot b\right)}
\end{array}
Initial program 76.5%
un-div-inv76.6%
difference-of-squares86.0%
associate-/r*86.3%
div-inv86.3%
metadata-eval86.3%
Applied egg-rr86.3%
frac-sub86.3%
frac-times98.9%
*-un-lft-identity98.9%
*-commutative98.9%
Applied egg-rr98.9%
*-rgt-identity98.9%
associate-/l*98.8%
associate-*r/98.8%
+-commutative98.8%
*-commutative98.8%
Simplified98.8%
*-commutative98.8%
associate-/r*99.6%
pow199.6%
pow199.6%
pow-div99.6%
metadata-eval99.6%
metadata-eval99.6%
associate-*r/99.6%
+-commutative99.6%
frac-times98.9%
*-un-lft-identity98.9%
*-commutative98.9%
Applied egg-rr98.9%
associate-/l*98.9%
associate-*l*91.6%
+-commutative91.6%
Simplified91.6%
Taylor expanded in a around 0 60.4%
herbie shell --seed 2024143
(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))))