| Alternative 1 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 1988 |

(FPCore (x y z t) :precision binary64 (+ (/ x y) (/ (+ 2.0 (* (* z 2.0) (- 1.0 t))) (* t z))))
(FPCore (x y z t) :precision binary64 (if (<= (+ (/ x y) (/ (+ 2.0 (* (* 2.0 z) (- 1.0 t))) (* z t))) INFINITY) (+ (/ x y) (+ -2.0 (/ (+ 2.0 (/ 2.0 z)) t))) (- (/ x y) 2.0)))
double code(double x, double y, double z, double t) {
return (x / y) + ((2.0 + ((z * 2.0) * (1.0 - t))) / (t * z));
}
double code(double x, double y, double z, double t) {
double tmp;
if (((x / y) + ((2.0 + ((2.0 * z) * (1.0 - t))) / (z * t))) <= ((double) INFINITY)) {
tmp = (x / y) + (-2.0 + ((2.0 + (2.0 / z)) / t));
} else {
tmp = (x / y) - 2.0;
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
return (x / y) + ((2.0 + ((z * 2.0) * (1.0 - t))) / (t * z));
}
public static double code(double x, double y, double z, double t) {
double tmp;
if (((x / y) + ((2.0 + ((2.0 * z) * (1.0 - t))) / (z * t))) <= Double.POSITIVE_INFINITY) {
tmp = (x / y) + (-2.0 + ((2.0 + (2.0 / z)) / t));
} else {
tmp = (x / y) - 2.0;
}
return tmp;
}
def code(x, y, z, t): return (x / y) + ((2.0 + ((z * 2.0) * (1.0 - t))) / (t * z))
def code(x, y, z, t): tmp = 0 if ((x / y) + ((2.0 + ((2.0 * z) * (1.0 - t))) / (z * t))) <= math.inf: tmp = (x / y) + (-2.0 + ((2.0 + (2.0 / z)) / t)) else: tmp = (x / y) - 2.0 return tmp
function code(x, y, z, t) return Float64(Float64(x / y) + Float64(Float64(2.0 + Float64(Float64(z * 2.0) * Float64(1.0 - t))) / Float64(t * z))) end
function code(x, y, z, t) tmp = 0.0 if (Float64(Float64(x / y) + Float64(Float64(2.0 + Float64(Float64(2.0 * z) * Float64(1.0 - t))) / Float64(z * t))) <= Inf) tmp = Float64(Float64(x / y) + Float64(-2.0 + Float64(Float64(2.0 + Float64(2.0 / z)) / t))); else tmp = Float64(Float64(x / y) - 2.0); end return tmp end
function tmp = code(x, y, z, t) tmp = (x / y) + ((2.0 + ((z * 2.0) * (1.0 - t))) / (t * z)); end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (((x / y) + ((2.0 + ((2.0 * z) * (1.0 - t))) / (z * t))) <= Inf) tmp = (x / y) + (-2.0 + ((2.0 + (2.0 / z)) / t)); else tmp = (x / y) - 2.0; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := N[(N[(x / y), $MachinePrecision] + N[(N[(2.0 + N[(N[(z * 2.0), $MachinePrecision] * N[(1.0 - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(x / y), $MachinePrecision] + N[(N[(2.0 + N[(N[(2.0 * z), $MachinePrecision] * N[(1.0 - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(x / y), $MachinePrecision] + N[(-2.0 + N[(N[(2.0 + N[(2.0 / z), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x / y), $MachinePrecision] - 2.0), $MachinePrecision]]
\frac{x}{y} + \frac{2 + \left(z \cdot 2\right) \cdot \left(1 - t\right)}{t \cdot z}
\begin{array}{l}
\mathbf{if}\;\frac{x}{y} + \frac{2 + \left(2 \cdot z\right) \cdot \left(1 - t\right)}{z \cdot t} \leq \infty:\\
\;\;\;\;\frac{x}{y} + \left(-2 + \frac{2 + \frac{2}{z}}{t}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y} - 2\\
\end{array}
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 86.2% |
|---|---|
| Target | 99.3% |
| Herbie | 99.6% |
if (+.f64 (/.f64 x y) (/.f64 (+.f64 2 (*.f64 (*.f64 z 2) (-.f64 1 t))) (*.f64 t z))) < +inf.0Initial program 99.9%
Simplified99.9%
[Start]99.9% | \[ \frac{x}{y} + \frac{2 + \left(z \cdot 2\right) \cdot \left(1 - t\right)}{t \cdot z}
\] |
|---|---|
sub-neg [=>]99.9% | \[ \frac{x}{y} + \frac{2 + \left(z \cdot 2\right) \cdot \color{blue}{\left(1 + \left(-t\right)\right)}}{t \cdot z}
\] |
distribute-rgt-in [=>]99.9% | \[ \frac{x}{y} + \frac{2 + \color{blue}{\left(1 \cdot \left(z \cdot 2\right) + \left(-t\right) \cdot \left(z \cdot 2\right)\right)}}{t \cdot z}
\] |
*-lft-identity [=>]99.9% | \[ \frac{x}{y} + \frac{2 + \left(\color{blue}{z \cdot 2} + \left(-t\right) \cdot \left(z \cdot 2\right)\right)}{t \cdot z}
\] |
associate-+r+ [=>]99.9% | \[ \frac{x}{y} + \frac{\color{blue}{\left(2 + z \cdot 2\right) + \left(-t\right) \cdot \left(z \cdot 2\right)}}{t \cdot z}
\] |
cancel-sign-sub-inv [<=]99.9% | \[ \frac{x}{y} + \frac{\color{blue}{\left(2 + z \cdot 2\right) - t \cdot \left(z \cdot 2\right)}}{t \cdot z}
\] |
div-sub [=>]87.0% | \[ \frac{x}{y} + \color{blue}{\left(\frac{2 + z \cdot 2}{t \cdot z} - \frac{t \cdot \left(z \cdot 2\right)}{t \cdot z}\right)}
\] |
associate-*r* [=>]87.0% | \[ \frac{x}{y} + \left(\frac{2 + z \cdot 2}{t \cdot z} - \frac{\color{blue}{\left(t \cdot z\right) \cdot 2}}{t \cdot z}\right)
\] |
associate-*l/ [<=]87.0% | \[ \frac{x}{y} + \left(\frac{2 + z \cdot 2}{t \cdot z} - \color{blue}{\frac{t \cdot z}{t \cdot z} \cdot 2}\right)
\] |
*-inverses [=>]99.9% | \[ \frac{x}{y} + \left(\frac{2 + z \cdot 2}{t \cdot z} - \color{blue}{1} \cdot 2\right)
\] |
metadata-eval [=>]99.9% | \[ \frac{x}{y} + \left(\frac{2 + z \cdot 2}{t \cdot z} - \color{blue}{2}\right)
\] |
sub-neg [=>]99.9% | \[ \frac{x}{y} + \color{blue}{\left(\frac{2 + z \cdot 2}{t \cdot z} + \left(-2\right)\right)}
\] |
metadata-eval [=>]99.9% | \[ \frac{x}{y} + \left(\frac{2 + z \cdot 2}{t \cdot z} + \color{blue}{-2}\right)
\] |
metadata-eval [<=]99.9% | \[ \frac{x}{y} + \left(\frac{2 + z \cdot 2}{t \cdot z} + \color{blue}{2 \cdot -1}\right)
\] |
+-commutative [<=]99.9% | \[ \frac{x}{y} + \color{blue}{\left(2 \cdot -1 + \frac{2 + z \cdot 2}{t \cdot z}\right)}
\] |
metadata-eval [=>]99.9% | \[ \frac{x}{y} + \left(\color{blue}{-2} + \frac{2 + z \cdot 2}{t \cdot z}\right)
\] |
associate-/l/ [<=]99.9% | \[ \frac{x}{y} + \left(-2 + \color{blue}{\frac{\frac{2 + z \cdot 2}{z}}{t}}\right)
\] |
if +inf.0 < (+.f64 (/.f64 x y) (/.f64 (+.f64 2 (*.f64 (*.f64 z 2) (-.f64 1 t))) (*.f64 t z))) Initial program 0.0%
Simplified84.6%
[Start]0.0% | \[ \frac{x}{y} + \frac{2 + \left(z \cdot 2\right) \cdot \left(1 - t\right)}{t \cdot z}
\] |
|---|---|
sub-neg [=>]0.0% | \[ \frac{x}{y} + \frac{2 + \left(z \cdot 2\right) \cdot \color{blue}{\left(1 + \left(-t\right)\right)}}{t \cdot z}
\] |
distribute-rgt-in [=>]0.0% | \[ \frac{x}{y} + \frac{2 + \color{blue}{\left(1 \cdot \left(z \cdot 2\right) + \left(-t\right) \cdot \left(z \cdot 2\right)\right)}}{t \cdot z}
\] |
*-lft-identity [=>]0.0% | \[ \frac{x}{y} + \frac{2 + \left(\color{blue}{z \cdot 2} + \left(-t\right) \cdot \left(z \cdot 2\right)\right)}{t \cdot z}
\] |
associate-+r+ [=>]0.0% | \[ \frac{x}{y} + \frac{\color{blue}{\left(2 + z \cdot 2\right) + \left(-t\right) \cdot \left(z \cdot 2\right)}}{t \cdot z}
\] |
cancel-sign-sub-inv [<=]0.0% | \[ \frac{x}{y} + \frac{\color{blue}{\left(2 + z \cdot 2\right) - t \cdot \left(z \cdot 2\right)}}{t \cdot z}
\] |
div-sub [=>]0.0% | \[ \frac{x}{y} + \color{blue}{\left(\frac{2 + z \cdot 2}{t \cdot z} - \frac{t \cdot \left(z \cdot 2\right)}{t \cdot z}\right)}
\] |
associate-*r* [=>]0.0% | \[ \frac{x}{y} + \left(\frac{2 + z \cdot 2}{t \cdot z} - \frac{\color{blue}{\left(t \cdot z\right) \cdot 2}}{t \cdot z}\right)
\] |
associate-*l/ [<=]0.0% | \[ \frac{x}{y} + \left(\frac{2 + z \cdot 2}{t \cdot z} - \color{blue}{\frac{t \cdot z}{t \cdot z} \cdot 2}\right)
\] |
*-inverses [=>]84.6% | \[ \frac{x}{y} + \left(\frac{2 + z \cdot 2}{t \cdot z} - \color{blue}{1} \cdot 2\right)
\] |
metadata-eval [=>]84.6% | \[ \frac{x}{y} + \left(\frac{2 + z \cdot 2}{t \cdot z} - \color{blue}{2}\right)
\] |
sub-neg [=>]84.6% | \[ \frac{x}{y} + \color{blue}{\left(\frac{2 + z \cdot 2}{t \cdot z} + \left(-2\right)\right)}
\] |
metadata-eval [=>]84.6% | \[ \frac{x}{y} + \left(\frac{2 + z \cdot 2}{t \cdot z} + \color{blue}{-2}\right)
\] |
metadata-eval [<=]84.6% | \[ \frac{x}{y} + \left(\frac{2 + z \cdot 2}{t \cdot z} + \color{blue}{2 \cdot -1}\right)
\] |
+-commutative [<=]84.6% | \[ \frac{x}{y} + \color{blue}{\left(2 \cdot -1 + \frac{2 + z \cdot 2}{t \cdot z}\right)}
\] |
metadata-eval [=>]84.6% | \[ \frac{x}{y} + \left(\color{blue}{-2} + \frac{2 + z \cdot 2}{t \cdot z}\right)
\] |
associate-/l/ [<=]84.6% | \[ \frac{x}{y} + \left(-2 + \color{blue}{\frac{\frac{2 + z \cdot 2}{z}}{t}}\right)
\] |
Taylor expanded in t around inf 97.4%
Final simplification99.5%
| Alternative 1 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 1988 |
| Alternative 2 | |
|---|---|
| Accuracy | 88.4% |
| Cost | 1225 |
| Alternative 3 | |
|---|---|
| Accuracy | 61.8% |
| Cost | 1114 |
| Alternative 4 | |
|---|---|
| Accuracy | 61.7% |
| Cost | 1113 |
| Alternative 5 | |
|---|---|
| Accuracy | 80.5% |
| Cost | 1105 |
| Alternative 6 | |
|---|---|
| Accuracy | 79.6% |
| Cost | 976 |
| Alternative 7 | |
|---|---|
| Accuracy | 51.4% |
| Cost | 972 |
| Alternative 8 | |
|---|---|
| Accuracy | 85.0% |
| Cost | 841 |
| Alternative 9 | |
|---|---|
| Accuracy | 64.1% |
| Cost | 840 |
| Alternative 10 | |
|---|---|
| Accuracy | 64.3% |
| Cost | 840 |
| Alternative 11 | |
|---|---|
| Accuracy | 37.5% |
| Cost | 456 |
| Alternative 12 | |
|---|---|
| Accuracy | 20.1% |
| Cost | 64 |
herbie shell --seed 2023263
(FPCore (x y z t)
:name "Data.HashTable.ST.Basic:computeOverhead from hashtables-1.2.0.2"
:precision binary64
:herbie-target
(- (/ (+ (/ 2.0 z) 2.0) t) (- 2.0 (/ x y)))
(+ (/ x y) (/ (+ 2.0 (* (* z 2.0) (- 1.0 t))) (* t z))))