| Alternative 1 | |
|---|---|
| Accuracy | 96.9% |
| Cost | 16713 |

(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 (/ (- (+ (* a (+ y t)) (* z (+ x y))) (* y b)) t_1)))
(if (or (<= t_2 (- INFINITY)) (not (<= t_2 4e+285)))
(- (+ (/ (+ x y) (/ t_1 z)) (/ (+ y t) (/ t_1 a))) (/ y (/ (+ y t) b)))
(/ (fma y (- a b) (fma (+ x y) z (* t a))) (+ x (+ y t))))))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 = (((a * (y + t)) + (z * (x + y))) - (y * b)) / t_1;
double tmp;
if ((t_2 <= -((double) INFINITY)) || !(t_2 <= 4e+285)) {
tmp = (((x + y) / (t_1 / z)) + ((y + t) / (t_1 / a))) - (y / ((y + t) / b));
} else {
tmp = fma(y, (a - b), fma((x + y), z, (t * a))) / (x + (y + t));
}
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(a * Float64(y + t)) + Float64(z * Float64(x + y))) - Float64(y * b)) / t_1) tmp = 0.0 if ((t_2 <= Float64(-Inf)) || !(t_2 <= 4e+285)) tmp = Float64(Float64(Float64(Float64(x + y) / Float64(t_1 / z)) + Float64(Float64(y + t) / Float64(t_1 / a))) - Float64(y / Float64(Float64(y + t) / b))); else tmp = Float64(fma(y, Float64(a - b), fma(Float64(x + y), z, Float64(t * a))) / Float64(x + Float64(y + t))); 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[(a * N[(y + t), $MachinePrecision]), $MachinePrecision] + N[(z * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(y * b), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision]}, If[Or[LessEqual[t$95$2, (-Infinity)], N[Not[LessEqual[t$95$2, 4e+285]], $MachinePrecision]], N[(N[(N[(N[(x + y), $MachinePrecision] / N[(t$95$1 / z), $MachinePrecision]), $MachinePrecision] + N[(N[(y + t), $MachinePrecision] / N[(t$95$1 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(y / N[(N[(y + t), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y * N[(a - b), $MachinePrecision] + N[(N[(x + y), $MachinePrecision] * z + N[(t * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + N[(y + t), $MachinePrecision]), $MachinePrecision]), $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(a \cdot \left(y + t\right) + z \cdot \left(x + y\right)\right) - y \cdot b}{t_1}\\
\mathbf{if}\;t_2 \leq -\infty \lor \neg \left(t_2 \leq 4 \cdot 10^{+285}\right):\\
\;\;\;\;\left(\frac{x + y}{\frac{t_1}{z}} + \frac{y + t}{\frac{t_1}{a}}\right) - \frac{y}{\frac{y + t}{b}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, a - b, \mathsf{fma}\left(x + y, z, t \cdot a\right)\right)}{x + \left(y + t\right)}\\
\end{array}
Herbie found 18 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 60.9% |
|---|---|
| Target | 82.2% |
| Herbie | 96.9% |
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 3.9999999999999999e285 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) Initial program 5.5%
Simplified5.6%
[Start]5.5% | \[ \frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}
\] |
|---|---|
*-commutative [=>]5.5% | \[ \frac{\left(\left(x + y\right) \cdot z + \color{blue}{a \cdot \left(t + y\right)}\right) - y \cdot b}{\left(x + t\right) + y}
\] |
distribute-rgt-in [=>]5.1% | \[ \frac{\left(\left(x + y\right) \cdot z + \color{blue}{\left(t \cdot a + y \cdot a\right)}\right) - y \cdot b}{\left(x + t\right) + y}
\] |
associate-+r+ [=>]5.1% | \[ \frac{\color{blue}{\left(\left(\left(x + y\right) \cdot z + t \cdot a\right) + y \cdot a\right)} - y \cdot b}{\left(x + t\right) + y}
\] |
associate--l+ [=>]5.1% | \[ \frac{\color{blue}{\left(\left(x + y\right) \cdot z + t \cdot a\right) + \left(y \cdot a - y \cdot b\right)}}{\left(x + t\right) + y}
\] |
+-commutative [=>]5.1% | \[ \frac{\color{blue}{\left(t \cdot a + \left(x + y\right) \cdot z\right)} + \left(y \cdot a - y \cdot b\right)}{\left(x + t\right) + y}
\] |
+-commutative [=>]5.1% | \[ \frac{\color{blue}{\left(y \cdot a - y \cdot b\right) + \left(t \cdot a + \left(x + y\right) \cdot z\right)}}{\left(x + t\right) + y}
\] |
distribute-lft-out-- [=>]5.2% | \[ \frac{\color{blue}{y \cdot \left(a - b\right)} + \left(t \cdot a + \left(x + y\right) \cdot z\right)}{\left(x + t\right) + y}
\] |
fma-def [=>]5.5% | \[ \frac{\color{blue}{\mathsf{fma}\left(y, a - b, t \cdot a + \left(x + y\right) \cdot z\right)}}{\left(x + t\right) + y}
\] |
+-commutative [<=]5.5% | \[ \frac{\mathsf{fma}\left(y, a - b, \color{blue}{\left(x + y\right) \cdot z + t \cdot a}\right)}{\left(x + t\right) + y}
\] |
fma-def [=>]5.6% | \[ \frac{\mathsf{fma}\left(y, a - b, \color{blue}{\mathsf{fma}\left(x + y, z, t \cdot a\right)}\right)}{\left(x + t\right) + y}
\] |
associate-+l+ [=>]5.6% | \[ \frac{\mathsf{fma}\left(y, a - b, \mathsf{fma}\left(x + y, z, t \cdot a\right)\right)}{\color{blue}{x + \left(t + y\right)}}
\] |
+-commutative [=>]5.6% | \[ \frac{\mathsf{fma}\left(y, a - b, \mathsf{fma}\left(x + y, z, t \cdot a\right)\right)}{x + \color{blue}{\left(y + t\right)}}
\] |
Taylor expanded in a around -inf 5.5%
Simplified72.9%
[Start]5.5% | \[ \frac{\left(y + x\right) \cdot z}{y + \left(t + x\right)} + \left(-1 \cdot \frac{\left(-1 \cdot t + -1 \cdot y\right) \cdot a}{y + \left(t + x\right)} + -1 \cdot \frac{y \cdot b}{y + \left(t + x\right)}\right)
\] |
|---|---|
associate-+r+ [=>]5.5% | \[ \color{blue}{\left(\frac{\left(y + x\right) \cdot z}{y + \left(t + x\right)} + -1 \cdot \frac{\left(-1 \cdot t + -1 \cdot y\right) \cdot a}{y + \left(t + x\right)}\right) + -1 \cdot \frac{y \cdot b}{y + \left(t + x\right)}}
\] |
mul-1-neg [=>]5.5% | \[ \left(\frac{\left(y + x\right) \cdot z}{y + \left(t + x\right)} + -1 \cdot \frac{\left(-1 \cdot t + -1 \cdot y\right) \cdot a}{y + \left(t + x\right)}\right) + \color{blue}{\left(-\frac{y \cdot b}{y + \left(t + x\right)}\right)}
\] |
unsub-neg [=>]5.5% | \[ \color{blue}{\left(\frac{\left(y + x\right) \cdot z}{y + \left(t + x\right)} + -1 \cdot \frac{\left(-1 \cdot t + -1 \cdot y\right) \cdot a}{y + \left(t + x\right)}\right) - \frac{y \cdot b}{y + \left(t + x\right)}}
\] |
Taylor expanded in x around 0 71.0%
Simplified92.7%
[Start]71.0% | \[ \left(\frac{y + x}{\frac{y + \left(t + x\right)}{z}} - \frac{\left(-t\right) - y}{\frac{y + \left(t + x\right)}{a}}\right) - \frac{y \cdot b}{y + t}
\] |
|---|---|
associate-/l* [=>]92.7% | \[ \left(\frac{y + x}{\frac{y + \left(t + x\right)}{z}} - \frac{\left(-t\right) - y}{\frac{y + \left(t + x\right)}{a}}\right) - \color{blue}{\frac{y}{\frac{y + t}{b}}}
\] |
if -inf.0 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < 3.9999999999999999e285Initial program 99.7%
Simplified99.7%
[Start]99.7% | \[ \frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}
\] |
|---|---|
*-commutative [=>]99.7% | \[ \frac{\left(\left(x + y\right) \cdot z + \color{blue}{a \cdot \left(t + y\right)}\right) - y \cdot b}{\left(x + t\right) + y}
\] |
distribute-rgt-in [=>]99.7% | \[ \frac{\left(\left(x + y\right) \cdot z + \color{blue}{\left(t \cdot a + y \cdot a\right)}\right) - y \cdot b}{\left(x + t\right) + y}
\] |
associate-+r+ [=>]99.7% | \[ \frac{\color{blue}{\left(\left(\left(x + y\right) \cdot z + t \cdot a\right) + y \cdot a\right)} - y \cdot b}{\left(x + t\right) + y}
\] |
associate--l+ [=>]99.7% | \[ \frac{\color{blue}{\left(\left(x + y\right) \cdot z + t \cdot a\right) + \left(y \cdot a - y \cdot b\right)}}{\left(x + t\right) + y}
\] |
+-commutative [=>]99.7% | \[ \frac{\color{blue}{\left(t \cdot a + \left(x + y\right) \cdot z\right)} + \left(y \cdot a - y \cdot b\right)}{\left(x + t\right) + y}
\] |
+-commutative [=>]99.7% | \[ \frac{\color{blue}{\left(y \cdot a - y \cdot b\right) + \left(t \cdot a + \left(x + y\right) \cdot z\right)}}{\left(x + t\right) + y}
\] |
distribute-lft-out-- [=>]99.8% | \[ \frac{\color{blue}{y \cdot \left(a - b\right)} + \left(t \cdot a + \left(x + y\right) \cdot z\right)}{\left(x + t\right) + y}
\] |
fma-def [=>]99.7% | \[ \frac{\color{blue}{\mathsf{fma}\left(y, a - b, t \cdot a + \left(x + y\right) \cdot z\right)}}{\left(x + t\right) + y}
\] |
+-commutative [<=]99.7% | \[ \frac{\mathsf{fma}\left(y, a - b, \color{blue}{\left(x + y\right) \cdot z + t \cdot a}\right)}{\left(x + t\right) + y}
\] |
fma-def [=>]99.7% | \[ \frac{\mathsf{fma}\left(y, a - b, \color{blue}{\mathsf{fma}\left(x + y, z, t \cdot a\right)}\right)}{\left(x + t\right) + y}
\] |
associate-+l+ [=>]99.7% | \[ \frac{\mathsf{fma}\left(y, a - b, \mathsf{fma}\left(x + y, z, t \cdot a\right)\right)}{\color{blue}{x + \left(t + y\right)}}
\] |
+-commutative [=>]99.7% | \[ \frac{\mathsf{fma}\left(y, a - b, \mathsf{fma}\left(x + y, z, t \cdot a\right)\right)}{x + \color{blue}{\left(y + t\right)}}
\] |
Final simplification96.9%
| Alternative 1 | |
|---|---|
| Accuracy | 96.9% |
| Cost | 16713 |
| Alternative 2 | |
|---|---|
| Accuracy | 96.9% |
| Cost | 4809 |
| Alternative 3 | |
|---|---|
| Accuracy | 87.7% |
| Cost | 4169 |
| Alternative 4 | |
|---|---|
| Accuracy | 92.6% |
| Cost | 4169 |
| Alternative 5 | |
|---|---|
| Accuracy | 92.7% |
| Cost | 4168 |
| Alternative 6 | |
|---|---|
| Accuracy | 91.1% |
| Cost | 4168 |
| Alternative 7 | |
|---|---|
| Accuracy | 64.2% |
| Cost | 1620 |
| Alternative 8 | |
|---|---|
| Accuracy | 64.3% |
| Cost | 1488 |
| Alternative 9 | |
|---|---|
| Accuracy | 59.9% |
| Cost | 1232 |
| Alternative 10 | |
|---|---|
| Accuracy | 60.2% |
| Cost | 1232 |
| Alternative 11 | |
|---|---|
| Accuracy | 59.9% |
| Cost | 1104 |
| Alternative 12 | |
|---|---|
| Accuracy | 55.4% |
| Cost | 716 |
| Alternative 13 | |
|---|---|
| Accuracy | 56.2% |
| Cost | 716 |
| Alternative 14 | |
|---|---|
| Accuracy | 55.5% |
| Cost | 716 |
| Alternative 15 | |
|---|---|
| Accuracy | 57.7% |
| Cost | 580 |
| Alternative 16 | |
|---|---|
| Accuracy | 47.8% |
| Cost | 456 |
| Alternative 17 | |
|---|---|
| Accuracy | 44.5% |
| Cost | 328 |
| Alternative 18 | |
|---|---|
| Accuracy | 32.5% |
| Cost | 64 |
herbie shell --seed 2023272
(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)))