
(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 (* (/ b PI) a)) (+ b a)))
assert(a < b);
double code(double a, double b) {
return (0.5 / ((b / ((double) M_PI)) * a)) / (b + a);
}
assert a < b;
public static double code(double a, double b) {
return (0.5 / ((b / Math.PI) * a)) / (b + a);
}
[a, b] = sort([a, b]) def code(a, b): return (0.5 / ((b / math.pi) * a)) / (b + a)
a, b = sort([a, b]) function code(a, b) return Float64(Float64(0.5 / Float64(Float64(b / pi) * a)) / Float64(b + a)) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = (0.5 / ((b / pi) * 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[(b / Pi), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / N[(b + a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\frac{0.5}{\frac{b}{\pi} \cdot a}}{b + a}
\end{array}
Initial program 77.1%
*-commutative77.1%
associate-*r*77.1%
associate-*r/77.1%
associate-*r*77.1%
*-rgt-identity77.1%
sub-neg77.1%
distribute-neg-frac77.1%
metadata-eval77.1%
Simplified77.1%
*-un-lft-identity77.1%
difference-of-squares86.5%
times-frac99.5%
add-sqr-sqrt50.1%
sqrt-unprod71.3%
frac-times71.3%
metadata-eval71.3%
metadata-eval71.3%
frac-times71.3%
sqrt-unprod30.7%
add-sqr-sqrt64.4%
div-inv64.4%
metadata-eval64.4%
Applied egg-rr64.4%
Taylor expanded in a around 0 99.7%
associate-*l/99.7%
*-un-lft-identity99.7%
*-commutative99.7%
associate-/r*99.7%
+-commutative99.7%
Applied egg-rr99.7%
*-commutative99.7%
associate-/r*99.7%
associate-*r/99.7%
*-commutative99.7%
*-commutative99.7%
times-frac99.6%
Simplified99.6%
clear-num99.6%
frac-times99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Final simplification99.7%
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 a)))))
assert(a < b);
double code(double a, double b) {
return ((double) M_PI) * (0.5 / ((b * a) * (b + a)));
}
assert a < b;
public static double code(double a, double b) {
return Math.PI * (0.5 / ((b * a) * (b + a)));
}
[a, b] = sort([a, b]) def code(a, b): return math.pi * (0.5 / ((b * a) * (b + a)))
a, b = sort([a, b]) function code(a, b) return Float64(pi * Float64(0.5 / Float64(Float64(b * a) * Float64(b + a)))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = pi * (0.5 / ((b * a) * (b + a)));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(Pi * N[(0.5 / N[(N[(b * a), $MachinePrecision] * N[(b + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\pi \cdot \frac{0.5}{\left(b \cdot a\right) \cdot \left(b + a\right)}
\end{array}
Initial program 77.1%
*-commutative77.1%
associate-*r*77.1%
associate-*r/77.1%
associate-*r*77.1%
*-rgt-identity77.1%
sub-neg77.1%
distribute-neg-frac77.1%
metadata-eval77.1%
Simplified77.1%
*-un-lft-identity77.1%
difference-of-squares86.5%
times-frac99.5%
add-sqr-sqrt50.1%
sqrt-unprod71.3%
frac-times71.3%
metadata-eval71.3%
metadata-eval71.3%
frac-times71.3%
sqrt-unprod30.7%
add-sqr-sqrt64.4%
div-inv64.4%
metadata-eval64.4%
Applied egg-rr64.4%
Taylor expanded in a around 0 99.7%
associate-*r/99.7%
*-commutative99.7%
frac-times99.4%
*-un-lft-identity99.4%
+-commutative99.4%
Applied egg-rr99.4%
associate-/l*99.4%
+-commutative99.4%
*-commutative99.4%
Applied egg-rr99.4%
Final simplification99.4%
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 77.1%
*-commutative77.1%
associate-*r*77.1%
associate-*r/77.1%
associate-*r*77.1%
*-rgt-identity77.1%
sub-neg77.1%
distribute-neg-frac77.1%
metadata-eval77.1%
Simplified77.1%
*-un-lft-identity77.1%
difference-of-squares86.5%
times-frac99.5%
add-sqr-sqrt50.1%
sqrt-unprod71.3%
frac-times71.3%
metadata-eval71.3%
metadata-eval71.3%
frac-times71.3%
sqrt-unprod30.7%
add-sqr-sqrt64.4%
div-inv64.4%
metadata-eval64.4%
Applied egg-rr64.4%
Taylor expanded in a around 0 99.7%
associate-*r/99.7%
*-commutative99.7%
frac-times99.4%
*-un-lft-identity99.4%
+-commutative99.4%
Applied egg-rr99.4%
*-commutative99.4%
times-frac99.7%
*-commutative99.7%
+-commutative99.7%
Applied egg-rr99.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 PI) (* b (* b a))))
assert(a < b);
double code(double a, double b) {
return (0.5 * ((double) M_PI)) / (b * (b * a));
}
assert a < b;
public static double code(double a, double b) {
return (0.5 * Math.PI) / (b * (b * a));
}
[a, b] = sort([a, b]) def code(a, b): return (0.5 * math.pi) / (b * (b * a))
a, b = sort([a, b]) function code(a, b) return Float64(Float64(0.5 * pi) / Float64(b * Float64(b * a))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = (0.5 * pi) / (b * (b * a));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(0.5 * Pi), $MachinePrecision] / N[(b * N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{0.5 \cdot \pi}{b \cdot \left(b \cdot a\right)}
\end{array}
Initial program 77.1%
*-commutative77.1%
associate-*r*77.1%
associate-*r/77.1%
associate-*r*77.1%
*-rgt-identity77.1%
sub-neg77.1%
distribute-neg-frac77.1%
metadata-eval77.1%
Simplified77.1%
*-un-lft-identity77.1%
difference-of-squares86.5%
times-frac99.5%
add-sqr-sqrt50.1%
sqrt-unprod71.3%
frac-times71.3%
metadata-eval71.3%
metadata-eval71.3%
frac-times71.3%
sqrt-unprod30.7%
add-sqr-sqrt64.4%
div-inv64.4%
metadata-eval64.4%
Applied egg-rr64.4%
Taylor expanded in a around 0 99.7%
Taylor expanded in b around inf 63.4%
associate-*r/63.4%
*-commutative63.4%
frac-times63.4%
*-un-lft-identity63.4%
*-commutative63.4%
Applied egg-rr63.4%
Final simplification63.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (/ (* (/ PI b) (/ 0.5 a)) b))
assert(a < b);
double code(double a, double b) {
return ((((double) M_PI) / b) * (0.5 / a)) / b;
}
assert a < b;
public static double code(double a, double b) {
return ((Math.PI / b) * (0.5 / a)) / b;
}
[a, b] = sort([a, b]) def code(a, b): return ((math.pi / b) * (0.5 / a)) / b
a, b = sort([a, b]) function code(a, b) return Float64(Float64(Float64(pi / b) * Float64(0.5 / a)) / b) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = ((pi / 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[(N[(Pi / b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\frac{\pi}{b} \cdot \frac{0.5}{a}}{b}
\end{array}
Initial program 77.1%
*-commutative77.1%
associate-*r*77.1%
associate-*r/77.1%
associate-*r*77.1%
*-rgt-identity77.1%
sub-neg77.1%
distribute-neg-frac77.1%
metadata-eval77.1%
Simplified77.1%
*-un-lft-identity77.1%
difference-of-squares86.5%
times-frac99.5%
add-sqr-sqrt50.1%
sqrt-unprod71.3%
frac-times71.3%
metadata-eval71.3%
metadata-eval71.3%
frac-times71.3%
sqrt-unprod30.7%
add-sqr-sqrt64.4%
div-inv64.4%
metadata-eval64.4%
Applied egg-rr64.4%
Taylor expanded in a around 0 99.7%
Taylor expanded in b around inf 63.4%
associate-*l/63.4%
*-un-lft-identity63.4%
associate-*r/63.4%
frac-times63.4%
*-commutative63.4%
Applied egg-rr63.4%
Final simplification63.4%
herbie shell --seed 2024053
(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))))