| Alternative 1 | |
|---|---|
| Error | 1.34% |
| Cost | 11721 |
(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 (+ x (+ y t)))
(t_2 (/ (- (+ (* z (+ x y)) (* a (+ y t))) (* y b)) (+ y (+ x t)))))
(if (or (<= t_2 -5e+278) (not (<= t_2 1e+168)))
(+
(- (fma (/ a t_1) t (* a (/ y t_1))) (/ b (/ t_1 y)))
(/ z (/ t_1 (+ x y))))
(/ (fma y (- z b) (fma (+ y t) a (* x z))) 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 = x + (y + t);
double t_2 = (((z * (x + y)) + (a * (y + t))) - (y * b)) / (y + (x + t));
double tmp;
if ((t_2 <= -5e+278) || !(t_2 <= 1e+168)) {
tmp = (fma((a / t_1), t, (a * (y / t_1))) - (b / (t_1 / y))) + (z / (t_1 / (x + y)));
} else {
tmp = fma(y, (z - b), fma((y + t), a, (x * z))) / 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(x + Float64(y + t)) t_2 = Float64(Float64(Float64(Float64(z * Float64(x + y)) + Float64(a * Float64(y + t))) - Float64(y * b)) / Float64(y + Float64(x + t))) tmp = 0.0 if ((t_2 <= -5e+278) || !(t_2 <= 1e+168)) tmp = Float64(Float64(fma(Float64(a / t_1), t, Float64(a * Float64(y / t_1))) - Float64(b / Float64(t_1 / y))) + Float64(z / Float64(t_1 / Float64(x + y)))); else tmp = Float64(fma(y, Float64(z - b), fma(Float64(y + t), a, Float64(x * z))) / 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[(x + N[(y + t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(N[(z * N[(x + y), $MachinePrecision]), $MachinePrecision] + N[(a * N[(y + t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(y * b), $MachinePrecision]), $MachinePrecision] / N[(y + N[(x + t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$2, -5e+278], N[Not[LessEqual[t$95$2, 1e+168]], $MachinePrecision]], N[(N[(N[(N[(a / t$95$1), $MachinePrecision] * t + N[(a * N[(y / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(b / N[(t$95$1 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(z / N[(t$95$1 / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y * N[(z - b), $MachinePrecision] + N[(N[(y + t), $MachinePrecision] * a + N[(x * z), $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 := x + \left(y + t\right)\\
t_2 := \frac{\left(z \cdot \left(x + y\right) + a \cdot \left(y + t\right)\right) - y \cdot b}{y + \left(x + t\right)}\\
\mathbf{if}\;t_2 \leq -5 \cdot 10^{+278} \lor \neg \left(t_2 \leq 10^{+168}\right):\\
\;\;\;\;\left(\mathsf{fma}\left(\frac{a}{t_1}, t, a \cdot \frac{y}{t_1}\right) - \frac{b}{\frac{t_1}{y}}\right) + \frac{z}{\frac{t_1}{x + y}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, z - b, \mathsf{fma}\left(y + t, a, x \cdot z\right)\right)}{t_1}\\
\end{array}
| Original | 41.59% |
|---|---|
| Target | 17.9% |
| Herbie | 1.34% |
if (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < -5.00000000000000029e278 or 9.9999999999999993e167 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) Initial program 87.85
Simplified87.85
[Start]87.85 | \[ \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 [=>]87.85 | \[ \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 [=>]87.85 | \[ \frac{\color{blue}{\left(-y \cdot b\right) + \left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right)}}{\left(x + t\right) + y}
\] |
*-commutative [=>]87.85 | \[ \frac{\left(-y \cdot b\right) + \left(\color{blue}{z \cdot \left(x + y\right)} + \left(t + y\right) \cdot a\right)}{\left(x + t\right) + y}
\] |
+-commutative [=>]87.85 | \[ \frac{\left(-y \cdot b\right) + \left(z \cdot \color{blue}{\left(y + x\right)} + \left(t + y\right) \cdot a\right)}{\left(x + t\right) + y}
\] |
distribute-rgt-in [=>]87.85 | \[ \frac{\left(-y \cdot b\right) + \left(\color{blue}{\left(y \cdot z + x \cdot z\right)} + \left(t + y\right) \cdot a\right)}{\left(x + t\right) + y}
\] |
associate-+l+ [=>]87.85 | \[ \frac{\left(-y \cdot b\right) + \color{blue}{\left(y \cdot z + \left(x \cdot z + \left(t + y\right) \cdot a\right)\right)}}{\left(x + t\right) + y}
\] |
associate-+r+ [=>]87.85 | \[ \frac{\color{blue}{\left(\left(-y \cdot b\right) + y \cdot z\right) + \left(x \cdot z + \left(t + y\right) \cdot a\right)}}{\left(x + t\right) + y}
\] |
+-commutative [<=]87.85 | \[ \frac{\color{blue}{\left(y \cdot z + \left(-y \cdot b\right)\right)} + \left(x \cdot z + \left(t + y\right) \cdot a\right)}{\left(x + t\right) + y}
\] |
sub-neg [<=]87.85 | \[ \frac{\color{blue}{\left(y \cdot z - y \cdot b\right)} + \left(x \cdot z + \left(t + y\right) \cdot a\right)}{\left(x + t\right) + y}
\] |
distribute-lft-out-- [=>]87.85 | \[ \frac{\color{blue}{y \cdot \left(z - b\right)} + \left(x \cdot z + \left(t + y\right) \cdot a\right)}{\left(x + t\right) + y}
\] |
fma-def [=>]87.85 | \[ \frac{\color{blue}{\mathsf{fma}\left(y, z - b, x \cdot z + \left(t + y\right) \cdot a\right)}}{\left(x + t\right) + y}
\] |
+-commutative [=>]87.85 | \[ \frac{\mathsf{fma}\left(y, z - b, \color{blue}{\left(t + y\right) \cdot a + x \cdot z}\right)}{\left(x + t\right) + y}
\] |
fma-def [=>]87.85 | \[ \frac{\mathsf{fma}\left(y, z - b, \color{blue}{\mathsf{fma}\left(t + y, a, x \cdot z\right)}\right)}{\left(x + t\right) + y}
\] |
+-commutative [=>]87.85 | \[ \frac{\mathsf{fma}\left(y, z - b, \mathsf{fma}\left(\color{blue}{y + t}, a, x \cdot z\right)\right)}{\left(x + t\right) + y}
\] |
associate-+l+ [=>]87.85 | \[ \frac{\mathsf{fma}\left(y, z - b, \mathsf{fma}\left(y + t, a, x \cdot z\right)\right)}{\color{blue}{x + \left(t + y\right)}}
\] |
+-commutative [=>]87.85 | \[ \frac{\mathsf{fma}\left(y, z - b, \mathsf{fma}\left(y + t, a, x \cdot z\right)\right)}{x + \color{blue}{\left(y + t\right)}}
\] |
Taylor expanded in z around inf 87.85
Simplified2.4
[Start]87.85 | \[ \frac{\left(y + x\right) \cdot z}{y + \left(t + x\right)} + \left(\frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)} + -1 \cdot \frac{y \cdot b}{y + \left(t + x\right)}\right)
\] |
|---|---|
+-commutative [=>]87.85 | \[ \color{blue}{\left(\frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)} + -1 \cdot \frac{y \cdot b}{y + \left(t + x\right)}\right) + \frac{\left(y + x\right) \cdot z}{y + \left(t + x\right)}}
\] |
Applied egg-rr2.39
if -5.00000000000000029e278 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < 9.9999999999999993e167Initial program 0.42
Simplified0.41
[Start]0.42 | \[ \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.42 | \[ \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.42 | \[ \frac{\color{blue}{\left(-y \cdot b\right) + \left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right)}}{\left(x + t\right) + y}
\] |
*-commutative [=>]0.42 | \[ \frac{\left(-y \cdot b\right) + \left(\color{blue}{z \cdot \left(x + y\right)} + \left(t + y\right) \cdot a\right)}{\left(x + t\right) + y}
\] |
+-commutative [=>]0.42 | \[ \frac{\left(-y \cdot b\right) + \left(z \cdot \color{blue}{\left(y + x\right)} + \left(t + y\right) \cdot a\right)}{\left(x + t\right) + y}
\] |
distribute-rgt-in [=>]0.42 | \[ \frac{\left(-y \cdot b\right) + \left(\color{blue}{\left(y \cdot z + x \cdot z\right)} + \left(t + y\right) \cdot a\right)}{\left(x + t\right) + y}
\] |
associate-+l+ [=>]0.42 | \[ \frac{\left(-y \cdot b\right) + \color{blue}{\left(y \cdot z + \left(x \cdot z + \left(t + y\right) \cdot a\right)\right)}}{\left(x + t\right) + y}
\] |
associate-+r+ [=>]0.42 | \[ \frac{\color{blue}{\left(\left(-y \cdot b\right) + y \cdot z\right) + \left(x \cdot z + \left(t + y\right) \cdot a\right)}}{\left(x + t\right) + y}
\] |
+-commutative [<=]0.42 | \[ \frac{\color{blue}{\left(y \cdot z + \left(-y \cdot b\right)\right)} + \left(x \cdot z + \left(t + y\right) \cdot a\right)}{\left(x + t\right) + y}
\] |
sub-neg [<=]0.42 | \[ \frac{\color{blue}{\left(y \cdot z - y \cdot b\right)} + \left(x \cdot z + \left(t + y\right) \cdot a\right)}{\left(x + t\right) + y}
\] |
distribute-lft-out-- [=>]0.42 | \[ \frac{\color{blue}{y \cdot \left(z - b\right)} + \left(x \cdot z + \left(t + y\right) \cdot a\right)}{\left(x + t\right) + y}
\] |
fma-def [=>]0.41 | \[ \frac{\color{blue}{\mathsf{fma}\left(y, z - b, x \cdot z + \left(t + y\right) \cdot a\right)}}{\left(x + t\right) + y}
\] |
+-commutative [=>]0.41 | \[ \frac{\mathsf{fma}\left(y, z - b, \color{blue}{\left(t + y\right) \cdot a + x \cdot z}\right)}{\left(x + t\right) + y}
\] |
fma-def [=>]0.41 | \[ \frac{\mathsf{fma}\left(y, z - b, \color{blue}{\mathsf{fma}\left(t + y, a, x \cdot z\right)}\right)}{\left(x + t\right) + y}
\] |
+-commutative [=>]0.41 | \[ \frac{\mathsf{fma}\left(y, z - b, \mathsf{fma}\left(\color{blue}{y + t}, a, x \cdot z\right)\right)}{\left(x + t\right) + y}
\] |
associate-+l+ [=>]0.41 | \[ \frac{\mathsf{fma}\left(y, z - b, \mathsf{fma}\left(y + t, a, x \cdot z\right)\right)}{\color{blue}{x + \left(t + y\right)}}
\] |
+-commutative [=>]0.41 | \[ \frac{\mathsf{fma}\left(y, z - b, \mathsf{fma}\left(y + t, a, x \cdot z\right)\right)}{x + \color{blue}{\left(y + t\right)}}
\] |
Final simplification1.34
| Alternative 1 | |
|---|---|
| Error | 1.34% |
| Cost | 11721 |
| Alternative 2 | |
|---|---|
| Error | 1.82% |
| Cost | 4937 |
| Alternative 3 | |
|---|---|
| Error | 1.34% |
| Cost | 4937 |
| Alternative 4 | |
|---|---|
| Error | 5.13% |
| Cost | 4297 |
| Alternative 5 | |
|---|---|
| Error | 12.09% |
| Cost | 4169 |
| Alternative 6 | |
|---|---|
| Error | 44.46% |
| Cost | 2408 |
| Alternative 7 | |
|---|---|
| Error | 46.87% |
| Cost | 2288 |
| Alternative 8 | |
|---|---|
| Error | 48.01% |
| Cost | 2024 |
| Alternative 9 | |
|---|---|
| Error | 46.87% |
| Cost | 2024 |
| Alternative 10 | |
|---|---|
| Error | 46.93% |
| Cost | 2024 |
| Alternative 11 | |
|---|---|
| Error | 49.3% |
| Cost | 2020 |
| Alternative 12 | |
|---|---|
| Error | 45.86% |
| Cost | 1892 |
| Alternative 13 | |
|---|---|
| Error | 40.87% |
| Cost | 1104 |
| Alternative 14 | |
|---|---|
| Error | 42.33% |
| Cost | 976 |
| Alternative 15 | |
|---|---|
| Error | 42.61% |
| Cost | 976 |
| Alternative 16 | |
|---|---|
| Error | 42.72% |
| Cost | 976 |
| Alternative 17 | |
|---|---|
| Error | 42.36% |
| Cost | 848 |
| Alternative 18 | |
|---|---|
| Error | 56.17% |
| Cost | 592 |
| Alternative 19 | |
|---|---|
| Error | 67.49% |
| Cost | 64 |
herbie shell --seed 2023089
(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)))