| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 7232 |
\[\mathsf{fma}\left(\left(1 + \frac{1}{z}\right) - t, \frac{2}{t}, \frac{x}{y}\right)
\]

(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 (fma (- (+ 1.0 (/ 1.0 z)) t) (/ 2.0 t) (/ x y)))
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) {
return fma(((1.0 + (1.0 / z)) - t), (2.0 / t), (x / y));
}
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) return fma(Float64(Float64(1.0 + Float64(1.0 / z)) - t), Float64(2.0 / t), Float64(x / y)) 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_] := N[(N[(N[(1.0 + N[(1.0 / z), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision] * N[(2.0 / t), $MachinePrecision] + N[(x / y), $MachinePrecision]), $MachinePrecision]
\frac{x}{y} + \frac{2 + \left(z \cdot 2\right) \cdot \left(1 - t\right)}{t \cdot z}
\mathsf{fma}\left(\left(1 + \frac{1}{z}\right) - t, \frac{2}{t}, \frac{x}{y}\right)
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 86.1% |
|---|---|
| Target | 98.9% |
| Herbie | 99.3% |
Initial program 84.6%
Simplified86.8%
[Start]84.6% | \[ \frac{x}{y} + \frac{2 + \left(z \cdot 2\right) \cdot \left(1 - t\right)}{t \cdot z}
\] |
|---|---|
+-commutative [=>]84.6% | \[ \color{blue}{\frac{2 + \left(z \cdot 2\right) \cdot \left(1 - t\right)}{t \cdot z} + \frac{x}{y}}
\] |
*-commutative [=>]84.6% | \[ \frac{2 + \color{blue}{\left(1 - t\right) \cdot \left(z \cdot 2\right)}}{t \cdot z} + \frac{x}{y}
\] |
associate-*r* [=>]84.6% | \[ \frac{2 + \color{blue}{\left(\left(1 - t\right) \cdot z\right) \cdot 2}}{t \cdot z} + \frac{x}{y}
\] |
distribute-rgt1-in [=>]84.6% | \[ \frac{\color{blue}{\left(\left(1 - t\right) \cdot z + 1\right) \cdot 2}}{t \cdot z} + \frac{x}{y}
\] |
*-commutative [=>]84.6% | \[ \frac{\left(\left(1 - t\right) \cdot z + 1\right) \cdot 2}{\color{blue}{z \cdot t}} + \frac{x}{y}
\] |
times-frac [=>]86.0% | \[ \color{blue}{\frac{\left(1 - t\right) \cdot z + 1}{z} \cdot \frac{2}{t}} + \frac{x}{y}
\] |
fma-def [=>]86.8% | \[ \color{blue}{\mathsf{fma}\left(\frac{\left(1 - t\right) \cdot z + 1}{z}, \frac{2}{t}, \frac{x}{y}\right)}
\] |
*-commutative [<=]86.8% | \[ \mathsf{fma}\left(\frac{\color{blue}{z \cdot \left(1 - t\right)} + 1}{z}, \frac{2}{t}, \frac{x}{y}\right)
\] |
fma-def [=>]86.8% | \[ \mathsf{fma}\left(\frac{\color{blue}{\mathsf{fma}\left(z, 1 - t, 1\right)}}{z}, \frac{2}{t}, \frac{x}{y}\right)
\] |
Taylor expanded in z around 0 99.5%
Final simplification99.5%
| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 7232 |
| Alternative 2 | |
|---|---|
| Accuracy | 64.1% |
| Cost | 1620 |
| Alternative 3 | |
|---|---|
| Accuracy | 64.0% |
| Cost | 1620 |
| Alternative 4 | |
|---|---|
| Accuracy | 69.0% |
| Cost | 1240 |
| Alternative 5 | |
|---|---|
| Accuracy | 88.7% |
| Cost | 1225 |
| Alternative 6 | |
|---|---|
| Accuracy | 80.2% |
| Cost | 976 |
| Alternative 7 | |
|---|---|
| Accuracy | 80.2% |
| Cost | 976 |
| Alternative 8 | |
|---|---|
| Accuracy | 50.5% |
| Cost | 972 |
| Alternative 9 | |
|---|---|
| Accuracy | 82.0% |
| Cost | 841 |
| Alternative 10 | |
|---|---|
| Accuracy | 63.5% |
| Cost | 840 |
| Alternative 11 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 832 |
| Alternative 12 | |
|---|---|
| Accuracy | 36.2% |
| Cost | 456 |
| Alternative 13 | |
|---|---|
| Accuracy | 20.4% |
| Cost | 64 |
herbie shell --seed 2023165
(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))))