| Alternative 1 | |
|---|---|
| Error | 0.3 |
| 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 (* (+ y t) a))
(t_3 (/ (- (+ (* (+ x y) z) t_2) (* y b)) t_1))
(t_4 (+ x (+ y t))))
(if (or (<= t_3 (- INFINITY)) (not (<= t_3 5e+305)))
(+ (* x (/ z t_4)) (+ (* (+ y t) (/ a t_4)) (* y (/ (- z b) t_4))))
(/ (- (fma (+ x y) z t_2) (* y 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 = (y + t) * a;
double t_3 = ((((x + y) * z) + t_2) - (y * b)) / t_1;
double t_4 = x + (y + t);
double tmp;
if ((t_3 <= -((double) INFINITY)) || !(t_3 <= 5e+305)) {
tmp = (x * (z / t_4)) + (((y + t) * (a / t_4)) + (y * ((z - b) / t_4)));
} else {
tmp = (fma((x + y), z, t_2) - (y * 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(y + t) * a) t_3 = Float64(Float64(Float64(Float64(Float64(x + y) * z) + t_2) - Float64(y * b)) / t_1) t_4 = Float64(x + Float64(y + t)) tmp = 0.0 if ((t_3 <= Float64(-Inf)) || !(t_3 <= 5e+305)) tmp = Float64(Float64(x * Float64(z / t_4)) + Float64(Float64(Float64(y + t) * Float64(a / t_4)) + Float64(y * Float64(Float64(z - b) / t_4)))); else tmp = Float64(Float64(fma(Float64(x + y), z, t_2) - Float64(y * 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[(y + t), $MachinePrecision] * a), $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[(N[(N[(x + y), $MachinePrecision] * z), $MachinePrecision] + t$95$2), $MachinePrecision] - N[(y * b), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision]}, Block[{t$95$4 = N[(x + N[(y + t), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$3, (-Infinity)], N[Not[LessEqual[t$95$3, 5e+305]], $MachinePrecision]], N[(N[(x * N[(z / t$95$4), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(y + t), $MachinePrecision] * N[(a / t$95$4), $MachinePrecision]), $MachinePrecision] + N[(y * N[(N[(z - b), $MachinePrecision] / t$95$4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(x + y), $MachinePrecision] * z + t$95$2), $MachinePrecision] - N[(y * b), $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 := \left(y + t\right) \cdot a\\
t_3 := \frac{\left(\left(x + y\right) \cdot z + t_2\right) - y \cdot b}{t_1}\\
t_4 := x + \left(y + t\right)\\
\mathbf{if}\;t_3 \leq -\infty \lor \neg \left(t_3 \leq 5 \cdot 10^{+305}\right):\\
\;\;\;\;x \cdot \frac{z}{t_4} + \left(\left(y + t\right) \cdot \frac{a}{t_4} + y \cdot \frac{z - b}{t_4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x + y, z, t_2\right) - y \cdot b}{t_1}\\
\end{array}
| Original | 26.7 |
|---|---|
| Target | 11.1 |
| Herbie | 0.3 |
if (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < -inf.0 or 5.00000000000000009e305 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) Initial program 63.9
Simplified63.9
[Start]63.9 | \[ \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 [=>]63.9 | \[ \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 [=>]63.9 | \[ \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+ [=>]63.9 | \[ \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 [=>]63.9 | \[ \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 [=>]63.9 | \[ \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 [=>]63.9 | \[ \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 [=>]63.9 | \[ \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+ [=>]63.9 | \[ \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 [=>]63.9 | \[ \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 [<=]63.9 | \[ \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-- [=>]63.9 | \[ \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 [=>]63.9 | \[ \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 63.9
Simplified0.3
[Start]63.9 | \[ \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)
\] |
|---|---|
+-commutative [=>]63.9 | \[ \color{blue}{\left(\frac{z \cdot x}{y + \left(t + x\right)} + \frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)}\right) + \frac{\left(z - b\right) \cdot y}{y + \left(t + x\right)}}
\] |
associate-+l+ [=>]63.9 | \[ \color{blue}{\frac{z \cdot x}{y + \left(t + x\right)} + \left(\frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)} + \frac{\left(z - b\right) \cdot y}{y + \left(t + x\right)}\right)}
\] |
associate-/l* [=>]52.6 | \[ \color{blue}{\frac{z}{\frac{y + \left(t + x\right)}{x}}} + \left(\frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)} + \frac{\left(z - b\right) \cdot y}{y + \left(t + x\right)}\right)
\] |
associate-/r/ [=>]52.7 | \[ \color{blue}{\frac{z}{y + \left(t + x\right)} \cdot x} + \left(\frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)} + \frac{\left(z - b\right) \cdot y}{y + \left(t + x\right)}\right)
\] |
associate-+r+ [=>]52.7 | \[ \frac{z}{\color{blue}{\left(y + t\right) + x}} \cdot x + \left(\frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)} + \frac{\left(z - b\right) \cdot y}{y + \left(t + x\right)}\right)
\] |
+-commutative [=>]52.7 | \[ \frac{z}{\color{blue}{x + \left(y + t\right)}} \cdot x + \left(\frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)} + \frac{\left(z - b\right) \cdot y}{y + \left(t + x\right)}\right)
\] |
+-commutative [=>]52.7 | \[ \frac{z}{x + \color{blue}{\left(t + y\right)}} \cdot x + \left(\frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)} + \frac{\left(z - b\right) \cdot y}{y + \left(t + x\right)}\right)
\] |
associate-/l* [=>]32.0 | \[ \frac{z}{x + \left(t + y\right)} \cdot x + \left(\color{blue}{\frac{a}{\frac{y + \left(t + x\right)}{y + t}}} + \frac{\left(z - b\right) \cdot y}{y + \left(t + x\right)}\right)
\] |
associate-/r/ [=>]32.1 | \[ \frac{z}{x + \left(t + y\right)} \cdot x + \left(\color{blue}{\frac{a}{y + \left(t + x\right)} \cdot \left(y + t\right)} + \frac{\left(z - b\right) \cdot y}{y + \left(t + x\right)}\right)
\] |
associate-+r+ [=>]32.1 | \[ \frac{z}{x + \left(t + y\right)} \cdot x + \left(\frac{a}{\color{blue}{\left(y + t\right) + x}} \cdot \left(y + t\right) + \frac{\left(z - b\right) \cdot y}{y + \left(t + x\right)}\right)
\] |
+-commutative [=>]32.1 | \[ \frac{z}{x + \left(t + y\right)} \cdot x + \left(\frac{a}{\color{blue}{x + \left(y + t\right)}} \cdot \left(y + t\right) + \frac{\left(z - b\right) \cdot y}{y + \left(t + x\right)}\right)
\] |
+-commutative [=>]32.1 | \[ \frac{z}{x + \left(t + y\right)} \cdot x + \left(\frac{a}{x + \color{blue}{\left(t + y\right)}} \cdot \left(y + t\right) + \frac{\left(z - b\right) \cdot y}{y + \left(t + x\right)}\right)
\] |
+-commutative [=>]32.1 | \[ \frac{z}{x + \left(t + y\right)} \cdot x + \left(\frac{a}{x + \left(t + y\right)} \cdot \color{blue}{\left(t + y\right)} + \frac{\left(z - b\right) \cdot y}{y + \left(t + x\right)}\right)
\] |
associate-/l* [=>]0.2 | \[ \frac{z}{x + \left(t + y\right)} \cdot x + \left(\frac{a}{x + \left(t + y\right)} \cdot \left(t + y\right) + \color{blue}{\frac{z - b}{\frac{y + \left(t + x\right)}{y}}}\right)
\] |
associate-/r/ [=>]0.3 | \[ \frac{z}{x + \left(t + y\right)} \cdot x + \left(\frac{a}{x + \left(t + y\right)} \cdot \left(t + y\right) + \color{blue}{\frac{z - b}{y + \left(t + x\right)} \cdot y}\right)
\] |
associate-+r+ [=>]0.3 | \[ \frac{z}{x + \left(t + y\right)} \cdot x + \left(\frac{a}{x + \left(t + y\right)} \cdot \left(t + y\right) + \frac{z - b}{\color{blue}{\left(y + t\right) + x}} \cdot y\right)
\] |
+-commutative [=>]0.3 | \[ \frac{z}{x + \left(t + y\right)} \cdot x + \left(\frac{a}{x + \left(t + y\right)} \cdot \left(t + y\right) + \frac{z - b}{\color{blue}{x + \left(y + t\right)}} \cdot y\right)
\] |
+-commutative [=>]0.3 | \[ \frac{z}{x + \left(t + y\right)} \cdot x + \left(\frac{a}{x + \left(t + y\right)} \cdot \left(t + y\right) + \frac{z - b}{x + \color{blue}{\left(t + y\right)}} \cdot y\right)
\] |
if -inf.0 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < 5.00000000000000009e305Initial 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}
\] |
|---|---|
cancel-sign-sub [<=]0.3 | \[ \frac{\color{blue}{\left(\left(x + y\right) \cdot z - \left(-\left(t + y\right)\right) \cdot a\right)} - y \cdot b}{\left(x + t\right) + y}
\] |
distribute-lft-neg-in [<=]0.3 | \[ \frac{\left(\left(x + y\right) \cdot z - \color{blue}{\left(-\left(t + y\right) \cdot a\right)}\right) - y \cdot b}{\left(x + t\right) + y}
\] |
fma-neg [=>]0.3 | \[ \frac{\color{blue}{\mathsf{fma}\left(x + y, z, -\left(-\left(t + y\right) \cdot a\right)\right)} - y \cdot b}{\left(x + t\right) + y}
\] |
remove-double-neg [=>]0.3 | \[ \frac{\mathsf{fma}\left(x + y, z, \color{blue}{\left(t + y\right) \cdot a}\right) - y \cdot b}{\left(x + t\right) + y}
\] |
+-commutative [=>]0.3 | \[ \frac{\mathsf{fma}\left(x + y, z, \color{blue}{\left(y + t\right)} \cdot a\right) - y \cdot b}{\left(x + t\right) + y}
\] |
+-commutative [=>]0.3 | \[ \frac{\mathsf{fma}\left(x + y, z, \left(y + t\right) \cdot a\right) - y \cdot b}{\color{blue}{y + \left(x + t\right)}}
\] |
Final simplification0.3
| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 4937 |
| Alternative 2 | |
|---|---|
| Error | 2.6 |
| Cost | 4297 |
| Alternative 3 | |
|---|---|
| Error | 8.0 |
| Cost | 4169 |
| Alternative 4 | |
|---|---|
| Error | 27.6 |
| Cost | 1500 |
| Alternative 5 | |
|---|---|
| Error | 27.4 |
| Cost | 1500 |
| Alternative 6 | |
|---|---|
| Error | 27.6 |
| Cost | 1372 |
| Alternative 7 | |
|---|---|
| Error | 28.5 |
| Cost | 1372 |
| Alternative 8 | |
|---|---|
| Error | 28.6 |
| Cost | 1372 |
| Alternative 9 | |
|---|---|
| Error | 24.4 |
| Cost | 1364 |
| Alternative 10 | |
|---|---|
| Error | 23.2 |
| Cost | 1224 |
| Alternative 11 | |
|---|---|
| Error | 26.1 |
| Cost | 1104 |
| Alternative 12 | |
|---|---|
| Error | 27.4 |
| Cost | 976 |
| Alternative 13 | |
|---|---|
| Error | 27.1 |
| Cost | 976 |
| Alternative 14 | |
|---|---|
| Error | 27.4 |
| Cost | 848 |
| Alternative 15 | |
|---|---|
| Error | 36.6 |
| Cost | 592 |
| Alternative 16 | |
|---|---|
| Error | 43.6 |
| Cost | 64 |
herbie shell --seed 2022354
(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)))