(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 t_1))
(t_3 (/ (- (+ (* (+ x y) z) (* (+ y t) a)) (* y b)) t_1))
(t_4
(+
(/ y (/ t_1 z))
(- (+ (* x (/ z t_1)) (+ (* t t_2) (* y t_2))) (* b (/ y t_1))))))
(if (<= t_3 -2e+141)
t_4
(if (<= t_3 5e+242)
(-
(+
(/ (* 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 = a / 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)) + ((t * t_2) + (y * t_2))) - (b * (y / t_1)));
double tmp;
if (t_3 <= -2e+141) {
tmp = t_4;
} else if (t_3 <= 5e+242) {
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 = a / t_1
t_3 = ((((x + y) * z) + ((y + t) * a)) - (y * b)) / t_1
t_4 = (y / (t_1 / z)) + (((x * (z / t_1)) + ((t * t_2) + (y * t_2))) - (b * (y / t_1)))
if (t_3 <= (-2d+141)) then
tmp = t_4
else if (t_3 <= 5d+242) 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 = a / 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)) + ((t * t_2) + (y * t_2))) - (b * (y / t_1)));
double tmp;
if (t_3 <= -2e+141) {
tmp = t_4;
} else if (t_3 <= 5e+242) {
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 = a / t_1 t_3 = ((((x + y) * z) + ((y + t) * a)) - (y * b)) / t_1 t_4 = (y / (t_1 / z)) + (((x * (z / t_1)) + ((t * t_2) + (y * t_2))) - (b * (y / t_1))) tmp = 0 if t_3 <= -2e+141: tmp = t_4 elif t_3 <= 5e+242: 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(a / 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(t * t_2) + Float64(y * t_2))) - Float64(b * Float64(y / t_1)))) tmp = 0.0 if (t_3 <= -2e+141) tmp = t_4; elseif (t_3 <= 5e+242) 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 = a / t_1; t_3 = ((((x + y) * z) + ((y + t) * a)) - (y * b)) / t_1; t_4 = (y / (t_1 / z)) + (((x * (z / t_1)) + ((t * t_2) + (y * t_2))) - (b * (y / t_1))); tmp = 0.0; if (t_3 <= -2e+141) tmp = t_4; elseif (t_3 <= 5e+242) 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[(a / 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[(t * t$95$2), $MachinePrecision] + N[(y * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(b * N[(y / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -2e+141], t$95$4, If[LessEqual[t$95$3, 5e+242], 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{a}{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(t \cdot t_2 + y \cdot t_2\right)\right) - b \cdot \frac{y}{t_1}\right)\\
\mathbf{if}\;t_3 \leq -2 \cdot 10^{+141}:\\
\;\;\;\;t_4\\
\mathbf{elif}\;t_3 \leq 5 \cdot 10^{+242}:\\
\;\;\;\;\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.9 |
|---|---|
| Target | 10.8 |
| Herbie | 1.6 |
if (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < -2.00000000000000003e141 or 5.0000000000000004e242 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) Initial program 53.5
Simplified53.5
Taylor expanded in a around 0 53.5
Simplified2.9
if -2.00000000000000003e141 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < 5.0000000000000004e242Initial program 0.3
Simplified0.3
Taylor expanded in a around 0 0.3
Final simplification1.6
herbie shell --seed 2022160
(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)))