
(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 79.3%
associate-*l*79.4%
associate-*l/79.3%
*-lft-identity79.3%
difference-of-squares87.1%
associate-/l/99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
associate-*r/99.7%
div-inv99.7%
metadata-eval99.7%
+-commutative99.7%
Applied egg-rr99.7%
Taylor expanded in a around 0 99.7%
expm1-log1p-u72.8%
expm1-udef59.5%
Applied egg-rr59.5%
expm1-def72.8%
expm1-log1p99.7%
associate-/l/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 (* (/ (/ 0.5 b) (+ b a)) (/ PI a)))
assert(a < b);
double code(double a, double b) {
return ((0.5 / b) / (b + a)) * (((double) M_PI) / a);
}
assert a < b;
public static double code(double a, double b) {
return ((0.5 / b) / (b + a)) * (Math.PI / a);
}
[a, b] = sort([a, b]) def code(a, b): return ((0.5 / b) / (b + a)) * (math.pi / a)
a, b = sort([a, b]) function code(a, b) return Float64(Float64(Float64(0.5 / b) / Float64(b + a)) * Float64(pi / a)) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = ((0.5 / b) / (b + a)) * (pi / a);
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(N[(0.5 / b), $MachinePrecision] / N[(b + a), $MachinePrecision]), $MachinePrecision] * N[(Pi / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\frac{0.5}{b}}{b + a} \cdot \frac{\pi}{a}
\end{array}
Initial program 79.3%
associate-*l*79.4%
associate-*l/79.3%
*-lft-identity79.3%
difference-of-squares87.1%
associate-/l/99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
associate-*r/99.7%
div-inv99.7%
metadata-eval99.7%
+-commutative99.7%
Applied egg-rr99.7%
Taylor expanded in a around 0 99.7%
expm1-log1p-u72.8%
expm1-udef59.5%
Applied egg-rr59.5%
expm1-def72.8%
expm1-log1p99.7%
associate-/l/99.7%
Simplified99.7%
associate-/l*98.7%
associate-/l/98.7%
associate-/r*98.7%
associate-/r/99.6%
clear-num99.6%
times-frac92.4%
associate-/r/92.4%
associate-*r/92.4%
associate-/l/91.9%
associate-*r/91.9%
times-frac92.3%
clear-num92.4%
+-commutative92.4%
Applied egg-rr92.4%
Final simplification92.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (/ 0.5 (/ (+ b a) (/ PI (* b a)))))
assert(a < b);
double code(double a, double b) {
return 0.5 / ((b + a) / (((double) M_PI) / (b * a)));
}
assert a < b;
public static double code(double a, double b) {
return 0.5 / ((b + a) / (Math.PI / (b * a)));
}
[a, b] = sort([a, b]) def code(a, b): return 0.5 / ((b + a) / (math.pi / (b * a)))
a, b = sort([a, b]) function code(a, b) return Float64(0.5 / Float64(Float64(b + a) / Float64(pi / Float64(b * a)))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = 0.5 / ((b + a) / (pi / (b * a)));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(0.5 / N[(N[(b + a), $MachinePrecision] / N[(Pi / N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{0.5}{\frac{b + a}{\frac{\pi}{b \cdot a}}}
\end{array}
Initial program 79.3%
associate-*l*79.4%
associate-*l/79.3%
*-lft-identity79.3%
difference-of-squares87.1%
associate-/l/99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in a around 0 99.6%
expm1-log1p-u72.8%
expm1-udef59.4%
Applied egg-rr59.4%
expm1-def72.8%
expm1-log1p99.6%
associate-/r*99.6%
*-rgt-identity99.6%
associate-*r/99.5%
associate-*l/99.6%
*-lft-identity99.6%
Simplified99.6%
frac-times99.6%
associate-/l/99.6%
div-inv99.7%
*-un-lft-identity99.7%
+-commutative99.7%
times-frac99.7%
metadata-eval99.7%
metadata-eval99.7%
times-frac99.7%
*-un-lft-identity99.7%
associate-/l*98.7%
Applied egg-rr98.7%
Final simplification98.7%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (/ PI (* (* (+ b a) (* b a)) 2.0)))
assert(a < b);
double code(double a, double b) {
return ((double) M_PI) / (((b + a) * (b * a)) * 2.0);
}
assert a < b;
public static double code(double a, double b) {
return Math.PI / (((b + a) * (b * a)) * 2.0);
}
[a, b] = sort([a, b]) def code(a, b): return math.pi / (((b + a) * (b * a)) * 2.0)
a, b = sort([a, b]) function code(a, b) return Float64(pi / Float64(Float64(Float64(b + a) * Float64(b * a)) * 2.0)) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = pi / (((b + a) * (b * a)) * 2.0);
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(Pi / N[(N[(N[(b + a), $MachinePrecision] * N[(b * a), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\pi}{\left(\left(b + a\right) \cdot \left(b \cdot a\right)\right) \cdot 2}
\end{array}
Initial program 79.3%
associate-*l*79.4%
associate-*l/79.3%
*-lft-identity79.3%
difference-of-squares87.1%
associate-/l/99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in a around 0 99.6%
*-commutative99.6%
associate-/l/98.7%
frac-times98.8%
*-un-lft-identity98.8%
+-commutative98.8%
Applied egg-rr98.8%
Final simplification98.8%
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 79.3%
associate-*l*79.4%
associate-*l/79.3%
*-lft-identity79.3%
difference-of-squares87.1%
associate-/l/99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
associate-*r/99.7%
div-inv99.7%
metadata-eval99.7%
+-commutative99.7%
Applied egg-rr99.7%
Taylor expanded in a around 0 99.7%
Final simplification99.7%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (/ (/ PI a) (* a (* b 2.0))))
assert(a < b);
double code(double a, double b) {
return (((double) M_PI) / a) / (a * (b * 2.0));
}
assert a < b;
public static double code(double a, double b) {
return (Math.PI / a) / (a * (b * 2.0));
}
[a, b] = sort([a, b]) def code(a, b): return (math.pi / a) / (a * (b * 2.0))
a, b = sort([a, b]) function code(a, b) return Float64(Float64(pi / a) / Float64(a * Float64(b * 2.0))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = (pi / a) / (a * (b * 2.0));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(Pi / a), $MachinePrecision] / N[(a * N[(b * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\frac{\pi}{a}}{a \cdot \left(b \cdot 2\right)}
\end{array}
Initial program 79.3%
associate-*l*79.4%
associate-*l/79.3%
*-lft-identity79.3%
difference-of-squares87.1%
associate-/l/99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
associate-*r/99.7%
div-inv99.7%
metadata-eval99.7%
+-commutative99.7%
Applied egg-rr99.7%
Taylor expanded in a around 0 99.7%
*-un-lft-identity99.7%
times-frac99.7%
metadata-eval99.7%
metadata-eval99.7%
times-frac99.7%
*-un-lft-identity99.7%
div-inv99.6%
associate-/l/99.6%
+-commutative99.6%
frac-times99.6%
expm1-log1p-u78.2%
expm1-udef51.7%
Applied egg-rr51.7%
expm1-def78.2%
expm1-log1p99.7%
associate-/l*92.4%
Simplified92.4%
Taylor expanded in a around inf 63.6%
*-commutative63.6%
*-commutative63.6%
*-commutative63.6%
associate-*r*63.9%
Simplified63.9%
Final simplification63.9%
herbie shell --seed 2024031
(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))))