| Alternative 1 | |
|---|---|
| Accuracy | 88.3% |
| Cost | 2244 |

(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 (+ t x))) (t_2 (/ (+ y x) (/ t_1 z))))
(if (<= t -1.05e+28)
(- (+ t_2 (/ (+ t y) (/ t_1 a))) (/ (* y b) t_1))
(if (<= t 128000000.0)
(+ z (+ (/ (* t a) t_1) (* (/ y t_1) (- a b))))
(+ t_2 (+ a (/ y (/ t_1 (- a b)))))))))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 + (t + x);
double t_2 = (y + x) / (t_1 / z);
double tmp;
if (t <= -1.05e+28) {
tmp = (t_2 + ((t + y) / (t_1 / a))) - ((y * b) / t_1);
} else if (t <= 128000000.0) {
tmp = z + (((t * a) / t_1) + ((y / t_1) * (a - b)));
} else {
tmp = t_2 + (a + (y / (t_1 / (a - b))));
}
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) :: tmp
t_1 = y + (t + x)
t_2 = (y + x) / (t_1 / z)
if (t <= (-1.05d+28)) then
tmp = (t_2 + ((t + y) / (t_1 / a))) - ((y * b) / t_1)
else if (t <= 128000000.0d0) then
tmp = z + (((t * a) / t_1) + ((y / t_1) * (a - b)))
else
tmp = t_2 + (a + (y / (t_1 / (a - b))))
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 + (t + x);
double t_2 = (y + x) / (t_1 / z);
double tmp;
if (t <= -1.05e+28) {
tmp = (t_2 + ((t + y) / (t_1 / a))) - ((y * b) / t_1);
} else if (t <= 128000000.0) {
tmp = z + (((t * a) / t_1) + ((y / t_1) * (a - b)));
} else {
tmp = t_2 + (a + (y / (t_1 / (a - b))));
}
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 + (t + x) t_2 = (y + x) / (t_1 / z) tmp = 0 if t <= -1.05e+28: tmp = (t_2 + ((t + y) / (t_1 / a))) - ((y * b) / t_1) elif t <= 128000000.0: tmp = z + (((t * a) / t_1) + ((y / t_1) * (a - b))) else: tmp = t_2 + (a + (y / (t_1 / (a - b)))) 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(t + x)) t_2 = Float64(Float64(y + x) / Float64(t_1 / z)) tmp = 0.0 if (t <= -1.05e+28) tmp = Float64(Float64(t_2 + Float64(Float64(t + y) / Float64(t_1 / a))) - Float64(Float64(y * b) / t_1)); elseif (t <= 128000000.0) tmp = Float64(z + Float64(Float64(Float64(t * a) / t_1) + Float64(Float64(y / t_1) * Float64(a - b)))); else tmp = Float64(t_2 + Float64(a + Float64(y / Float64(t_1 / Float64(a - b))))); 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 + (t + x); t_2 = (y + x) / (t_1 / z); tmp = 0.0; if (t <= -1.05e+28) tmp = (t_2 + ((t + y) / (t_1 / a))) - ((y * b) / t_1); elseif (t <= 128000000.0) tmp = z + (((t * a) / t_1) + ((y / t_1) * (a - b))); else tmp = t_2 + (a + (y / (t_1 / (a - b)))); 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[(t + x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(y + x), $MachinePrecision] / N[(t$95$1 / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t, -1.05e+28], N[(N[(t$95$2 + N[(N[(t + y), $MachinePrecision] / N[(t$95$1 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(y * b), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 128000000.0], N[(z + N[(N[(N[(t * a), $MachinePrecision] / t$95$1), $MachinePrecision] + N[(N[(y / t$95$1), $MachinePrecision] * N[(a - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$2 + N[(a + N[(y / N[(t$95$1 / N[(a - b), $MachinePrecision]), $MachinePrecision]), $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(t + x\right)\\
t_2 := \frac{y + x}{\frac{t_1}{z}}\\
\mathbf{if}\;t \leq -1.05 \cdot 10^{+28}:\\
\;\;\;\;\left(t_2 + \frac{t + y}{\frac{t_1}{a}}\right) - \frac{y \cdot b}{t_1}\\
\mathbf{elif}\;t \leq 128000000:\\
\;\;\;\;z + \left(\frac{t \cdot a}{t_1} + \frac{y}{t_1} \cdot \left(a - b\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t_2 + \left(a + \frac{y}{\frac{t_1}{a - b}}\right)\\
\end{array}
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 60.4% |
|---|---|
| Target | 82.4% |
| Herbie | 88.3% |
if t < -1.04999999999999995e28Initial program 40.8%
Simplified41.2%
[Start]40.8% | \[ \frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}
\] |
|---|---|
*-commutative [=>]40.8% | \[ \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 [=>]40.3% | \[ \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+ [=>]40.3% | \[ \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+ [=>]40.3% | \[ \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 [=>]40.3% | \[ \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 [=>]40.3% | \[ \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-- [=>]40.5% | \[ \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 [=>]41.0% | \[ \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 [<=]41.0% | \[ \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 [=>]41.2% | \[ \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+ [=>]41.2% | \[ \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 [=>]41.2% | \[ \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 40.8%
Simplified77.8%
[Start]40.8% | \[ \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+ [=>]40.8% | \[ \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 [=>]40.8% | \[ \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 [=>]40.8% | \[ \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)}}
\] |
if -1.04999999999999995e28 < t < 1.28e8Initial program 61.3%
Simplified61.6%
[Start]61.3% | \[ \frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}
\] |
|---|---|
*-commutative [=>]61.3% | \[ \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 [=>]61.3% | \[ \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+ [=>]61.3% | \[ \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+ [=>]61.3% | \[ \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 [=>]61.3% | \[ \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 [=>]61.3% | \[ \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-- [=>]61.5% | \[ \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 [=>]61.6% | \[ \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 [<=]61.6% | \[ \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 [=>]61.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+ [=>]61.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 [=>]61.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 z around inf 61.5%
Simplified87.2%
[Start]61.5% | \[ \frac{\left(y + x\right) \cdot z}{y + \left(t + x\right)} + \left(\frac{y \cdot \left(a - b\right)}{y + \left(t + x\right)} + \frac{a \cdot t}{y + \left(t + x\right)}\right)
\] |
|---|---|
associate-/l* [=>]64.9% | \[ \color{blue}{\frac{y + x}{\frac{y + \left(t + x\right)}{z}}} + \left(\frac{y \cdot \left(a - b\right)}{y + \left(t + x\right)} + \frac{a \cdot t}{y + \left(t + x\right)}\right)
\] |
+-commutative [=>]64.9% | \[ \frac{y + x}{\frac{y + \left(t + x\right)}{z}} + \color{blue}{\left(\frac{a \cdot t}{y + \left(t + x\right)} + \frac{y \cdot \left(a - b\right)}{y + \left(t + x\right)}\right)}
\] |
associate-/l* [=>]87.2% | \[ \frac{y + x}{\frac{y + \left(t + x\right)}{z}} + \left(\frac{a \cdot t}{y + \left(t + x\right)} + \color{blue}{\frac{y}{\frac{y + \left(t + x\right)}{a - b}}}\right)
\] |
Applied egg-rr90.4%
[Start]87.2% | \[ \frac{y + x}{\frac{y + \left(t + x\right)}{z}} + \left(\frac{a \cdot t}{y + \left(t + x\right)} + \frac{y}{\frac{y + \left(t + x\right)}{a - b}}\right)
\] |
|---|---|
associate-/r/ [=>]90.4% | \[ \frac{y + x}{\frac{y + \left(t + x\right)}{z}} + \left(\frac{a \cdot t}{y + \left(t + x\right)} + \color{blue}{\frac{y}{y + \left(t + x\right)} \cdot \left(a - b\right)}\right)
\] |
+-commutative [<=]90.4% | \[ \frac{y + x}{\frac{y + \left(t + x\right)}{z}} + \left(\frac{a \cdot t}{y + \left(t + x\right)} + \frac{y}{y + \color{blue}{\left(x + t\right)}} \cdot \left(a - b\right)\right)
\] |
Taylor expanded in y around inf 97.8%
if 1.28e8 < t Initial program 58.2%
Simplified58.2%
[Start]58.2% | \[ \frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}
\] |
|---|---|
*-commutative [=>]58.2% | \[ \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 [=>]58.2% | \[ \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+ [=>]58.2% | \[ \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+ [=>]58.2% | \[ \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 [=>]58.2% | \[ \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 [=>]58.2% | \[ \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-- [=>]58.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 [=>]58.2% | \[ \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 [<=]58.2% | \[ \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 [=>]58.2% | \[ \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+ [=>]58.2% | \[ \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 [=>]58.2% | \[ \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 z around inf 58.2%
Simplified73.7%
[Start]58.2% | \[ \frac{\left(y + x\right) \cdot z}{y + \left(t + x\right)} + \left(\frac{y \cdot \left(a - b\right)}{y + \left(t + x\right)} + \frac{a \cdot t}{y + \left(t + x\right)}\right)
\] |
|---|---|
associate-/l* [=>]67.5% | \[ \color{blue}{\frac{y + x}{\frac{y + \left(t + x\right)}{z}}} + \left(\frac{y \cdot \left(a - b\right)}{y + \left(t + x\right)} + \frac{a \cdot t}{y + \left(t + x\right)}\right)
\] |
+-commutative [=>]67.5% | \[ \frac{y + x}{\frac{y + \left(t + x\right)}{z}} + \color{blue}{\left(\frac{a \cdot t}{y + \left(t + x\right)} + \frac{y \cdot \left(a - b\right)}{y + \left(t + x\right)}\right)}
\] |
associate-/l* [=>]73.7% | \[ \frac{y + x}{\frac{y + \left(t + x\right)}{z}} + \left(\frac{a \cdot t}{y + \left(t + x\right)} + \color{blue}{\frac{y}{\frac{y + \left(t + x\right)}{a - b}}}\right)
\] |
Taylor expanded in t around inf 96.4%
Final simplification93.7%
| Alternative 1 | |
|---|---|
| Accuracy | 88.3% |
| Cost | 2244 |
| Alternative 2 | |
|---|---|
| Accuracy | 87.9% |
| Cost | 4169 |
| Alternative 3 | |
|---|---|
| Accuracy | 89.7% |
| Cost | 1865 |
| Alternative 4 | |
|---|---|
| Accuracy | 80.4% |
| Cost | 1736 |
| Alternative 5 | |
|---|---|
| Accuracy | 64.2% |
| Cost | 969 |
| Alternative 6 | |
|---|---|
| Accuracy | 59.6% |
| Cost | 585 |
| Alternative 7 | |
|---|---|
| Accuracy | 52.1% |
| Cost | 456 |
| Alternative 8 | |
|---|---|
| Accuracy | 44.7% |
| Cost | 328 |
| Alternative 9 | |
|---|---|
| Accuracy | 52.3% |
| Cost | 324 |
| Alternative 10 | |
|---|---|
| Accuracy | 51.7% |
| Cost | 324 |
| Alternative 11 | |
|---|---|
| Accuracy | 33.2% |
| Cost | 64 |
herbie shell --seed 2023165
(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)))