| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 1352 |
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
(FPCore (x y z) :precision binary64 (if (<= x -7e-19) (+ (* x (- 1.0 z)) (* x (* y z))) (if (<= x 2.3e-86) (+ x (* z (* x (+ y -1.0)))) (* x (- (fma y z 1.0) z)))))
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 <= -7e-19) {
tmp = (x * (1.0 - z)) + (x * (y * z));
} else if (x <= 2.3e-86) {
tmp = x + (z * (x * (y + -1.0)));
} else {
tmp = x * (fma(y, z, 1.0) - z);
}
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 (x <= -7e-19) tmp = Float64(Float64(x * Float64(1.0 - z)) + Float64(x * Float64(y * z))); elseif (x <= 2.3e-86) tmp = Float64(x + Float64(z * Float64(x * Float64(y + -1.0)))); else tmp = Float64(x * Float64(fma(y, z, 1.0) - z)); 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[x, -7e-19], N[(N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision] + N[(x * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.3e-86], N[(x + N[(z * N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(y * z + 1.0), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]]]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{-19}:\\
\;\;\;\;x \cdot \left(1 - z\right) + x \cdot \left(y \cdot z\right)\\
\mathbf{elif}\;x \leq 2.3 \cdot 10^{-86}:\\
\;\;\;\;x + z \cdot \left(x \cdot \left(y + -1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\mathsf{fma}\left(y, z, 1\right) - z\right)\\
\end{array}
| Original | 3.5 |
|---|---|
| Target | 0.2 |
| Herbie | 0.3 |
if x < -7.00000000000000031e-19Initial program 0.2
Simplified0.2
[Start]0.2 | \[ x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\] |
|---|---|
*-commutative [=>]0.2 | \[ x \cdot \left(1 - \color{blue}{z \cdot \left(1 - y\right)}\right)
\] |
sub-neg [=>]0.2 | \[ x \cdot \left(1 - z \cdot \color{blue}{\left(1 + \left(-y\right)\right)}\right)
\] |
distribute-rgt-in [=>]0.2 | \[ x \cdot \left(1 - \color{blue}{\left(1 \cdot z + \left(-y\right) \cdot z\right)}\right)
\] |
associate--r+ [=>]0.2 | \[ x \cdot \color{blue}{\left(\left(1 - 1 \cdot z\right) - \left(-y\right) \cdot z\right)}
\] |
*-lft-identity [=>]0.2 | \[ x \cdot \left(\left(1 - \color{blue}{z}\right) - \left(-y\right) \cdot z\right)
\] |
sub-neg [=>]0.2 | \[ x \cdot \left(\color{blue}{\left(1 + \left(-z\right)\right)} - \left(-y\right) \cdot z\right)
\] |
distribute-lft-out-- [<=]0.2 | \[ \color{blue}{x \cdot \left(1 + \left(-z\right)\right) - x \cdot \left(\left(-y\right) \cdot z\right)}
\] |
distribute-lft-in [=>]0.2 | \[ \color{blue}{\left(x \cdot 1 + x \cdot \left(-z\right)\right)} - x \cdot \left(\left(-y\right) \cdot z\right)
\] |
*-rgt-identity [=>]0.2 | \[ \left(\color{blue}{x} + x \cdot \left(-z\right)\right) - x \cdot \left(\left(-y\right) \cdot z\right)
\] |
+-commutative [=>]0.2 | \[ \color{blue}{\left(x \cdot \left(-z\right) + x\right)} - x \cdot \left(\left(-y\right) \cdot z\right)
\] |
associate-+r- [<=]0.2 | \[ \color{blue}{x \cdot \left(-z\right) + \left(x - x \cdot \left(\left(-y\right) \cdot z\right)\right)}
\] |
*-commutative [=>]0.2 | \[ x \cdot \left(-z\right) + \left(x - \color{blue}{\left(\left(-y\right) \cdot z\right) \cdot x}\right)
\] |
cancel-sign-sub-inv [=>]0.2 | \[ x \cdot \left(-z\right) + \color{blue}{\left(x + \left(-\left(-y\right) \cdot z\right) \cdot x\right)}
\] |
distribute-rgt-neg-in [=>]0.2 | \[ x \cdot \left(-z\right) + \left(x + \color{blue}{\left(\left(-y\right) \cdot \left(-z\right)\right)} \cdot x\right)
\] |
distribute-rgt1-in [=>]0.2 | \[ x \cdot \left(-z\right) + \color{blue}{\left(\left(-y\right) \cdot \left(-z\right) + 1\right) \cdot x}
\] |
*-commutative [=>]0.2 | \[ x \cdot \left(-z\right) + \color{blue}{x \cdot \left(\left(-y\right) \cdot \left(-z\right) + 1\right)}
\] |
+-commutative [=>]0.2 | \[ \color{blue}{x \cdot \left(\left(-y\right) \cdot \left(-z\right) + 1\right) + x \cdot \left(-z\right)}
\] |
Applied egg-rr0.2
if -7.00000000000000031e-19 < x < 2.29999999999999996e-86Initial program 6.3
Simplified6.3
[Start]6.3 | \[ x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\] |
|---|---|
*-commutative [=>]6.3 | \[ x \cdot \left(1 - \color{blue}{z \cdot \left(1 - y\right)}\right)
\] |
sub-neg [=>]6.3 | \[ x \cdot \left(1 - z \cdot \color{blue}{\left(1 + \left(-y\right)\right)}\right)
\] |
distribute-rgt-in [=>]6.3 | \[ x \cdot \left(1 - \color{blue}{\left(1 \cdot z + \left(-y\right) \cdot z\right)}\right)
\] |
associate--r+ [=>]6.3 | \[ x \cdot \color{blue}{\left(\left(1 - 1 \cdot z\right) - \left(-y\right) \cdot z\right)}
\] |
*-lft-identity [=>]6.3 | \[ x \cdot \left(\left(1 - \color{blue}{z}\right) - \left(-y\right) \cdot z\right)
\] |
sub-neg [=>]6.3 | \[ x \cdot \left(\color{blue}{\left(1 + \left(-z\right)\right)} - \left(-y\right) \cdot z\right)
\] |
distribute-lft-out-- [<=]6.3 | \[ \color{blue}{x \cdot \left(1 + \left(-z\right)\right) - x \cdot \left(\left(-y\right) \cdot z\right)}
\] |
distribute-lft-in [=>]6.3 | \[ \color{blue}{\left(x \cdot 1 + x \cdot \left(-z\right)\right)} - x \cdot \left(\left(-y\right) \cdot z\right)
\] |
*-rgt-identity [=>]6.3 | \[ \left(\color{blue}{x} + x \cdot \left(-z\right)\right) - x \cdot \left(\left(-y\right) \cdot z\right)
\] |
+-commutative [=>]6.3 | \[ \color{blue}{\left(x \cdot \left(-z\right) + x\right)} - x \cdot \left(\left(-y\right) \cdot z\right)
\] |
associate-+r- [<=]6.3 | \[ \color{blue}{x \cdot \left(-z\right) + \left(x - x \cdot \left(\left(-y\right) \cdot z\right)\right)}
\] |
*-commutative [=>]6.3 | \[ x \cdot \left(-z\right) + \left(x - \color{blue}{\left(\left(-y\right) \cdot z\right) \cdot x}\right)
\] |
cancel-sign-sub-inv [=>]6.3 | \[ x \cdot \left(-z\right) + \color{blue}{\left(x + \left(-\left(-y\right) \cdot z\right) \cdot x\right)}
\] |
distribute-rgt-neg-in [=>]6.3 | \[ x \cdot \left(-z\right) + \left(x + \color{blue}{\left(\left(-y\right) \cdot \left(-z\right)\right)} \cdot x\right)
\] |
distribute-rgt1-in [=>]6.3 | \[ x \cdot \left(-z\right) + \color{blue}{\left(\left(-y\right) \cdot \left(-z\right) + 1\right) \cdot x}
\] |
*-commutative [=>]6.3 | \[ x \cdot \left(-z\right) + \color{blue}{x \cdot \left(\left(-y\right) \cdot \left(-z\right) + 1\right)}
\] |
+-commutative [=>]6.3 | \[ \color{blue}{x \cdot \left(\left(-y\right) \cdot \left(-z\right) + 1\right) + x \cdot \left(-z\right)}
\] |
Taylor expanded in z around -inf 3.0
Simplified0.1
[Start]3.0 | \[ -1 \cdot \left(\left(1 + -1 \cdot y\right) \cdot \left(z \cdot x\right)\right) + x
\] |
|---|---|
+-commutative [=>]3.0 | \[ \color{blue}{x + -1 \cdot \left(\left(1 + -1 \cdot y\right) \cdot \left(z \cdot x\right)\right)}
\] |
mul-1-neg [=>]3.0 | \[ x + \color{blue}{\left(-\left(1 + -1 \cdot y\right) \cdot \left(z \cdot x\right)\right)}
\] |
unsub-neg [=>]3.0 | \[ \color{blue}{x - \left(1 + -1 \cdot y\right) \cdot \left(z \cdot x\right)}
\] |
associate-*r* [=>]6.3 | \[ x - \color{blue}{\left(\left(1 + -1 \cdot y\right) \cdot z\right) \cdot x}
\] |
*-commutative [=>]6.3 | \[ x - \color{blue}{\left(z \cdot \left(1 + -1 \cdot y\right)\right)} \cdot x
\] |
associate-*l* [=>]0.1 | \[ x - \color{blue}{z \cdot \left(\left(1 + -1 \cdot y\right) \cdot x\right)}
\] |
mul-1-neg [=>]0.1 | \[ x - z \cdot \left(\left(1 + \color{blue}{\left(-y\right)}\right) \cdot x\right)
\] |
unsub-neg [=>]0.1 | \[ x - z \cdot \left(\color{blue}{\left(1 - y\right)} \cdot x\right)
\] |
if 2.29999999999999996e-86 < x Initial program 0.8
Simplified0.8
[Start]0.8 | \[ x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\] |
|---|---|
*-commutative [=>]0.8 | \[ x \cdot \left(1 - \color{blue}{z \cdot \left(1 - y\right)}\right)
\] |
sub-neg [=>]0.8 | \[ x \cdot \left(1 - z \cdot \color{blue}{\left(1 + \left(-y\right)\right)}\right)
\] |
distribute-rgt-in [=>]0.8 | \[ x \cdot \left(1 - \color{blue}{\left(1 \cdot z + \left(-y\right) \cdot z\right)}\right)
\] |
associate--r+ [=>]0.8 | \[ x \cdot \color{blue}{\left(\left(1 - 1 \cdot z\right) - \left(-y\right) \cdot z\right)}
\] |
*-lft-identity [=>]0.8 | \[ x \cdot \left(\left(1 - \color{blue}{z}\right) - \left(-y\right) \cdot z\right)
\] |
sub-neg [=>]0.8 | \[ x \cdot \left(\color{blue}{\left(1 + \left(-z\right)\right)} - \left(-y\right) \cdot z\right)
\] |
distribute-lft-out-- [<=]0.8 | \[ \color{blue}{x \cdot \left(1 + \left(-z\right)\right) - x \cdot \left(\left(-y\right) \cdot z\right)}
\] |
distribute-lft-in [=>]0.8 | \[ \color{blue}{\left(x \cdot 1 + x \cdot \left(-z\right)\right)} - x \cdot \left(\left(-y\right) \cdot z\right)
\] |
*-rgt-identity [=>]0.8 | \[ \left(\color{blue}{x} + x \cdot \left(-z\right)\right) - x \cdot \left(\left(-y\right) \cdot z\right)
\] |
+-commutative [=>]0.8 | \[ \color{blue}{\left(x \cdot \left(-z\right) + x\right)} - x \cdot \left(\left(-y\right) \cdot z\right)
\] |
associate-+r- [<=]0.8 | \[ \color{blue}{x \cdot \left(-z\right) + \left(x - x \cdot \left(\left(-y\right) \cdot z\right)\right)}
\] |
*-commutative [=>]0.8 | \[ x \cdot \left(-z\right) + \left(x - \color{blue}{\left(\left(-y\right) \cdot z\right) \cdot x}\right)
\] |
cancel-sign-sub-inv [=>]0.8 | \[ x \cdot \left(-z\right) + \color{blue}{\left(x + \left(-\left(-y\right) \cdot z\right) \cdot x\right)}
\] |
distribute-rgt-neg-in [=>]0.8 | \[ x \cdot \left(-z\right) + \left(x + \color{blue}{\left(\left(-y\right) \cdot \left(-z\right)\right)} \cdot x\right)
\] |
distribute-rgt1-in [=>]0.8 | \[ x \cdot \left(-z\right) + \color{blue}{\left(\left(-y\right) \cdot \left(-z\right) + 1\right) \cdot x}
\] |
*-commutative [=>]0.8 | \[ x \cdot \left(-z\right) + \color{blue}{x \cdot \left(\left(-y\right) \cdot \left(-z\right) + 1\right)}
\] |
+-commutative [=>]0.8 | \[ \color{blue}{x \cdot \left(\left(-y\right) \cdot \left(-z\right) + 1\right) + x \cdot \left(-z\right)}
\] |
Final simplification0.3
| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 1352 |
| Alternative 2 | |
|---|---|
| Error | 12.4 |
| Cost | 1115 |
| Alternative 3 | |
|---|---|
| Error | 12.7 |
| Cost | 1112 |
| Alternative 4 | |
|---|---|
| Error | 20.5 |
| Cost | 1048 |
| Alternative 5 | |
|---|---|
| Error | 0.2 |
| Cost | 969 |
| Alternative 6 | |
|---|---|
| Error | 21.3 |
| Cost | 916 |
| Alternative 7 | |
|---|---|
| Error | 0.3 |
| Cost | 841 |
| Alternative 8 | |
|---|---|
| Error | 20.4 |
| Cost | 784 |
| Alternative 9 | |
|---|---|
| Error | 4.3 |
| Cost | 713 |
| Alternative 10 | |
|---|---|
| Error | 0.9 |
| Cost | 713 |
| Alternative 11 | |
|---|---|
| Error | 0.9 |
| Cost | 713 |
| Alternative 12 | |
|---|---|
| Error | 19.0 |
| Cost | 521 |
| Alternative 13 | |
|---|---|
| Error | 32.9 |
| Cost | 64 |
herbie shell --seed 2023031
(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))))