| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 968 |

(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
(FPCore (x y z) :precision binary64 (if (<= (* y z) -5e+239) (* y (- (* z x))) (if (<= (* y z) 5e+168) (* x (- 1.0 (* y z))) (* z (* y (- x))))))
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+239) {
tmp = y * -(z * x);
} else if ((y * z) <= 5e+168) {
tmp = x * (1.0 - (y * z));
} else {
tmp = z * (y * -x);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * (1.0d0 - (y * z))
end function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y * z) <= (-5d+239)) then
tmp = y * -(z * x)
else if ((y * z) <= 5d+168) then
tmp = x * (1.0d0 - (y * z))
else
tmp = z * (y * -x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+239) {
tmp = y * -(z * x);
} else if ((y * z) <= 5e+168) {
tmp = x * (1.0 - (y * z));
} else {
tmp = z * (y * -x);
}
return tmp;
}
def code(x, y, z): return x * (1.0 - (y * z))
def code(x, y, z): tmp = 0 if (y * z) <= -5e+239: tmp = y * -(z * x) elif (y * z) <= 5e+168: tmp = x * (1.0 - (y * z)) else: tmp = z * (y * -x) 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+239) tmp = Float64(y * Float64(-Float64(z * x))); elseif (Float64(y * z) <= 5e+168) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(z * Float64(y * Float64(-x))); end return tmp end
function tmp = code(x, y, z) tmp = x * (1.0 - (y * z)); end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * z) <= -5e+239) tmp = y * -(z * x); elseif ((y * z) <= 5e+168) tmp = x * (1.0 - (y * z)); else tmp = z * (y * -x); end tmp_2 = 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+239], N[(y * (-N[(z * x), $MachinePrecision])), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 5e+168], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision]]]
x \cdot \left(1 - y \cdot z\right)
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+239}:\\
\;\;\;\;y \cdot \left(-z \cdot x\right)\\
\mathbf{elif}\;y \cdot z \leq 5 \cdot 10^{+168}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\end{array}
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
if (*.f64 y z) < -5.00000000000000007e239Initial program 77.1%
Taylor expanded in y around inf 99.9%
Simplified99.9%
[Start]99.9% | \[ -1 \cdot \left(y \cdot \left(z \cdot x\right)\right)
\] |
|---|---|
mul-1-neg [=>]99.9% | \[ \color{blue}{-y \cdot \left(z \cdot x\right)}
\] |
distribute-rgt-neg-in [=>]99.9% | \[ \color{blue}{y \cdot \left(-z \cdot x\right)}
\] |
distribute-lft-neg-out [<=]99.9% | \[ y \cdot \color{blue}{\left(\left(-z\right) \cdot x\right)}
\] |
*-commutative [=>]99.9% | \[ y \cdot \color{blue}{\left(x \cdot \left(-z\right)\right)}
\] |
if -5.00000000000000007e239 < (*.f64 y z) < 4.99999999999999967e168Initial program 99.9%
if 4.99999999999999967e168 < (*.f64 y z) Initial program 86.2%
Taylor expanded in x around 0 86.2%
Simplified99.8%
[Start]86.2% | \[ \left(1 - y \cdot z\right) \cdot x
\] |
|---|---|
*-commutative [=>]86.2% | \[ \color{blue}{x \cdot \left(1 - y \cdot z\right)}
\] |
distribute-rgt-out-- [<=]86.2% | \[ \color{blue}{1 \cdot x - \left(y \cdot z\right) \cdot x}
\] |
associate-*r* [<=]99.8% | \[ 1 \cdot x - \color{blue}{y \cdot \left(z \cdot x\right)}
\] |
*-lft-identity [=>]99.8% | \[ \color{blue}{x} - y \cdot \left(z \cdot x\right)
\] |
Applied egg-rr20.2%
[Start]99.8% | \[ x - y \cdot \left(z \cdot x\right)
\] |
|---|---|
cancel-sign-sub-inv [=>]99.8% | \[ \color{blue}{x + \left(-y\right) \cdot \left(z \cdot x\right)}
\] |
flip3-+ [=>]20.2% | \[ \color{blue}{\frac{{x}^{3} + {\left(\left(-y\right) \cdot \left(z \cdot x\right)\right)}^{3}}{x \cdot x + \left(\left(\left(-y\right) \cdot \left(z \cdot x\right)\right) \cdot \left(\left(-y\right) \cdot \left(z \cdot x\right)\right) - x \cdot \left(\left(-y\right) \cdot \left(z \cdot x\right)\right)\right)}}
\] |
Taylor expanded in y around inf 0.1%
Simplified20.2%
[Start]0.1% | \[ \frac{-1 \cdot \left({y}^{3} \cdot \left({z}^{3} \cdot {x}^{3}\right)\right)}{x \cdot x + \left(\left(\left(-y\right) \cdot \left(z \cdot x\right)\right) \cdot \left(\left(-y\right) \cdot \left(z \cdot x\right)\right) - x \cdot \left(\left(-y\right) \cdot \left(z \cdot x\right)\right)\right)}
\] |
|---|---|
mul-1-neg [=>]0.1% | \[ \frac{\color{blue}{-{y}^{3} \cdot \left({z}^{3} \cdot {x}^{3}\right)}}{x \cdot x + \left(\left(\left(-y\right) \cdot \left(z \cdot x\right)\right) \cdot \left(\left(-y\right) \cdot \left(z \cdot x\right)\right) - x \cdot \left(\left(-y\right) \cdot \left(z \cdot x\right)\right)\right)}
\] |
cube-prod [<=]8.9% | \[ \frac{-{y}^{3} \cdot \color{blue}{{\left(z \cdot x\right)}^{3}}}{x \cdot x + \left(\left(\left(-y\right) \cdot \left(z \cdot x\right)\right) \cdot \left(\left(-y\right) \cdot \left(z \cdot x\right)\right) - x \cdot \left(\left(-y\right) \cdot \left(z \cdot x\right)\right)\right)}
\] |
distribute-lft-neg-in [=>]8.9% | \[ \frac{\color{blue}{\left(-{y}^{3}\right) \cdot {\left(z \cdot x\right)}^{3}}}{x \cdot x + \left(\left(\left(-y\right) \cdot \left(z \cdot x\right)\right) \cdot \left(\left(-y\right) \cdot \left(z \cdot x\right)\right) - x \cdot \left(\left(-y\right) \cdot \left(z \cdot x\right)\right)\right)}
\] |
cube-neg [<=]8.9% | \[ \frac{\color{blue}{{\left(-y\right)}^{3}} \cdot {\left(z \cdot x\right)}^{3}}{x \cdot x + \left(\left(\left(-y\right) \cdot \left(z \cdot x\right)\right) \cdot \left(\left(-y\right) \cdot \left(z \cdot x\right)\right) - x \cdot \left(\left(-y\right) \cdot \left(z \cdot x\right)\right)\right)}
\] |
cube-prod [<=]20.2% | \[ \frac{\color{blue}{{\left(\left(-y\right) \cdot \left(z \cdot x\right)\right)}^{3}}}{x \cdot x + \left(\left(\left(-y\right) \cdot \left(z \cdot x\right)\right) \cdot \left(\left(-y\right) \cdot \left(z \cdot x\right)\right) - x \cdot \left(\left(-y\right) \cdot \left(z \cdot x\right)\right)\right)}
\] |
distribute-lft-neg-in [<=]20.2% | \[ \frac{{\color{blue}{\left(-y \cdot \left(z \cdot x\right)\right)}}^{3}}{x \cdot x + \left(\left(\left(-y\right) \cdot \left(z \cdot x\right)\right) \cdot \left(\left(-y\right) \cdot \left(z \cdot x\right)\right) - x \cdot \left(\left(-y\right) \cdot \left(z \cdot x\right)\right)\right)}
\] |
distribute-rgt-neg-in [=>]20.2% | \[ \frac{{\color{blue}{\left(y \cdot \left(-z \cdot x\right)\right)}}^{3}}{x \cdot x + \left(\left(\left(-y\right) \cdot \left(z \cdot x\right)\right) \cdot \left(\left(-y\right) \cdot \left(z \cdot x\right)\right) - x \cdot \left(\left(-y\right) \cdot \left(z \cdot x\right)\right)\right)}
\] |
distribute-rgt-neg-in [=>]20.2% | \[ \frac{{\left(y \cdot \color{blue}{\left(z \cdot \left(-x\right)\right)}\right)}^{3}}{x \cdot x + \left(\left(\left(-y\right) \cdot \left(z \cdot x\right)\right) \cdot \left(\left(-y\right) \cdot \left(z \cdot x\right)\right) - x \cdot \left(\left(-y\right) \cdot \left(z \cdot x\right)\right)\right)}
\] |
Taylor expanded in y around inf 99.8%
Simplified97.4%
[Start]99.8% | \[ -1 \cdot \left(y \cdot \left(z \cdot x\right)\right)
\] |
|---|---|
mul-1-neg [=>]99.8% | \[ \color{blue}{-y \cdot \left(z \cdot x\right)}
\] |
*-commutative [=>]99.8% | \[ -\color{blue}{\left(z \cdot x\right) \cdot y}
\] |
associate-*r* [<=]97.4% | \[ -\color{blue}{z \cdot \left(x \cdot y\right)}
\] |
distribute-rgt-neg-in [=>]97.4% | \[ \color{blue}{z \cdot \left(-x \cdot y\right)}
\] |
*-commutative [=>]97.4% | \[ z \cdot \left(-\color{blue}{y \cdot x}\right)
\] |
distribute-rgt-neg-in [=>]97.4% | \[ z \cdot \color{blue}{\left(y \cdot \left(-x\right)\right)}
\] |
Final simplification99.5%
| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 968 |
| Alternative 2 | |
|---|---|
| Accuracy | 74.6% |
| Cost | 649 |
| Alternative 3 | |
|---|---|
| Accuracy | 75.4% |
| Cost | 648 |
| Alternative 4 | |
|---|---|
| Accuracy | 75.1% |
| Cost | 648 |
| Alternative 5 | |
|---|---|
| Accuracy | 50.8% |
| Cost | 64 |
herbie shell --seed 2023263
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))