| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 4937 |
(FPCore (x y z t a b) :precision binary64 (/ (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)) (+ (+ x t) y)))
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (+ y (+ x t)))
(t_2 (/ (- (+ (* z (+ x y)) (* (+ y t) a)) (* y b)) t_1)))
(if (or (<= t_2 -5e-22) (not (<= t_2 5e+71)))
(+ (/ (- z b) (/ t_1 y)) (+ (/ z (/ t_1 x)) (/ a (/ t_1 (+ y t)))))
(/ (fma (+ y t) a (fma x z (* y (- z b)))) t_1))))double code(double x, double y, double z, double t, double a, double b) {
return ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y);
}
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = y + (x + t);
double t_2 = (((z * (x + y)) + ((y + t) * a)) - (y * b)) / t_1;
double tmp;
if ((t_2 <= -5e-22) || !(t_2 <= 5e+71)) {
tmp = ((z - b) / (t_1 / y)) + ((z / (t_1 / x)) + (a / (t_1 / (y + t))));
} else {
tmp = fma((y + t), a, fma(x, z, (y * (z - b)))) / t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) return Float64(Float64(Float64(Float64(Float64(x + y) * z) + Float64(Float64(t + y) * a)) - Float64(y * b)) / Float64(Float64(x + t) + y)) end
function code(x, y, z, t, a, b) t_1 = Float64(y + Float64(x + t)) t_2 = Float64(Float64(Float64(Float64(z * Float64(x + y)) + Float64(Float64(y + t) * a)) - Float64(y * b)) / t_1) tmp = 0.0 if ((t_2 <= -5e-22) || !(t_2 <= 5e+71)) tmp = Float64(Float64(Float64(z - b) / Float64(t_1 / y)) + Float64(Float64(z / Float64(t_1 / x)) + Float64(a / Float64(t_1 / Float64(y + t))))); else tmp = Float64(fma(Float64(y + t), a, fma(x, z, Float64(y * Float64(z - b)))) / t_1); end return tmp end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(N[(N[(x + y), $MachinePrecision] * z), $MachinePrecision] + N[(N[(t + y), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] - N[(y * b), $MachinePrecision]), $MachinePrecision] / N[(N[(x + t), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(y + N[(x + t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(N[(z * N[(x + y), $MachinePrecision]), $MachinePrecision] + N[(N[(y + t), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] - N[(y * b), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision]}, If[Or[LessEqual[t$95$2, -5e-22], N[Not[LessEqual[t$95$2, 5e+71]], $MachinePrecision]], N[(N[(N[(z - b), $MachinePrecision] / N[(t$95$1 / y), $MachinePrecision]), $MachinePrecision] + N[(N[(z / N[(t$95$1 / x), $MachinePrecision]), $MachinePrecision] + N[(a / N[(t$95$1 / N[(y + t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y + t), $MachinePrecision] * a + N[(x * z + N[(y * N[(z - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision]]]]
\frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}
\begin{array}{l}
t_1 := y + \left(x + t\right)\\
t_2 := \frac{\left(z \cdot \left(x + y\right) + \left(y + t\right) \cdot a\right) - y \cdot b}{t_1}\\
\mathbf{if}\;t_2 \leq -5 \cdot 10^{-22} \lor \neg \left(t_2 \leq 5 \cdot 10^{+71}\right):\\
\;\;\;\;\frac{z - b}{\frac{t_1}{y}} + \left(\frac{z}{\frac{t_1}{x}} + \frac{a}{\frac{t_1}{y + t}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y + t, a, \mathsf{fma}\left(x, z, y \cdot \left(z - b\right)\right)\right)}{t_1}\\
\end{array}
| Original | 26.0 |
|---|---|
| Target | 11.1 |
| Herbie | 0.2 |
if (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < -4.99999999999999954e-22 or 4.99999999999999972e71 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) Initial program 36.8
Simplified36.8
[Start]36.8 | \[ \frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}
\] |
|---|---|
sub-neg [=>]36.8 | \[ \frac{\color{blue}{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) + \left(-y \cdot b\right)}}{\left(x + t\right) + y}
\] |
+-commutative [=>]36.8 | \[ \frac{\color{blue}{\left(\left(t + y\right) \cdot a + \left(x + y\right) \cdot z\right)} + \left(-y \cdot b\right)}{\left(x + t\right) + y}
\] |
associate-+l+ [=>]36.8 | \[ \frac{\color{blue}{\left(t + y\right) \cdot a + \left(\left(x + y\right) \cdot z + \left(-y \cdot b\right)\right)}}{\left(x + t\right) + y}
\] |
fma-def [=>]36.8 | \[ \frac{\color{blue}{\mathsf{fma}\left(t + y, a, \left(x + y\right) \cdot z + \left(-y \cdot b\right)\right)}}{\left(x + t\right) + y}
\] |
+-commutative [=>]36.8 | \[ \frac{\mathsf{fma}\left(\color{blue}{y + t}, a, \left(x + y\right) \cdot z + \left(-y \cdot b\right)\right)}{\left(x + t\right) + y}
\] |
*-commutative [=>]36.8 | \[ \frac{\mathsf{fma}\left(y + t, a, \color{blue}{z \cdot \left(x + y\right)} + \left(-y \cdot b\right)\right)}{\left(x + t\right) + y}
\] |
distribute-rgt-in [=>]36.8 | \[ \frac{\mathsf{fma}\left(y + t, a, \color{blue}{\left(x \cdot z + y \cdot z\right)} + \left(-y \cdot b\right)\right)}{\left(x + t\right) + y}
\] |
associate-+l+ [=>]36.8 | \[ \frac{\mathsf{fma}\left(y + t, a, \color{blue}{x \cdot z + \left(y \cdot z + \left(-y \cdot b\right)\right)}\right)}{\left(x + t\right) + y}
\] |
fma-def [=>]36.8 | \[ \frac{\mathsf{fma}\left(y + t, a, \color{blue}{\mathsf{fma}\left(x, z, y \cdot z + \left(-y \cdot b\right)\right)}\right)}{\left(x + t\right) + y}
\] |
sub-neg [<=]36.8 | \[ \frac{\mathsf{fma}\left(y + t, a, \mathsf{fma}\left(x, z, \color{blue}{y \cdot z - y \cdot b}\right)\right)}{\left(x + t\right) + y}
\] |
distribute-lft-out-- [=>]36.8 | \[ \frac{\mathsf{fma}\left(y + t, a, \mathsf{fma}\left(x, z, \color{blue}{y \cdot \left(z - b\right)}\right)\right)}{\left(x + t\right) + y}
\] |
+-commutative [=>]36.8 | \[ \frac{\mathsf{fma}\left(y + t, a, \mathsf{fma}\left(x, z, y \cdot \left(z - b\right)\right)\right)}{\color{blue}{y + \left(x + t\right)}}
\] |
Taylor expanded in a around inf 36.8
Simplified0.1
[Start]36.8 | \[ \frac{\left(z - b\right) \cdot y}{y + \left(t + x\right)} + \left(\frac{z \cdot x}{y + \left(t + x\right)} + \frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)}\right)
\] |
|---|---|
associate-/l* [=>]27.7 | \[ \color{blue}{\frac{z - b}{\frac{y + \left(t + x\right)}{y}}} + \left(\frac{z \cdot x}{y + \left(t + x\right)} + \frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)}\right)
\] |
+-commutative [=>]27.7 | \[ \frac{z - b}{\frac{\color{blue}{\left(t + x\right) + y}}{y}} + \left(\frac{z \cdot x}{y + \left(t + x\right)} + \frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)}\right)
\] |
+-commutative [=>]27.7 | \[ \frac{z - b}{\frac{\color{blue}{\left(x + t\right)} + y}{y}} + \left(\frac{z \cdot x}{y + \left(t + x\right)} + \frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)}\right)
\] |
associate-/l* [=>]19.2 | \[ \frac{z - b}{\frac{\left(x + t\right) + y}{y}} + \left(\color{blue}{\frac{z}{\frac{y + \left(t + x\right)}{x}}} + \frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)}\right)
\] |
+-commutative [=>]19.2 | \[ \frac{z - b}{\frac{\left(x + t\right) + y}{y}} + \left(\frac{z}{\frac{\color{blue}{\left(t + x\right) + y}}{x}} + \frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)}\right)
\] |
+-commutative [=>]19.2 | \[ \frac{z - b}{\frac{\left(x + t\right) + y}{y}} + \left(\frac{z}{\frac{\color{blue}{\left(x + t\right)} + y}{x}} + \frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)}\right)
\] |
associate-/l* [=>]0.1 | \[ \frac{z - b}{\frac{\left(x + t\right) + y}{y}} + \left(\frac{z}{\frac{\left(x + t\right) + y}{x}} + \color{blue}{\frac{a}{\frac{y + \left(t + x\right)}{y + t}}}\right)
\] |
+-commutative [=>]0.1 | \[ \frac{z - b}{\frac{\left(x + t\right) + y}{y}} + \left(\frac{z}{\frac{\left(x + t\right) + y}{x}} + \frac{a}{\frac{\color{blue}{\left(t + x\right) + y}}{y + t}}\right)
\] |
+-commutative [=>]0.1 | \[ \frac{z - b}{\frac{\left(x + t\right) + y}{y}} + \left(\frac{z}{\frac{\left(x + t\right) + y}{x}} + \frac{a}{\frac{\color{blue}{\left(x + t\right)} + y}{y + t}}\right)
\] |
+-commutative [=>]0.1 | \[ \frac{z - b}{\frac{\left(x + t\right) + y}{y}} + \left(\frac{z}{\frac{\left(x + t\right) + y}{x}} + \frac{a}{\frac{\left(x + t\right) + y}{\color{blue}{t + y}}}\right)
\] |
if -4.99999999999999954e-22 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < 4.99999999999999972e71Initial program 0.3
Simplified0.3
[Start]0.3 | \[ \frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}
\] |
|---|---|
sub-neg [=>]0.3 | \[ \frac{\color{blue}{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) + \left(-y \cdot b\right)}}{\left(x + t\right) + y}
\] |
+-commutative [=>]0.3 | \[ \frac{\color{blue}{\left(\left(t + y\right) \cdot a + \left(x + y\right) \cdot z\right)} + \left(-y \cdot b\right)}{\left(x + t\right) + y}
\] |
associate-+l+ [=>]0.3 | \[ \frac{\color{blue}{\left(t + y\right) \cdot a + \left(\left(x + y\right) \cdot z + \left(-y \cdot b\right)\right)}}{\left(x + t\right) + y}
\] |
fma-def [=>]0.3 | \[ \frac{\color{blue}{\mathsf{fma}\left(t + y, a, \left(x + y\right) \cdot z + \left(-y \cdot b\right)\right)}}{\left(x + t\right) + y}
\] |
+-commutative [=>]0.3 | \[ \frac{\mathsf{fma}\left(\color{blue}{y + t}, a, \left(x + y\right) \cdot z + \left(-y \cdot b\right)\right)}{\left(x + t\right) + y}
\] |
*-commutative [=>]0.3 | \[ \frac{\mathsf{fma}\left(y + t, a, \color{blue}{z \cdot \left(x + y\right)} + \left(-y \cdot b\right)\right)}{\left(x + t\right) + y}
\] |
distribute-rgt-in [=>]0.3 | \[ \frac{\mathsf{fma}\left(y + t, a, \color{blue}{\left(x \cdot z + y \cdot z\right)} + \left(-y \cdot b\right)\right)}{\left(x + t\right) + y}
\] |
associate-+l+ [=>]0.3 | \[ \frac{\mathsf{fma}\left(y + t, a, \color{blue}{x \cdot z + \left(y \cdot z + \left(-y \cdot b\right)\right)}\right)}{\left(x + t\right) + y}
\] |
fma-def [=>]0.3 | \[ \frac{\mathsf{fma}\left(y + t, a, \color{blue}{\mathsf{fma}\left(x, z, y \cdot z + \left(-y \cdot b\right)\right)}\right)}{\left(x + t\right) + y}
\] |
sub-neg [<=]0.3 | \[ \frac{\mathsf{fma}\left(y + t, a, \mathsf{fma}\left(x, z, \color{blue}{y \cdot z - y \cdot b}\right)\right)}{\left(x + t\right) + y}
\] |
distribute-lft-out-- [=>]0.3 | \[ \frac{\mathsf{fma}\left(y + t, a, \mathsf{fma}\left(x, z, \color{blue}{y \cdot \left(z - b\right)}\right)\right)}{\left(x + t\right) + y}
\] |
+-commutative [=>]0.3 | \[ \frac{\mathsf{fma}\left(y + t, a, \mathsf{fma}\left(x, z, y \cdot \left(z - b\right)\right)\right)}{\color{blue}{y + \left(x + t\right)}}
\] |
Final simplification0.2
| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 4937 |
| Alternative 2 | |
|---|---|
| Error | 3.5 |
| Cost | 4297 |
| Alternative 3 | |
|---|---|
| Error | 7.2 |
| Cost | 4169 |
| Alternative 4 | |
|---|---|
| Error | 22.4 |
| Cost | 1744 |
| Alternative 5 | |
|---|---|
| Error | 24.5 |
| Cost | 1497 |
| Alternative 6 | |
|---|---|
| Error | 24.2 |
| Cost | 1497 |
| Alternative 7 | |
|---|---|
| Error | 28.2 |
| Cost | 1496 |
| Alternative 8 | |
|---|---|
| Error | 24.2 |
| Cost | 1496 |
| Alternative 9 | |
|---|---|
| Error | 27.9 |
| Cost | 1232 |
| Alternative 10 | |
|---|---|
| Error | 26.4 |
| Cost | 712 |
| Alternative 11 | |
|---|---|
| Error | 26.1 |
| Cost | 712 |
| Alternative 12 | |
|---|---|
| Error | 36.3 |
| Cost | 592 |
| Alternative 13 | |
|---|---|
| Error | 36.7 |
| Cost | 592 |
| Alternative 14 | |
|---|---|
| Error | 26.6 |
| Cost | 584 |
| Alternative 15 | |
|---|---|
| Error | 43.1 |
| Cost | 64 |
herbie shell --seed 2022349
(FPCore (x y z t a b)
:name "AI.Clustering.Hierarchical.Internal:ward from clustering-0.2.1"
:precision binary64
:herbie-target
(if (< (/ (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)) (+ (+ x t) y)) -3.5813117084150564e+153) (- (+ z a) b) (if (< (/ (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)) (+ (+ x t) y)) 1.2285964308315609e+82) (/ 1.0 (/ (+ (+ x t) y) (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)))) (- (+ z a) b)))
(/ (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)) (+ (+ x t) y)))