
(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 4 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 (- (- a) b)) (* a (/ b PI))))
assert(a < b);
double code(double a, double b) {
return (-0.5 / (-a - b)) / (a * (b / ((double) M_PI)));
}
assert a < b;
public static double code(double a, double b) {
return (-0.5 / (-a - b)) / (a * (b / Math.PI));
}
[a, b] = sort([a, b]) def code(a, b): return (-0.5 / (-a - b)) / (a * (b / math.pi))
a, b = sort([a, b]) function code(a, b) return Float64(Float64(-0.5 / Float64(Float64(-a) - b)) / Float64(a * Float64(b / pi))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = (-0.5 / (-a - b)) / (a * (b / pi));
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[(a * N[(b / Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{\frac{-0.5}{\left(-a\right) - b}}{a \cdot \frac{b}{\pi}}
\end{array}
Initial program 74.7%
*-commutative74.7%
associate-*r*74.6%
associate-*r/74.6%
associate-*r*74.6%
*-rgt-identity74.6%
sub-neg74.6%
distribute-neg-frac74.6%
metadata-eval74.6%
Simplified74.6%
Taylor expanded in a around 0 53.8%
associate-*r/53.8%
*-commutative53.8%
metadata-eval53.8%
div-inv53.8%
*-un-lft-identity53.8%
associate-*l/53.7%
*-un-lft-identity53.7%
difference-of-squares58.0%
times-frac65.5%
associate-*l/65.5%
*-un-lft-identity65.5%
div-inv65.5%
metadata-eval65.5%
*-commutative65.5%
associate-*r/65.5%
Applied egg-rr65.5%
associate-*l/65.5%
*-lft-identity65.5%
associate-/l*65.5%
associate-*l/65.5%
+-commutative65.5%
associate-/l/65.5%
Simplified65.5%
Taylor expanded in b around inf 99.5%
frac-2neg99.5%
+-commutative99.5%
clear-num99.5%
frac-times98.9%
metadata-eval98.9%
metadata-eval98.9%
Applied egg-rr98.9%
associate-/r*99.6%
distribute-neg-in99.6%
mul-1-neg99.6%
unsub-neg99.6%
mul-1-neg99.6%
*-commutative99.6%
associate-/l*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 (let* ((t_0 (/ PI (* b a)))) (if (<= b 1.96e-44) (* (/ 0.5 a) t_0) (* 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 (b <= 1.96e-44) {
tmp = (0.5 / a) * t_0;
} 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 (b <= 1.96e-44) {
tmp = (0.5 / a) * t_0;
} 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 b <= 1.96e-44: tmp = (0.5 / a) * t_0 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 (b <= 1.96e-44) tmp = Float64(Float64(0.5 / a) * t_0); 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 (b <= 1.96e-44)
tmp = (0.5 / a) * t_0;
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[LessEqual[b, 1.96e-44], N[(N[(0.5 / a), $MachinePrecision] * t$95$0), $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}\;b \leq 1.96 \cdot 10^{-44}:\\
\;\;\;\;\frac{0.5}{a} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \frac{0.5}{b}\\
\end{array}
\end{array}
if b < 1.9599999999999999e-44Initial program 73.8%
*-commutative73.8%
associate-*r*73.8%
associate-*r/73.8%
associate-*r*73.8%
*-rgt-identity73.8%
sub-neg73.8%
distribute-neg-frac73.8%
metadata-eval73.8%
Simplified73.8%
Taylor expanded in a around 0 47.4%
associate-*r/47.4%
*-commutative47.4%
metadata-eval47.4%
div-inv47.4%
*-un-lft-identity47.4%
associate-*l/47.4%
*-un-lft-identity47.4%
difference-of-squares49.0%
times-frac55.1%
associate-*l/55.1%
*-un-lft-identity55.1%
div-inv55.1%
metadata-eval55.1%
*-commutative55.1%
associate-*r/55.1%
Applied egg-rr55.1%
associate-*l/55.2%
*-lft-identity55.2%
associate-/l*55.2%
associate-*l/55.1%
+-commutative55.1%
associate-/l/55.1%
Simplified55.1%
Taylor expanded in b around inf 99.5%
Taylor expanded in a around inf 72.7%
if 1.9599999999999999e-44 < b Initial program 76.7%
*-commutative76.7%
associate-*r*76.7%
associate-*r/76.8%
associate-*r*76.8%
*-rgt-identity76.8%
sub-neg76.8%
distribute-neg-frac76.8%
metadata-eval76.8%
Simplified76.8%
Taylor expanded in a around 0 69.5%
associate-*r/69.5%
*-commutative69.5%
metadata-eval69.5%
div-inv69.5%
*-un-lft-identity69.5%
associate-*l/69.4%
*-un-lft-identity69.4%
difference-of-squares80.2%
times-frac91.0%
associate-*l/90.9%
*-un-lft-identity90.9%
div-inv90.9%
metadata-eval90.9%
*-commutative90.9%
associate-*r/90.9%
Applied egg-rr90.9%
associate-*l/91.1%
*-lft-identity91.1%
associate-/l*91.1%
associate-*l/90.9%
+-commutative90.9%
associate-/l/91.0%
Simplified91.0%
Taylor expanded in b around inf 99.6%
Taylor expanded in a around 0 81.8%
Final simplification75.3%
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(0.5 * Float64(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[(0.5 * N[(N[(N[(Pi / b), $MachinePrecision] / a), $MachinePrecision] / N[(b + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
0.5 \cdot \frac{\frac{\frac{\pi}{b}}{a}}{b + a}
\end{array}
Initial program 74.7%
*-commutative74.7%
associate-*r*74.6%
associate-*r/74.6%
associate-*r*74.6%
*-rgt-identity74.6%
sub-neg74.6%
distribute-neg-frac74.6%
metadata-eval74.6%
Simplified74.6%
Taylor expanded in a around 0 53.8%
associate-*r/53.8%
*-commutative53.8%
metadata-eval53.8%
div-inv53.8%
*-un-lft-identity53.8%
associate-*l/53.7%
*-un-lft-identity53.7%
difference-of-squares58.0%
times-frac65.5%
associate-*l/65.5%
*-un-lft-identity65.5%
div-inv65.5%
metadata-eval65.5%
*-commutative65.5%
associate-*r/65.5%
Applied egg-rr65.5%
associate-*l/65.5%
*-lft-identity65.5%
associate-/l*65.5%
associate-*l/65.5%
+-commutative65.5%
associate-/l/65.5%
Simplified65.5%
Taylor expanded in b around inf 99.5%
frac-times99.0%
*-commutative99.0%
+-commutative99.0%
Applied egg-rr99.0%
*-commutative99.0%
times-frac99.5%
*-commutative99.5%
associate-*l/99.6%
associate-/l*99.6%
associate-/r*99.3%
+-commutative99.3%
Simplified99.3%
Final simplification99.3%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (* (/ 0.5 a) (/ PI (* b a))))
assert(a < b);
double code(double a, double b) {
return (0.5 / a) * (((double) M_PI) / (b * a));
}
assert a < b;
public static double code(double a, double b) {
return (0.5 / a) * (Math.PI / (b * a));
}
[a, b] = sort([a, b]) def code(a, b): return (0.5 / a) * (math.pi / (b * a))
a, b = sort([a, b]) function code(a, b) return Float64(Float64(0.5 / a) * Float64(pi / Float64(b * a))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = (0.5 / a) * (pi / (b * a));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(0.5 / a), $MachinePrecision] * N[(Pi / N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{0.5}{a} \cdot \frac{\pi}{b \cdot a}
\end{array}
Initial program 74.7%
*-commutative74.7%
associate-*r*74.6%
associate-*r/74.6%
associate-*r*74.6%
*-rgt-identity74.6%
sub-neg74.6%
distribute-neg-frac74.6%
metadata-eval74.6%
Simplified74.6%
Taylor expanded in a around 0 53.8%
associate-*r/53.8%
*-commutative53.8%
metadata-eval53.8%
div-inv53.8%
*-un-lft-identity53.8%
associate-*l/53.7%
*-un-lft-identity53.7%
difference-of-squares58.0%
times-frac65.5%
associate-*l/65.5%
*-un-lft-identity65.5%
div-inv65.5%
metadata-eval65.5%
*-commutative65.5%
associate-*r/65.5%
Applied egg-rr65.5%
associate-*l/65.5%
*-lft-identity65.5%
associate-/l*65.5%
associate-*l/65.5%
+-commutative65.5%
associate-/l/65.5%
Simplified65.5%
Taylor expanded in b around inf 99.5%
Taylor expanded in a around inf 64.8%
herbie shell --seed 2024180
(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))))