| Alternative 1 | |
|---|---|
| Error | 9.75% |
| Cost | 4552 |
(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 (* z (+ x y)))
(t_2 (+ x (+ y t)))
(t_3 (+ y (+ x t)))
(t_4 (* (+ y t) a))
(t_5 (/ (- (+ t_4 t_1) (* y b)) t_3)))
(if (or (<= t_5 (- INFINITY)) (not (<= t_5 5e+306)))
(+ (+ (* y (/ (- z b) t_2)) (* (+ y t) (/ a t_2))) (* x (/ z t_2)))
(+ (/ t_4 t_3) (/ (- t_1 (* y b)) t_3)))))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 = z * (x + y);
double t_2 = x + (y + t);
double t_3 = y + (x + t);
double t_4 = (y + t) * a;
double t_5 = ((t_4 + t_1) - (y * b)) / t_3;
double tmp;
if ((t_5 <= -((double) INFINITY)) || !(t_5 <= 5e+306)) {
tmp = ((y * ((z - b) / t_2)) + ((y + t) * (a / t_2))) + (x * (z / t_2));
} else {
tmp = (t_4 / t_3) + ((t_1 - (y * b)) / t_3);
}
return tmp;
}
public static 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);
}
public static double code(double x, double y, double z, double t, double a, double b) {
double t_1 = z * (x + y);
double t_2 = x + (y + t);
double t_3 = y + (x + t);
double t_4 = (y + t) * a;
double t_5 = ((t_4 + t_1) - (y * b)) / t_3;
double tmp;
if ((t_5 <= -Double.POSITIVE_INFINITY) || !(t_5 <= 5e+306)) {
tmp = ((y * ((z - b) / t_2)) + ((y + t) * (a / t_2))) + (x * (z / t_2));
} else {
tmp = (t_4 / t_3) + ((t_1 - (y * b)) / t_3);
}
return tmp;
}
def code(x, y, z, t, a, b): return ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y)
def code(x, y, z, t, a, b): t_1 = z * (x + y) t_2 = x + (y + t) t_3 = y + (x + t) t_4 = (y + t) * a t_5 = ((t_4 + t_1) - (y * b)) / t_3 tmp = 0 if (t_5 <= -math.inf) or not (t_5 <= 5e+306): tmp = ((y * ((z - b) / t_2)) + ((y + t) * (a / t_2))) + (x * (z / t_2)) else: tmp = (t_4 / t_3) + ((t_1 - (y * b)) / t_3) 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(z * Float64(x + y)) t_2 = Float64(x + Float64(y + t)) t_3 = Float64(y + Float64(x + t)) t_4 = Float64(Float64(y + t) * a) t_5 = Float64(Float64(Float64(t_4 + t_1) - Float64(y * b)) / t_3) tmp = 0.0 if ((t_5 <= Float64(-Inf)) || !(t_5 <= 5e+306)) tmp = Float64(Float64(Float64(y * Float64(Float64(z - b) / t_2)) + Float64(Float64(y + t) * Float64(a / t_2))) + Float64(x * Float64(z / t_2))); else tmp = Float64(Float64(t_4 / t_3) + Float64(Float64(t_1 - Float64(y * b)) / t_3)); end return tmp end
function tmp = code(x, y, z, t, a, b) tmp = ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y); end
function tmp_2 = code(x, y, z, t, a, b) t_1 = z * (x + y); t_2 = x + (y + t); t_3 = y + (x + t); t_4 = (y + t) * a; t_5 = ((t_4 + t_1) - (y * b)) / t_3; tmp = 0.0; if ((t_5 <= -Inf) || ~((t_5 <= 5e+306))) tmp = ((y * ((z - b) / t_2)) + ((y + t) * (a / t_2))) + (x * (z / t_2)); else tmp = (t_4 / t_3) + ((t_1 - (y * b)) / t_3); end tmp_2 = 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[(z * N[(x + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x + N[(y + t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(y + N[(x + t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[(y + t), $MachinePrecision] * a), $MachinePrecision]}, Block[{t$95$5 = N[(N[(N[(t$95$4 + t$95$1), $MachinePrecision] - N[(y * b), $MachinePrecision]), $MachinePrecision] / t$95$3), $MachinePrecision]}, If[Or[LessEqual[t$95$5, (-Infinity)], N[Not[LessEqual[t$95$5, 5e+306]], $MachinePrecision]], N[(N[(N[(y * N[(N[(z - b), $MachinePrecision] / t$95$2), $MachinePrecision]), $MachinePrecision] + N[(N[(y + t), $MachinePrecision] * N[(a / t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x * N[(z / t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$4 / t$95$3), $MachinePrecision] + N[(N[(t$95$1 - N[(y * b), $MachinePrecision]), $MachinePrecision] / t$95$3), $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 := z \cdot \left(x + y\right)\\
t_2 := x + \left(y + t\right)\\
t_3 := y + \left(x + t\right)\\
t_4 := \left(y + t\right) \cdot a\\
t_5 := \frac{\left(t_4 + t_1\right) - y \cdot b}{t_3}\\
\mathbf{if}\;t_5 \leq -\infty \lor \neg \left(t_5 \leq 5 \cdot 10^{+306}\right):\\
\;\;\;\;\left(y \cdot \frac{z - b}{t_2} + \left(y + t\right) \cdot \frac{a}{t_2}\right) + x \cdot \frac{z}{t_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_4}{t_3} + \frac{t_1 - y \cdot b}{t_3}\\
\end{array}
Results
| Original | 41.91% |
|---|---|
| Target | 16.81% |
| Herbie | 0.42% |
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 4.99999999999999993e306 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) Initial program 99.91
Simplified99.91
[Start]99.91 | \[ \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 [=>]99.91 | \[ \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 [=>]99.91 | \[ \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+ [=>]99.91 | \[ \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 [=>]99.91 | \[ \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 [=>]99.91 | \[ \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 [=>]99.91 | \[ \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 [=>]99.91 | \[ \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+ [=>]99.91 | \[ \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 [=>]99.91 | \[ \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 [<=]99.91 | \[ \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-- [=>]99.91 | \[ \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 [=>]99.91 | \[ \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 99.91
Simplified0.28
[Start]99.91 | \[ \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 [=>]99.91 | \[ \frac{\left(z - b\right) \cdot y}{y + \left(t + x\right)} + \color{blue}{\left(\frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)} + \frac{z \cdot x}{y + \left(t + x\right)}\right)}
\] |
associate-+r+ [=>]99.91 | \[ \color{blue}{\left(\frac{\left(z - b\right) \cdot y}{y + \left(t + x\right)} + \frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)}\right) + \frac{z \cdot x}{y + \left(t + x\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)) < 4.99999999999999993e306Initial program 0.52
Simplified0.52
[Start]0.52 | \[ \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.52 | \[ \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.52 | \[ \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.52 | \[ \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.52 | \[ \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.52 | \[ \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.52 | \[ \frac{\mathsf{fma}\left(x + y, z, \left(y + t\right) \cdot a\right) - y \cdot b}{\color{blue}{y + \left(x + t\right)}}
\] |
Taylor expanded in z around inf 0.5
Simplified0.51
[Start]0.5 | \[ \left(\frac{\left(y + x\right) \cdot z}{y + \left(t + x\right)} + \frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)}\right) - \frac{y \cdot b}{y + \left(t + x\right)}
\] |
|---|---|
+-commutative [=>]0.5 | \[ \color{blue}{\left(\frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)} + \frac{\left(y + x\right) \cdot z}{y + \left(t + x\right)}\right)} - \frac{y \cdot b}{y + \left(t + x\right)}
\] |
associate--l+ [=>]0.5 | \[ \color{blue}{\frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)} + \left(\frac{\left(y + x\right) \cdot z}{y + \left(t + x\right)} - \frac{y \cdot b}{y + \left(t + x\right)}\right)}
\] |
associate-+r+ [=>]0.5 | \[ \frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)} + \left(\frac{\left(y + x\right) \cdot z}{\color{blue}{\left(y + t\right) + x}} - \frac{y \cdot b}{y + \left(t + x\right)}\right)
\] |
+-commutative [<=]0.5 | \[ \frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)} + \left(\frac{\left(y + x\right) \cdot z}{\color{blue}{x + \left(y + t\right)}} - \frac{y \cdot b}{y + \left(t + x\right)}\right)
\] |
associate-+r+ [=>]0.5 | \[ \frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)} + \left(\frac{\left(y + x\right) \cdot z}{x + \left(y + t\right)} - \frac{y \cdot b}{\color{blue}{\left(y + t\right) + x}}\right)
\] |
+-commutative [<=]0.5 | \[ \frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)} + \left(\frac{\left(y + x\right) \cdot z}{x + \left(y + t\right)} - \frac{y \cdot b}{\color{blue}{x + \left(y + t\right)}}\right)
\] |
div-sub [<=]0.51 | \[ \frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)} + \color{blue}{\frac{\left(y + x\right) \cdot z - y \cdot b}{x + \left(y + t\right)}}
\] |
+-commutative [=>]0.51 | \[ \frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)} + \frac{\left(y + x\right) \cdot z - y \cdot b}{\color{blue}{\left(y + t\right) + x}}
\] |
associate-+r+ [<=]0.51 | \[ \frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)} + \frac{\left(y + x\right) \cdot z - y \cdot b}{\color{blue}{y + \left(t + x\right)}}
\] |
*-commutative [=>]0.51 | \[ \frac{a \cdot \left(y + t\right)}{y + \left(t + x\right)} + \frac{\color{blue}{z \cdot \left(y + x\right)} - y \cdot b}{y + \left(t + x\right)}
\] |
Final simplification0.42
| Alternative 1 | |
|---|---|
| Error | 9.75% |
| Cost | 4552 |
| Alternative 2 | |
|---|---|
| Error | 13.36% |
| Cost | 4168 |
| Alternative 3 | |
|---|---|
| Error | 9.75% |
| Cost | 4168 |
| Alternative 4 | |
|---|---|
| Error | 44.22% |
| Cost | 2156 |
| Alternative 5 | |
|---|---|
| Error | 45.17% |
| Cost | 2156 |
| Alternative 6 | |
|---|---|
| Error | 35.89% |
| Cost | 1884 |
| Alternative 7 | |
|---|---|
| Error | 36.45% |
| Cost | 1884 |
| Alternative 8 | |
|---|---|
| Error | 28.18% |
| Cost | 1608 |
| Alternative 9 | |
|---|---|
| Error | 43.78% |
| Cost | 1564 |
| Alternative 10 | |
|---|---|
| Error | 45.29% |
| Cost | 1500 |
| Alternative 11 | |
|---|---|
| Error | 43.96% |
| Cost | 1500 |
| Alternative 12 | |
|---|---|
| Error | 42.04% |
| Cost | 1108 |
| Alternative 13 | |
|---|---|
| Error | 42.57% |
| Cost | 973 |
| Alternative 14 | |
|---|---|
| Error | 44.4% |
| Cost | 844 |
| Alternative 15 | |
|---|---|
| Error | 44.41% |
| Cost | 844 |
| Alternative 16 | |
|---|---|
| Error | 44.38% |
| Cost | 844 |
| Alternative 17 | |
|---|---|
| Error | 54.93% |
| Cost | 720 |
| Alternative 18 | |
|---|---|
| Error | 40.85% |
| Cost | 584 |
| Alternative 19 | |
|---|---|
| Error | 51.63% |
| Cost | 456 |
| Alternative 20 | |
|---|---|
| Error | 55.17% |
| Cost | 328 |
| Alternative 21 | |
|---|---|
| Error | 66.58% |
| Cost | 64 |
herbie shell --seed 2023103
(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)))