| Alternative 1 | |
|---|---|
| Error | 2.3 |
| Cost | 708 |
\[\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -1 \cdot 10^{+98}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\]
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
(FPCore (x y z) :precision binary64 (if (<= (* y z) -1e+98) (* z (* y (- x))) (- x (* (* y z) 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) <= -1e+98) {
tmp = z * (y * -x);
} else {
tmp = x - ((y * z) * 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) <= (-1d+98)) then
tmp = z * (y * -x)
else
tmp = x - ((y * z) * 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) <= -1e+98) {
tmp = z * (y * -x);
} else {
tmp = x - ((y * z) * x);
}
return tmp;
}
def code(x, y, z): return x * (1.0 - (y * z))
def code(x, y, z): tmp = 0 if (y * z) <= -1e+98: tmp = z * (y * -x) else: tmp = x - ((y * z) * 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) <= -1e+98) tmp = Float64(z * Float64(y * Float64(-x))); else tmp = Float64(x - Float64(Float64(y * z) * 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) <= -1e+98) tmp = z * (y * -x); else tmp = x - ((y * z) * 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], -1e+98], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
x \cdot \left(1 - y \cdot z\right)
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -1 \cdot 10^{+98}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\end{array}
Results
if (*.f64 y z) < -9.99999999999999998e97Initial program 13.7
Taylor expanded in y around inf 3.4
Simplified4.6
[Start]3.4 | \[ -1 \cdot \left(y \cdot \left(z \cdot x\right)\right)
\] |
|---|---|
mul-1-neg [=>]3.4 | \[ \color{blue}{-y \cdot \left(z \cdot x\right)}
\] |
associate-*r* [=>]13.7 | \[ -\color{blue}{\left(y \cdot z\right) \cdot x}
\] |
distribute-rgt-neg-in [=>]13.7 | \[ \color{blue}{\left(y \cdot z\right) \cdot \left(-x\right)}
\] |
*-commutative [=>]13.7 | \[ \color{blue}{\left(z \cdot y\right)} \cdot \left(-x\right)
\] |
associate-*l* [=>]4.6 | \[ \color{blue}{z \cdot \left(y \cdot \left(-x\right)\right)}
\] |
if -9.99999999999999998e97 < (*.f64 y z) Initial program 2.1
Taylor expanded in x around 0 2.1
Simplified5.2
[Start]2.1 | \[ \left(1 - y \cdot z\right) \cdot x
\] |
|---|---|
*-commutative [<=]2.1 | \[ \color{blue}{x \cdot \left(1 - y \cdot z\right)}
\] |
distribute-rgt-out-- [<=]2.0 | \[ \color{blue}{1 \cdot x - \left(y \cdot z\right) \cdot x}
\] |
*-lft-identity [=>]2.0 | \[ \color{blue}{x} - \left(y \cdot z\right) \cdot x
\] |
associate-*r* [<=]5.2 | \[ x - \color{blue}{y \cdot \left(z \cdot x\right)}
\] |
Applied egg-rr20.7
Simplified2.0
[Start]20.7 | \[ x - \left(e^{\mathsf{log1p}\left(y \cdot \left(z \cdot x\right)\right)} - 1\right)
\] |
|---|---|
expm1-def [=>]15.1 | \[ x - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(y \cdot \left(z \cdot x\right)\right)\right)}
\] |
expm1-log1p [=>]5.2 | \[ x - \color{blue}{y \cdot \left(z \cdot x\right)}
\] |
associate-*r* [=>]2.0 | \[ x - \color{blue}{\left(y \cdot z\right) \cdot x}
\] |
Final simplification2.3
| Alternative 1 | |
|---|---|
| Error | 2.3 |
| Cost | 708 |
| Alternative 2 | |
|---|---|
| Error | 17.8 |
| Cost | 649 |
| Alternative 3 | |
|---|---|
| Error | 17.7 |
| Cost | 648 |
| Alternative 4 | |
|---|---|
| Error | 16.8 |
| Cost | 648 |
| Alternative 5 | |
|---|---|
| Error | 25.5 |
| Cost | 64 |
herbie shell --seed 2023018
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))