(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_1))
(t_3 (/ (- (+ (* (+ x y) z) (* (+ y t) a)) (* y b)) t_1))
(t_4
(+
(/ y (/ t_1 z))
(- (+ (* x (/ z t_1)) (+ (/ a (/ t_1 t)) (* a t_2))) (* b t_2)))))
(if (<= t_3 -3.907548398565683e-11)
t_4
(if (<= t_3 4.669296356063465e+283)
(-
(+
(/ (* y z) t_1)
(+ (/ (* x z) t_1) (+ (/ (* t a) t_1) (/ (* y a) t_1))))
(/ (* y b) t_1))
t_4))))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_1;
double t_3 = ((((x + y) * z) + ((y + t) * a)) - (y * b)) / t_1;
double t_4 = (y / (t_1 / z)) + (((x * (z / t_1)) + ((a / (t_1 / t)) + (a * t_2))) - (b * t_2));
double tmp;
if (t_3 <= -3.907548398565683e-11) {
tmp = t_4;
} else if (t_3 <= 4.669296356063465e+283) {
tmp = (((y * z) / t_1) + (((x * z) / t_1) + (((t * a) / t_1) + ((y * a) / t_1)))) - ((y * b) / t_1);
} else {
tmp = t_4;
}
return tmp;
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y)
end function
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: t_4
real(8) :: tmp
t_1 = y + (x + t)
t_2 = y / t_1
t_3 = ((((x + y) * z) + ((y + t) * a)) - (y * b)) / t_1
t_4 = (y / (t_1 / z)) + (((x * (z / t_1)) + ((a / (t_1 / t)) + (a * t_2))) - (b * t_2))
if (t_3 <= (-3.907548398565683d-11)) then
tmp = t_4
else if (t_3 <= 4.669296356063465d+283) then
tmp = (((y * z) / t_1) + (((x * z) / t_1) + (((t * a) / t_1) + ((y * a) / t_1)))) - ((y * b) / t_1)
else
tmp = t_4
end if
code = tmp
end function
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 = y / t_1;
double t_3 = ((((x + y) * z) + ((y + t) * a)) - (y * b)) / t_1;
double t_4 = (y / (t_1 / z)) + (((x * (z / t_1)) + ((a / (t_1 / t)) + (a * t_2))) - (b * t_2));
double tmp;
if (t_3 <= -3.907548398565683e-11) {
tmp = t_4;
} else if (t_3 <= 4.669296356063465e+283) {
tmp = (((y * z) / t_1) + (((x * z) / t_1) + (((t * a) / t_1) + ((y * a) / t_1)))) - ((y * b) / t_1);
} else {
tmp = t_4;
}
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 = y / t_1 t_3 = ((((x + y) * z) + ((y + t) * a)) - (y * b)) / t_1 t_4 = (y / (t_1 / z)) + (((x * (z / t_1)) + ((a / (t_1 / t)) + (a * t_2))) - (b * t_2)) tmp = 0 if t_3 <= -3.907548398565683e-11: tmp = t_4 elif t_3 <= 4.669296356063465e+283: tmp = (((y * z) / t_1) + (((x * z) / t_1) + (((t * a) / t_1) + ((y * a) / t_1)))) - ((y * b) / t_1) else: tmp = t_4 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(y / t_1) t_3 = Float64(Float64(Float64(Float64(Float64(x + y) * z) + Float64(Float64(y + t) * a)) - Float64(y * b)) / t_1) t_4 = Float64(Float64(y / Float64(t_1 / z)) + Float64(Float64(Float64(x * Float64(z / t_1)) + Float64(Float64(a / Float64(t_1 / t)) + Float64(a * t_2))) - Float64(b * t_2))) tmp = 0.0 if (t_3 <= -3.907548398565683e-11) tmp = t_4; elseif (t_3 <= 4.669296356063465e+283) 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(Float64(y * b) / t_1)); else tmp = t_4; 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 = y / t_1; t_3 = ((((x + y) * z) + ((y + t) * a)) - (y * b)) / t_1; t_4 = (y / (t_1 / z)) + (((x * (z / t_1)) + ((a / (t_1 / t)) + (a * t_2))) - (b * t_2)); tmp = 0.0; if (t_3 <= -3.907548398565683e-11) tmp = t_4; elseif (t_3 <= 4.669296356063465e+283) tmp = (((y * z) / t_1) + (((x * z) / t_1) + (((t * a) / t_1) + ((y * a) / t_1)))) - ((y * b) / t_1); else tmp = t_4; 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[(y / t$95$1), $MachinePrecision]}, Block[{t$95$3 = 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$4 = N[(N[(y / N[(t$95$1 / z), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(x * N[(z / t$95$1), $MachinePrecision]), $MachinePrecision] + N[(N[(a / N[(t$95$1 / t), $MachinePrecision]), $MachinePrecision] + N[(a * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(b * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -3.907548398565683e-11], t$95$4, If[LessEqual[t$95$3, 4.669296356063465e+283], 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[(N[(y * b), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision], t$95$4]]]]]]
\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{y}{t_1}\\
t_3 := \frac{\left(\left(x + y\right) \cdot z + \left(y + t\right) \cdot a\right) - y \cdot b}{t_1}\\
t_4 := \frac{y}{\frac{t_1}{z}} + \left(\left(x \cdot \frac{z}{t_1} + \left(\frac{a}{\frac{t_1}{t}} + a \cdot t_2\right)\right) - b \cdot t_2\right)\\
\mathbf{if}\;t_3 \leq -3.907548398565683 \cdot 10^{-11}:\\
\;\;\;\;t_4\\
\mathbf{elif}\;t_3 \leq 4.669296356063465 \cdot 10^{+283}:\\
\;\;\;\;\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) - \frac{y \cdot b}{t_1}\\
\mathbf{else}:\\
\;\;\;\;t_4\\
\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.4 |
|---|---|
| Target | 11.3 |
| Herbie | 0.8 |
if (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < -3.907548398565683e-11 or 4.669296356063465e283 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) Initial program 44.6
Simplified44.6
Taylor expanded in a around 0 44.6
Simplified1.2
if -3.907548398565683e-11 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < 4.669296356063465e283Initial program 0.4
Simplified0.4
Taylor expanded in a around 0 0.4
Final simplification0.8
herbie shell --seed 2022146
(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)))