(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 (/ (- (+ (* (+ x y) z) (* (+ y t) a)) (* y b)) t_1))
(t_3 (- (+ z a) b)))
(if (<= t_2 (- INFINITY))
t_3
(if (<= t_2 2.3121383245545765e+227)
(-
(+
(/ (* y z) t_1)
(+ (/ (* x z) t_1) (+ (/ (* t a) t_1) (/ (* y a) t_1))))
(* b (/ y t_1)))
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 = y + (x + t);
double t_2 = ((((x + y) * z) + ((y + t) * a)) - (y * b)) / t_1;
double t_3 = (z + a) - b;
double tmp;
if (t_2 <= -((double) INFINITY)) {
tmp = t_3;
} else if (t_2 <= 2.3121383245545765e+227) {
tmp = (((y * z) / t_1) + (((x * z) / t_1) + (((t * a) / t_1) + ((y * a) / t_1)))) - (b * (y / t_1));
} else {
tmp = 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 = y + (x + t);
double t_2 = ((((x + y) * z) + ((y + t) * a)) - (y * b)) / t_1;
double t_3 = (z + a) - b;
double tmp;
if (t_2 <= -Double.POSITIVE_INFINITY) {
tmp = t_3;
} else if (t_2 <= 2.3121383245545765e+227) {
tmp = (((y * z) / t_1) + (((x * z) / t_1) + (((t * a) / t_1) + ((y * a) / t_1)))) - (b * (y / t_1));
} else {
tmp = 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 = y + (x + t) t_2 = ((((x + y) * z) + ((y + t) * a)) - (y * b)) / t_1 t_3 = (z + a) - b tmp = 0 if t_2 <= -math.inf: tmp = t_3 elif t_2 <= 2.3121383245545765e+227: tmp = (((y * z) / t_1) + (((x * z) / t_1) + (((t * a) / t_1) + ((y * a) / t_1)))) - (b * (y / t_1)) else: tmp = 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(y + Float64(x + t)) t_2 = Float64(Float64(Float64(Float64(Float64(x + y) * z) + Float64(Float64(y + t) * a)) - Float64(y * b)) / t_1) t_3 = Float64(Float64(z + a) - b) tmp = 0.0 if (t_2 <= Float64(-Inf)) tmp = t_3; elseif (t_2 <= 2.3121383245545765e+227) tmp = Float64(Float64(Float64(Float64(y * z) / t_1) + Float64(Float64(Float64(x * z) / t_1) + Float64(Float64(Float64(t * a) / t_1) + Float64(Float64(y * a) / t_1)))) - Float64(b * Float64(y / t_1))); else tmp = 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 = y + (x + t); t_2 = ((((x + y) * z) + ((y + t) * a)) - (y * b)) / t_1; t_3 = (z + a) - b; tmp = 0.0; if (t_2 <= -Inf) tmp = t_3; elseif (t_2 <= 2.3121383245545765e+227) tmp = (((y * z) / t_1) + (((x * z) / t_1) + (((t * a) / t_1) + ((y * a) / t_1)))) - (b * (y / t_1)); else tmp = 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[(y + N[(x + t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(N[(N[(x + y), $MachinePrecision] * z), $MachinePrecision] + N[(N[(y + t), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] - N[(y * b), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(N[(z + a), $MachinePrecision] - b), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], t$95$3, If[LessEqual[t$95$2, 2.3121383245545765e+227], N[(N[(N[(N[(y * z), $MachinePrecision] / t$95$1), $MachinePrecision] + N[(N[(N[(x * z), $MachinePrecision] / t$95$1), $MachinePrecision] + N[(N[(N[(t * a), $MachinePrecision] / t$95$1), $MachinePrecision] + N[(N[(y * a), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(b * N[(y / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$3]]]]]
\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(\left(x + y\right) \cdot z + \left(y + t\right) \cdot a\right) - y \cdot b}{t_1}\\
t_3 := \left(z + a\right) - b\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;t_3\\
\mathbf{elif}\;t_2 \leq 2.3121383245545765 \cdot 10^{+227}:\\
\;\;\;\;\left(\frac{y \cdot z}{t_1} + \left(\frac{x \cdot z}{t_1} + \left(\frac{t \cdot a}{t_1} + \frac{y \cdot a}{t_1}\right)\right)\right) - b \cdot \frac{y}{t_1}\\
\mathbf{else}:\\
\;\;\;\;t_3\\
\end{array}




Bits error versus x




Bits error versus y




Bits error versus z




Bits error versus t




Bits error versus a




Bits error versus b
Results
| Original | 26.6 |
|---|---|
| Target | 11.4 |
| Herbie | 8.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 2.3121383245545765e227 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) Initial program 61.2
Simplified61.2
Taylor expanded in y around inf 18.0
if -inf.0 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < 2.3121383245545765e227Initial program 0.3
Simplified0.3
Taylor expanded in a around 0 0.3
Applied egg-rr1.0
Taylor expanded in a around 0 1.0
Final simplification8.3
herbie shell --seed 2022133
(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)))