| Alternative 1 | |
|---|---|
| Error | 0.83% |
| Cost | 1480 |
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- 1.0 (* y z)))))
(if (<= t_0 (- INFINITY))
(* y (* x (- z)))
(if (<= t_0 2e+298) (- x (* x (* y z))) (* z (* x (- y)))))))double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
double code(double x, double y, double z) {
double t_0 = x * (1.0 - (y * z));
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = y * (x * -z);
} else if (t_0 <= 2e+298) {
tmp = x - (x * (y * z));
} else {
tmp = z * (x * -y);
}
return tmp;
}
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 t_0 = x * (1.0 - (y * z));
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = y * (x * -z);
} else if (t_0 <= 2e+298) {
tmp = x - (x * (y * z));
} else {
tmp = z * (x * -y);
}
return tmp;
}
def code(x, y, z): return x * (1.0 - (y * z))
def code(x, y, z): t_0 = x * (1.0 - (y * z)) tmp = 0 if t_0 <= -math.inf: tmp = y * (x * -z) elif t_0 <= 2e+298: tmp = x - (x * (y * z)) else: tmp = z * (x * -y) return tmp
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(y * z))) end
function code(x, y, z) t_0 = Float64(x * Float64(1.0 - Float64(y * z))) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(y * Float64(x * Float64(-z))); elseif (t_0 <= 2e+298) tmp = Float64(x - Float64(x * Float64(y * z))); else tmp = Float64(z * Float64(x * Float64(-y))); end return tmp end
function tmp = code(x, y, z) tmp = x * (1.0 - (y * z)); end
function tmp_2 = code(x, y, z) t_0 = x * (1.0 - (y * z)); tmp = 0.0; if (t_0 <= -Inf) tmp = y * (x * -z); elseif (t_0 <= 2e+298) tmp = x - (x * (y * z)); else tmp = z * (x * -y); end tmp_2 = tmp; end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e+298], N[(x - N[(x * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision]]]]
x \cdot \left(1 - y \cdot z\right)
\begin{array}{l}
t_0 := x \cdot \left(1 - y \cdot z\right)\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+298}:\\
\;\;\;\;x - x \cdot \left(y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\end{array}
Results
if (*.f64 x (-.f64 1 (*.f64 y z))) < -inf.0Initial program 100
Taylor expanded in y around inf 0.45
Simplified0.45
[Start]0.45 | \[ -1 \cdot \left(y \cdot \left(z \cdot x\right)\right)
\] |
|---|---|
mul-1-neg [=>]0.45 | \[ \color{blue}{-y \cdot \left(z \cdot x\right)}
\] |
distribute-rgt-neg-in [=>]0.45 | \[ \color{blue}{y \cdot \left(-z \cdot x\right)}
\] |
distribute-lft-neg-in [=>]0.45 | \[ y \cdot \color{blue}{\left(\left(-z\right) \cdot x\right)}
\] |
if -inf.0 < (*.f64 x (-.f64 1 (*.f64 y z))) < 1.9999999999999999e298Initial program 0.16
Taylor expanded in x around 0 0.16
Simplified7.48
[Start]0.16 | \[ \left(1 - y \cdot z\right) \cdot x
\] |
|---|---|
sub-neg [=>]0.16 | \[ \color{blue}{\left(1 + \left(-y \cdot z\right)\right)} \cdot x
\] |
+-commutative [<=]0.16 | \[ \color{blue}{\left(\left(-y \cdot z\right) + 1\right)} \cdot x
\] |
distribute-lft1-in [<=]0.15 | \[ \color{blue}{\left(-y \cdot z\right) \cdot x + x}
\] |
distribute-lft-neg-out [=>]0.15 | \[ \color{blue}{\left(-\left(y \cdot z\right) \cdot x\right)} + x
\] |
associate-*r* [<=]7.48 | \[ \left(-\color{blue}{y \cdot \left(z \cdot x\right)}\right) + x
\] |
mul-1-neg [<=]7.48 | \[ \color{blue}{-1 \cdot \left(y \cdot \left(z \cdot x\right)\right)} + x
\] |
*-commutative [=>]7.48 | \[ \color{blue}{\left(y \cdot \left(z \cdot x\right)\right) \cdot -1} + x
\] |
associate-*l* [=>]7.48 | \[ \color{blue}{y \cdot \left(\left(z \cdot x\right) \cdot -1\right)} + x
\] |
fma-def [=>]7.48 | \[ \color{blue}{\mathsf{fma}\left(y, \left(z \cdot x\right) \cdot -1, x\right)}
\] |
associate-*l* [=>]7.48 | \[ \mathsf{fma}\left(y, \color{blue}{z \cdot \left(x \cdot -1\right)}, x\right)
\] |
*-commutative [=>]7.48 | \[ \mathsf{fma}\left(y, z \cdot \color{blue}{\left(-1 \cdot x\right)}, x\right)
\] |
neg-mul-1 [<=]7.48 | \[ \mathsf{fma}\left(y, z \cdot \color{blue}{\left(-x\right)}, x\right)
\] |
Taylor expanded in y around 0 7.48
Simplified0.15
[Start]7.48 | \[ -1 \cdot \left(y \cdot \left(z \cdot x\right)\right) + x
\] |
|---|---|
associate-*r* [=>]0.15 | \[ -1 \cdot \color{blue}{\left(\left(y \cdot z\right) \cdot x\right)} + x
\] |
mul-1-neg [=>]0.15 | \[ \color{blue}{\left(-\left(y \cdot z\right) \cdot x\right)} + x
\] |
+-commutative [<=]0.15 | \[ \color{blue}{x + \left(-\left(y \cdot z\right) \cdot x\right)}
\] |
sub-neg [<=]0.15 | \[ \color{blue}{x - \left(y \cdot z\right) \cdot x}
\] |
*-commutative [=>]0.15 | \[ x - \color{blue}{x \cdot \left(y \cdot z\right)}
\] |
if 1.9999999999999999e298 < (*.f64 x (-.f64 1 (*.f64 y z))) Initial program 74
Taylor expanded in y around inf 17.76
Simplified19.46
[Start]17.76 | \[ -1 \cdot \left(y \cdot \left(z \cdot x\right)\right)
\] |
|---|---|
mul-1-neg [=>]17.76 | \[ \color{blue}{-y \cdot \left(z \cdot x\right)}
\] |
associate-*r* [=>]88.51 | \[ -\color{blue}{\left(y \cdot z\right) \cdot x}
\] |
distribute-rgt-neg-in [=>]88.51 | \[ \color{blue}{\left(y \cdot z\right) \cdot \left(-x\right)}
\] |
*-commutative [=>]88.51 | \[ \color{blue}{\left(z \cdot y\right)} \cdot \left(-x\right)
\] |
associate-*l* [=>]19.46 | \[ \color{blue}{z \cdot \left(y \cdot \left(-x\right)\right)}
\] |
Final simplification0.83
| Alternative 1 | |
|---|---|
| Error | 0.83% |
| Cost | 1480 |
| Alternative 2 | |
|---|---|
| Error | 34.5% |
| Cost | 1044 |
| Alternative 3 | |
|---|---|
| Error | 33.58% |
| Cost | 1044 |
| Alternative 4 | |
|---|---|
| Error | 35.7% |
| Cost | 649 |
| Alternative 5 | |
|---|---|
| Error | 39.56% |
| Cost | 64 |
herbie shell --seed 2023115
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))