| Alternative 1 | |
|---|---|
| Accuracy | 98.4% |
| Cost | 15172 |

(FPCore (x y z t a b) :precision binary64 (+ (- (- x (* (- y 1.0) z)) (* (- t 1.0) a)) (* (- (+ y t) 2.0) b)))
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (* b (- (+ t y) 2.0))) (t_2 (+ x (* z (- 1.0 y)))))
(if (<= (+ (+ t_2 (* a (- 1.0 t))) t_1) INFINITY)
(+ t_1 (- t_2 (fma a t (- a))))
(fma a (- 1.0 t) (fma (- b z) y (- z (* b (- 2.0 t))))))))double code(double x, double y, double z, double t, double a, double b) {
return ((x - ((y - 1.0) * z)) - ((t - 1.0) * a)) + (((y + t) - 2.0) * b);
}
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = b * ((t + y) - 2.0);
double t_2 = x + (z * (1.0 - y));
double tmp;
if (((t_2 + (a * (1.0 - t))) + t_1) <= ((double) INFINITY)) {
tmp = t_1 + (t_2 - fma(a, t, -a));
} else {
tmp = fma(a, (1.0 - t), fma((b - z), y, (z - (b * (2.0 - t)))));
}
return tmp;
}
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x - Float64(Float64(y - 1.0) * z)) - Float64(Float64(t - 1.0) * a)) + Float64(Float64(Float64(y + t) - 2.0) * b)) end
function code(x, y, z, t, a, b) t_1 = Float64(b * Float64(Float64(t + y) - 2.0)) t_2 = Float64(x + Float64(z * Float64(1.0 - y))) tmp = 0.0 if (Float64(Float64(t_2 + Float64(a * Float64(1.0 - t))) + t_1) <= Inf) tmp = Float64(t_1 + Float64(t_2 - fma(a, t, Float64(-a)))); else tmp = fma(a, Float64(1.0 - t), fma(Float64(b - z), y, Float64(z - Float64(b * Float64(2.0 - t))))); end return tmp end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x - N[(N[(y - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision] - N[(N[(t - 1.0), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(y + t), $MachinePrecision] - 2.0), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(b * N[(N[(t + y), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x + N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(t$95$2 + N[(a * N[(1.0 - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision], Infinity], N[(t$95$1 + N[(t$95$2 - N[(a * t + (-a)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a * N[(1.0 - t), $MachinePrecision] + N[(N[(b - z), $MachinePrecision] * y + N[(z - N[(b * N[(2.0 - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\left(\left(x - \left(y - 1\right) \cdot z\right) - \left(t - 1\right) \cdot a\right) + \left(\left(y + t\right) - 2\right) \cdot b
\begin{array}{l}
t_1 := b \cdot \left(\left(t + y\right) - 2\right)\\
t_2 := x + z \cdot \left(1 - y\right)\\
\mathbf{if}\;\left(t_2 + a \cdot \left(1 - t\right)\right) + t_1 \leq \infty:\\
\;\;\;\;t_1 + \left(t_2 - \mathsf{fma}\left(a, t, -a\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, 1 - t, \mathsf{fma}\left(b - z, y, z - b \cdot \left(2 - t\right)\right)\right)\\
\end{array}
Herbie found 29 alternatives:
| Alternative | Accuracy | Speedup |
|---|
if (+.f64 (-.f64 (-.f64 x (*.f64 (-.f64 y 1) z)) (*.f64 (-.f64 t 1) a)) (*.f64 (-.f64 (+.f64 y t) 2) b)) < +inf.0Initial program 100.0%
Taylor expanded in t around 0 100.0%
Simplified100.0%
[Start]100.0% | \[ \left(\left(x - \left(y - 1\right) \cdot z\right) - \left(a \cdot t + -1 \cdot a\right)\right) + \left(\left(y + t\right) - 2\right) \cdot b
\] |
|---|---|
fma-def [=>]100.0% | \[ \left(\left(x - \left(y - 1\right) \cdot z\right) - \color{blue}{\mathsf{fma}\left(a, t, -1 \cdot a\right)}\right) + \left(\left(y + t\right) - 2\right) \cdot b
\] |
neg-mul-1 [<=]100.0% | \[ \left(\left(x - \left(y - 1\right) \cdot z\right) - \mathsf{fma}\left(a, t, \color{blue}{-a}\right)\right) + \left(\left(y + t\right) - 2\right) \cdot b
\] |
if +inf.0 < (+.f64 (-.f64 (-.f64 x (*.f64 (-.f64 y 1) z)) (*.f64 (-.f64 t 1) a)) (*.f64 (-.f64 (+.f64 y t) 2) b)) Initial program 0.0%
Simplified66.7%
[Start]0.0% | \[ \left(\left(x - \left(y - 1\right) \cdot z\right) - \left(t - 1\right) \cdot a\right) + \left(\left(y + t\right) - 2\right) \cdot b
\] |
|---|---|
sub-neg [=>]0.0% | \[ \color{blue}{\left(\left(x - \left(y - 1\right) \cdot z\right) + \left(-\left(t - 1\right) \cdot a\right)\right)} + \left(\left(y + t\right) - 2\right) \cdot b
\] |
+-commutative [=>]0.0% | \[ \color{blue}{\left(\left(-\left(t - 1\right) \cdot a\right) + \left(x - \left(y - 1\right) \cdot z\right)\right)} + \left(\left(y + t\right) - 2\right) \cdot b
\] |
associate-+l+ [=>]0.0% | \[ \color{blue}{\left(-\left(t - 1\right) \cdot a\right) + \left(\left(x - \left(y - 1\right) \cdot z\right) + \left(\left(y + t\right) - 2\right) \cdot b\right)}
\] |
*-commutative [=>]0.0% | \[ \left(-\color{blue}{a \cdot \left(t - 1\right)}\right) + \left(\left(x - \left(y - 1\right) \cdot z\right) + \left(\left(y + t\right) - 2\right) \cdot b\right)
\] |
distribute-rgt-neg-in [=>]0.0% | \[ \color{blue}{a \cdot \left(-\left(t - 1\right)\right)} + \left(\left(x - \left(y - 1\right) \cdot z\right) + \left(\left(y + t\right) - 2\right) \cdot b\right)
\] |
+-commutative [<=]0.0% | \[ a \cdot \left(-\left(t - 1\right)\right) + \color{blue}{\left(\left(\left(y + t\right) - 2\right) \cdot b + \left(x - \left(y - 1\right) \cdot z\right)\right)}
\] |
fma-def [=>]33.3% | \[ \color{blue}{\mathsf{fma}\left(a, -\left(t - 1\right), \left(\left(y + t\right) - 2\right) \cdot b + \left(x - \left(y - 1\right) \cdot z\right)\right)}
\] |
neg-sub0 [=>]33.3% | \[ \mathsf{fma}\left(a, \color{blue}{0 - \left(t - 1\right)}, \left(\left(y + t\right) - 2\right) \cdot b + \left(x - \left(y - 1\right) \cdot z\right)\right)
\] |
associate--r- [=>]33.3% | \[ \mathsf{fma}\left(a, \color{blue}{\left(0 - t\right) + 1}, \left(\left(y + t\right) - 2\right) \cdot b + \left(x - \left(y - 1\right) \cdot z\right)\right)
\] |
neg-sub0 [<=]33.3% | \[ \mathsf{fma}\left(a, \color{blue}{\left(-t\right)} + 1, \left(\left(y + t\right) - 2\right) \cdot b + \left(x - \left(y - 1\right) \cdot z\right)\right)
\] |
+-commutative [=>]33.3% | \[ \mathsf{fma}\left(a, \color{blue}{1 + \left(-t\right)}, \left(\left(y + t\right) - 2\right) \cdot b + \left(x - \left(y - 1\right) \cdot z\right)\right)
\] |
sub-neg [<=]33.3% | \[ \mathsf{fma}\left(a, \color{blue}{1 - t}, \left(\left(y + t\right) - 2\right) \cdot b + \left(x - \left(y - 1\right) \cdot z\right)\right)
\] |
fma-def [=>]66.7% | \[ \mathsf{fma}\left(a, 1 - t, \color{blue}{\mathsf{fma}\left(\left(y + t\right) - 2, b, x - \left(y - 1\right) \cdot z\right)}\right)
\] |
sub-neg [=>]66.7% | \[ \mathsf{fma}\left(a, 1 - t, \mathsf{fma}\left(\color{blue}{\left(y + t\right) + \left(-2\right)}, b, x - \left(y - 1\right) \cdot z\right)\right)
\] |
associate-+l+ [=>]66.7% | \[ \mathsf{fma}\left(a, 1 - t, \mathsf{fma}\left(\color{blue}{y + \left(t + \left(-2\right)\right)}, b, x - \left(y - 1\right) \cdot z\right)\right)
\] |
metadata-eval [=>]66.7% | \[ \mathsf{fma}\left(a, 1 - t, \mathsf{fma}\left(y + \left(t + \color{blue}{-2}\right), b, x - \left(y - 1\right) \cdot z\right)\right)
\] |
sub-neg [=>]66.7% | \[ \mathsf{fma}\left(a, 1 - t, \mathsf{fma}\left(y + \left(t + -2\right), b, \color{blue}{x + \left(-\left(y - 1\right) \cdot z\right)}\right)\right)
\] |
+-commutative [=>]66.7% | \[ \mathsf{fma}\left(a, 1 - t, \mathsf{fma}\left(y + \left(t + -2\right), b, \color{blue}{\left(-\left(y - 1\right) \cdot z\right) + x}\right)\right)
\] |
Taylor expanded in y around 0 77.8%
Simplified77.8%
[Start]77.8% | \[ \mathsf{fma}\left(a, 1 - t, \left(-1 \cdot z + b\right) \cdot y + \left(z + \left(b \cdot \left(t - 2\right) + x\right)\right)\right)
\] |
|---|---|
fma-def [=>]77.8% | \[ \mathsf{fma}\left(a, 1 - t, \color{blue}{\mathsf{fma}\left(-1 \cdot z + b, y, z + \left(b \cdot \left(t - 2\right) + x\right)\right)}\right)
\] |
+-commutative [=>]77.8% | \[ \mathsf{fma}\left(a, 1 - t, \mathsf{fma}\left(\color{blue}{b + -1 \cdot z}, y, z + \left(b \cdot \left(t - 2\right) + x\right)\right)\right)
\] |
mul-1-neg [=>]77.8% | \[ \mathsf{fma}\left(a, 1 - t, \mathsf{fma}\left(b + \color{blue}{\left(-z\right)}, y, z + \left(b \cdot \left(t - 2\right) + x\right)\right)\right)
\] |
sub-neg [<=]77.8% | \[ \mathsf{fma}\left(a, 1 - t, \mathsf{fma}\left(\color{blue}{b - z}, y, z + \left(b \cdot \left(t - 2\right) + x\right)\right)\right)
\] |
fma-def [=>]77.8% | \[ \mathsf{fma}\left(a, 1 - t, \mathsf{fma}\left(b - z, y, z + \color{blue}{\mathsf{fma}\left(b, t - 2, x\right)}\right)\right)
\] |
sub-neg [=>]77.8% | \[ \mathsf{fma}\left(a, 1 - t, \mathsf{fma}\left(b - z, y, z + \mathsf{fma}\left(b, \color{blue}{t + \left(-2\right)}, x\right)\right)\right)
\] |
metadata-eval [=>]77.8% | \[ \mathsf{fma}\left(a, 1 - t, \mathsf{fma}\left(b - z, y, z + \mathsf{fma}\left(b, t + \color{blue}{-2}, x\right)\right)\right)
\] |
Taylor expanded in b around inf 77.8%
Final simplification99.2%
| Alternative 1 | |
|---|---|
| Accuracy | 98.4% |
| Cost | 15172 |
| Alternative 2 | |
|---|---|
| Accuracy | 97.6% |
| Cost | 20160 |
| Alternative 3 | |
|---|---|
| Accuracy | 97.9% |
| Cost | 9092 |
| Alternative 4 | |
|---|---|
| Accuracy | 97.9% |
| Cost | 2756 |
| Alternative 5 | |
|---|---|
| Accuracy | 97.9% |
| Cost | 2756 |
| Alternative 6 | |
|---|---|
| Accuracy | 82.7% |
| Cost | 1356 |
| Alternative 7 | |
|---|---|
| Accuracy | 33.8% |
| Cost | 1244 |
| Alternative 8 | |
|---|---|
| Accuracy | 37.2% |
| Cost | 1244 |
| Alternative 9 | |
|---|---|
| Accuracy | 61.7% |
| Cost | 1240 |
| Alternative 10 | |
|---|---|
| Accuracy | 55.8% |
| Cost | 1240 |
| Alternative 11 | |
|---|---|
| Accuracy | 67.5% |
| Cost | 1233 |
| Alternative 12 | |
|---|---|
| Accuracy | 86.5% |
| Cost | 1225 |
| Alternative 13 | |
|---|---|
| Accuracy | 41.6% |
| Cost | 1112 |
| Alternative 14 | |
|---|---|
| Accuracy | 46.7% |
| Cost | 1112 |
| Alternative 15 | |
|---|---|
| Accuracy | 46.0% |
| Cost | 1112 |
| Alternative 16 | |
|---|---|
| Accuracy | 45.1% |
| Cost | 1112 |
| Alternative 17 | |
|---|---|
| Accuracy | 69.1% |
| Cost | 1104 |
| Alternative 18 | |
|---|---|
| Accuracy | 82.0% |
| Cost | 1096 |
| Alternative 19 | |
|---|---|
| Accuracy | 26.6% |
| Cost | 1048 |
| Alternative 20 | |
|---|---|
| Accuracy | 25.0% |
| Cost | 1048 |
| Alternative 21 | |
|---|---|
| Accuracy | 48.9% |
| Cost | 980 |
| Alternative 22 | |
|---|---|
| Accuracy | 68.3% |
| Cost | 968 |
| Alternative 23 | |
|---|---|
| Accuracy | 23.2% |
| Cost | 852 |
| Alternative 24 | |
|---|---|
| Accuracy | 69.2% |
| Cost | 841 |
| Alternative 25 | |
|---|---|
| Accuracy | 45.4% |
| Cost | 716 |
| Alternative 26 | |
|---|---|
| Accuracy | 23.5% |
| Cost | 588 |
| Alternative 27 | |
|---|---|
| Accuracy | 19.2% |
| Cost | 460 |
| Alternative 28 | |
|---|---|
| Accuracy | 21.2% |
| Cost | 328 |
| Alternative 29 | |
|---|---|
| Accuracy | 11.5% |
| Cost | 64 |
herbie shell --seed 2023272
(FPCore (x y z t a b)
:name "Statistics.Distribution.Beta:$centropy from math-functions-0.1.5.2"
:precision binary64
(+ (- (- x (* (- y 1.0) z)) (* (- t 1.0) a)) (* (- (+ y t) 2.0) b)))