| Alternative 1 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 7108 |

(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
(FPCore (x y z) :precision binary64 (if (<= (* y z) -5e+267) (fma -1.0 (* z (* y x)) x) (* x (- (fma y z -1.0)))))
double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+267) {
tmp = fma(-1.0, (z * (y * x)), x);
} else {
tmp = x * -fma(y, z, -1.0);
}
return tmp;
}
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(y * z))) end
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -5e+267) tmp = fma(-1.0, Float64(z * Float64(y * x)), x); else tmp = Float64(x * Float64(-fma(y, z, -1.0))); end return tmp end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -5e+267], N[(-1.0 * N[(z * N[(y * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(x * (-N[(y * z + -1.0), $MachinePrecision])), $MachinePrecision]]
x \cdot \left(1 - y \cdot z\right)
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+267}:\\
\;\;\;\;\mathsf{fma}\left(-1, z \cdot \left(y \cdot x\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-\mathsf{fma}\left(y, z, -1\right)\right)\\
\end{array}
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
if (*.f64 y z) < -4.9999999999999999e267Initial program 63.7%
Taylor expanded in x around 0 63.7%
Simplified99.9%
[Start]63.7% | \[ \left(1 - y \cdot z\right) \cdot x
\] |
|---|---|
sub-neg [=>]63.7% | \[ \color{blue}{\left(1 + \left(-y \cdot z\right)\right)} \cdot x
\] |
distribute-rgt-neg-out [<=]63.7% | \[ \left(1 + \color{blue}{y \cdot \left(-z\right)}\right) \cdot x
\] |
+-commutative [=>]63.7% | \[ \color{blue}{\left(y \cdot \left(-z\right) + 1\right)} \cdot x
\] |
distribute-lft1-in [<=]63.7% | \[ \color{blue}{\left(y \cdot \left(-z\right)\right) \cdot x + x}
\] |
associate-*l* [=>]99.9% | \[ \color{blue}{y \cdot \left(\left(-z\right) \cdot x\right)} + x
\] |
fma-def [=>]99.9% | \[ \color{blue}{\mathsf{fma}\left(y, \left(-z\right) \cdot x, x\right)}
\] |
*-commutative [=>]99.9% | \[ \mathsf{fma}\left(y, \color{blue}{x \cdot \left(-z\right)}, x\right)
\] |
Taylor expanded in y around 0 99.9%
Simplified99.9%
[Start]99.9% | \[ -1 \cdot \left(y \cdot \left(z \cdot x\right)\right) + x
\] |
|---|---|
fma-def [=>]99.9% | \[ \color{blue}{\mathsf{fma}\left(-1, y \cdot \left(z \cdot x\right), x\right)}
\] |
*-commutative [=>]99.9% | \[ \mathsf{fma}\left(-1, y \cdot \color{blue}{\left(x \cdot z\right)}, x\right)
\] |
associate-*r* [=>]99.9% | \[ \mathsf{fma}\left(-1, \color{blue}{\left(y \cdot x\right) \cdot z}, x\right)
\] |
if -4.9999999999999999e267 < (*.f64 y z) Initial program 98.4%
Applied egg-rr80.4%
[Start]98.4% | \[ x \cdot \left(1 - y \cdot z\right)
\] |
|---|---|
sub-neg [=>]98.4% | \[ x \cdot \color{blue}{\left(1 + \left(-y \cdot z\right)\right)}
\] |
flip-+ [=>]80.4% | \[ x \cdot \color{blue}{\frac{1 \cdot 1 - \left(-y \cdot z\right) \cdot \left(-y \cdot z\right)}{1 - \left(-y \cdot z\right)}}
\] |
metadata-eval [=>]80.4% | \[ x \cdot \frac{\color{blue}{1} - \left(-y \cdot z\right) \cdot \left(-y \cdot z\right)}{1 - \left(-y \cdot z\right)}
\] |
distribute-rgt-neg-in [=>]80.4% | \[ x \cdot \frac{1 - \color{blue}{\left(y \cdot \left(-z\right)\right)} \cdot \left(-y \cdot z\right)}{1 - \left(-y \cdot z\right)}
\] |
distribute-rgt-neg-in [=>]80.4% | \[ x \cdot \frac{1 - \left(y \cdot \left(-z\right)\right) \cdot \color{blue}{\left(y \cdot \left(-z\right)\right)}}{1 - \left(-y \cdot z\right)}
\] |
distribute-rgt-neg-in [=>]80.4% | \[ x \cdot \frac{1 - \left(y \cdot \left(-z\right)\right) \cdot \left(y \cdot \left(-z\right)\right)}{1 - \color{blue}{y \cdot \left(-z\right)}}
\] |
Taylor expanded in y around 0 98.4%
Simplified98.4%
[Start]98.4% | \[ x \cdot \left(1 + -1 \cdot \left(y \cdot z\right)\right)
\] |
|---|---|
+-commutative [=>]98.4% | \[ x \cdot \color{blue}{\left(-1 \cdot \left(y \cdot z\right) + 1\right)}
\] |
mul-1-neg [=>]98.4% | \[ x \cdot \left(\color{blue}{\left(-y \cdot z\right)} + 1\right)
\] |
metadata-eval [<=]98.4% | \[ x \cdot \left(\left(-y \cdot z\right) + \color{blue}{\left(--1\right)}\right)
\] |
distribute-neg-in [<=]98.4% | \[ x \cdot \color{blue}{\left(-\left(y \cdot z + -1\right)\right)}
\] |
fma-def [=>]98.4% | \[ x \cdot \left(-\color{blue}{\mathsf{fma}\left(y, z, -1\right)}\right)
\] |
Final simplification98.5%
| Alternative 1 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 7108 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 7044 |
| Alternative 3 | |
|---|---|
| Accuracy | 94.0% |
| Cost | 905 |
| Alternative 4 | |
|---|---|
| Accuracy | 94.0% |
| Cost | 904 |
| Alternative 5 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 708 |
| Alternative 6 | |
|---|---|
| Accuracy | 50.8% |
| Cost | 64 |
herbie shell --seed 2023272
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))