| Alternative 1 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 7492 |

(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
(FPCore (x y z) :precision binary64 (if (<= (* x (- 1.0 (* (- 1.0 y) z))) 100000.0) (- x (* z (* x (- 1.0 y)))) (fma (+ y -1.0) (* x z) x)))
double code(double x, double y, double z) {
return x * (1.0 - ((1.0 - y) * z));
}
double code(double x, double y, double z) {
double tmp;
if ((x * (1.0 - ((1.0 - y) * z))) <= 100000.0) {
tmp = x - (z * (x * (1.0 - y)));
} else {
tmp = fma((y + -1.0), (x * z), x);
}
return tmp;
}
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(Float64(1.0 - y) * z))) end
function code(x, y, z) tmp = 0.0 if (Float64(x * Float64(1.0 - Float64(Float64(1.0 - y) * z))) <= 100000.0) tmp = Float64(x - Float64(z * Float64(x * Float64(1.0 - y)))); else tmp = fma(Float64(y + -1.0), Float64(x * z), x); end return tmp end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[N[(x * N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 100000.0], N[(x - N[(z * N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y + -1.0), $MachinePrecision] * N[(x * z), $MachinePrecision] + x), $MachinePrecision]]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \leq 100000:\\
\;\;\;\;x - z \cdot \left(x \cdot \left(1 - y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y + -1, x \cdot z, x\right)\\
\end{array}
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 96.2% |
|---|---|
| Target | 99.8% |
| Herbie | 97.7% |
if (*.f64 x (-.f64 1 (*.f64 (-.f64 1 y) z))) < 1e5Initial program 97.0%
Simplified97.0%
[Start]97.0% | \[ x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\] |
|---|---|
sub-neg [=>]97.0% | \[ x \cdot \color{blue}{\left(1 + \left(-\left(1 - y\right) \cdot z\right)\right)}
\] |
+-commutative [=>]97.0% | \[ x \cdot \color{blue}{\left(\left(-\left(1 - y\right) \cdot z\right) + 1\right)}
\] |
distribute-rgt-neg-in [=>]97.0% | \[ x \cdot \left(\color{blue}{\left(1 - y\right) \cdot \left(-z\right)} + 1\right)
\] |
sub-neg [=>]97.0% | \[ x \cdot \left(\color{blue}{\left(1 + \left(-y\right)\right)} \cdot \left(-z\right) + 1\right)
\] |
+-commutative [=>]97.0% | \[ x \cdot \left(\color{blue}{\left(\left(-y\right) + 1\right)} \cdot \left(-z\right) + 1\right)
\] |
distribute-rgt1-in [<=]97.0% | \[ x \cdot \left(\color{blue}{\left(\left(-z\right) + \left(-y\right) \cdot \left(-z\right)\right)} + 1\right)
\] |
distribute-rgt-neg-in [<=]97.0% | \[ x \cdot \left(\left(\left(-z\right) + \color{blue}{\left(-\left(-y\right) \cdot z\right)}\right) + 1\right)
\] |
associate-+l+ [=>]97.0% | \[ x \cdot \color{blue}{\left(\left(-z\right) + \left(\left(-\left(-y\right) \cdot z\right) + 1\right)\right)}
\] |
associate-+l+ [<=]97.0% | \[ x \cdot \color{blue}{\left(\left(\left(-z\right) + \left(-\left(-y\right) \cdot z\right)\right) + 1\right)}
\] |
distribute-rgt-neg-in [=>]97.0% | \[ x \cdot \left(\left(\left(-z\right) + \color{blue}{\left(-y\right) \cdot \left(-z\right)}\right) + 1\right)
\] |
distribute-rgt1-in [=>]97.0% | \[ x \cdot \left(\color{blue}{\left(\left(-y\right) + 1\right) \cdot \left(-z\right)} + 1\right)
\] |
+-commutative [<=]97.0% | \[ x \cdot \left(\color{blue}{\left(1 + \left(-y\right)\right)} \cdot \left(-z\right) + 1\right)
\] |
sub-neg [<=]97.0% | \[ x \cdot \left(\color{blue}{\left(1 - y\right)} \cdot \left(-z\right) + 1\right)
\] |
distribute-rgt-neg-in [<=]97.0% | \[ x \cdot \left(\color{blue}{\left(-\left(1 - y\right) \cdot z\right)} + 1\right)
\] |
*-commutative [=>]97.0% | \[ x \cdot \left(\left(-\color{blue}{z \cdot \left(1 - y\right)}\right) + 1\right)
\] |
distribute-rgt-neg-in [=>]97.0% | \[ x \cdot \left(\color{blue}{z \cdot \left(-\left(1 - y\right)\right)} + 1\right)
\] |
fma-def [=>]97.0% | \[ x \cdot \color{blue}{\mathsf{fma}\left(z, -\left(1 - y\right), 1\right)}
\] |
Applied egg-rr99.9%
[Start]97.0% | \[ x \cdot \mathsf{fma}\left(z, y + -1, 1\right)
\] |
|---|---|
fma-udef [=>]97.0% | \[ x \cdot \color{blue}{\left(z \cdot \left(y + -1\right) + 1\right)}
\] |
distribute-rgt-in [=>]97.0% | \[ \color{blue}{\left(z \cdot \left(y + -1\right)\right) \cdot x + 1 \cdot x}
\] |
*-commutative [=>]97.0% | \[ \color{blue}{\left(\left(y + -1\right) \cdot z\right)} \cdot x + 1 \cdot x
\] |
associate-*r* [<=]96.5% | \[ \color{blue}{\left(y + -1\right) \cdot \left(z \cdot x\right)} + 1 \cdot x
\] |
*-commutative [<=]96.5% | \[ \left(y + -1\right) \cdot \color{blue}{\left(x \cdot z\right)} + 1 \cdot x
\] |
associate-*r* [=>]99.9% | \[ \color{blue}{\left(\left(y + -1\right) \cdot x\right) \cdot z} + 1 \cdot x
\] |
*-un-lft-identity [<=]99.9% | \[ \left(\left(y + -1\right) \cdot x\right) \cdot z + \color{blue}{x}
\] |
if 1e5 < (*.f64 x (-.f64 1 (*.f64 (-.f64 1 y) z))) Initial program 94.7%
Simplified99.8%
[Start]94.7% | \[ x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\] |
|---|---|
distribute-rgt-out-- [<=]94.6% | \[ \color{blue}{1 \cdot x - \left(\left(1 - y\right) \cdot z\right) \cdot x}
\] |
*-lft-identity [=>]94.6% | \[ \color{blue}{x} - \left(\left(1 - y\right) \cdot z\right) \cdot x
\] |
cancel-sign-sub-inv [=>]94.6% | \[ \color{blue}{x + \left(-\left(1 - y\right) \cdot z\right) \cdot x}
\] |
+-commutative [=>]94.6% | \[ \color{blue}{\left(-\left(1 - y\right) \cdot z\right) \cdot x + x}
\] |
distribute-lft-neg-in [=>]94.6% | \[ \color{blue}{\left(\left(-\left(1 - y\right)\right) \cdot z\right)} \cdot x + x
\] |
associate-*l* [=>]99.8% | \[ \color{blue}{\left(-\left(1 - y\right)\right) \cdot \left(z \cdot x\right)} + x
\] |
fma-def [=>]99.8% | \[ \color{blue}{\mathsf{fma}\left(-\left(1 - y\right), z \cdot x, x\right)}
\] |
neg-sub0 [=>]99.8% | \[ \mathsf{fma}\left(\color{blue}{0 - \left(1 - y\right)}, z \cdot x, x\right)
\] |
associate--r- [=>]99.8% | \[ \mathsf{fma}\left(\color{blue}{\left(0 - 1\right) + y}, z \cdot x, x\right)
\] |
metadata-eval [=>]99.8% | \[ \mathsf{fma}\left(\color{blue}{-1} + y, z \cdot x, x\right)
\] |
+-commutative [=>]99.8% | \[ \mathsf{fma}\left(\color{blue}{y + -1}, z \cdot x, x\right)
\] |
*-commutative [<=]99.8% | \[ \mathsf{fma}\left(y + -1, \color{blue}{x \cdot z}, x\right)
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 7492 |
| Alternative 2 | |
|---|---|
| Accuracy | 96.0% |
| Cost | 836 |
| Alternative 3 | |
|---|---|
| Accuracy | 64.1% |
| Cost | 785 |
| Alternative 4 | |
|---|---|
| Accuracy | 64.5% |
| Cost | 785 |
| Alternative 5 | |
|---|---|
| Accuracy | 64.4% |
| Cost | 785 |
| Alternative 6 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 713 |
| Alternative 7 | |
|---|---|
| Accuracy | 84.9% |
| Cost | 712 |
| Alternative 8 | |
|---|---|
| Accuracy | 84.8% |
| Cost | 584 |
| Alternative 9 | |
|---|---|
| Accuracy | 95.9% |
| Cost | 576 |
| Alternative 10 | |
|---|---|
| Accuracy | 64.5% |
| Cost | 521 |
| Alternative 11 | |
|---|---|
| Accuracy | 38.9% |
| Cost | 64 |
herbie shell --seed 2023263
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, J"
:precision binary64
:herbie-target
(if (< (* x (- 1.0 (* (- 1.0 y) z))) -1.618195973607049e+50) (+ x (* (- 1.0 y) (* (- z) x))) (if (< (* x (- 1.0 (* (- 1.0 y) z))) 3.892237649663903e+134) (- (* (* x y) z) (- (* x z) x)) (+ x (* (- 1.0 y) (* (- z) x)))))
(* x (- 1.0 (* (- 1.0 y) z))))