| Alternative 1 | |
|---|---|
| Accuracy | 96.8% |
| Cost | 580 |
\[\begin{array}{l}
\mathbf{if}\;z \leq 1.5 \cdot 10^{-14}:\\
\;\;\;\;x \cdot \left(1 - z \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \left(x \cdot y\right)\\
\end{array}
\]

(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
(FPCore (x y z) :precision binary64 (if (<= z 1.5e-14) (* x (- 1.0 (* z y))) (- x (* 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 tmp;
if (z <= 1.5e-14) {
tmp = x * (1.0 - (z * y));
} else {
tmp = x - (z * (x * y));
}
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 (z <= 1.5d-14) then
tmp = x * (1.0d0 - (z * y))
else
tmp = x - (z * (x * y))
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 (z <= 1.5e-14) {
tmp = x * (1.0 - (z * y));
} else {
tmp = x - (z * (x * y));
}
return tmp;
}
def code(x, y, z): return x * (1.0 - (y * z))
def code(x, y, z): tmp = 0 if z <= 1.5e-14: tmp = x * (1.0 - (z * y)) else: tmp = x - (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) tmp = 0.0 if (z <= 1.5e-14) tmp = Float64(x * Float64(1.0 - Float64(z * y))); else tmp = Float64(x - Float64(z * Float64(x * 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) tmp = 0.0; if (z <= 1.5e-14) tmp = x * (1.0 - (z * y)); else tmp = x - (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_] := If[LessEqual[z, 1.5e-14], N[(x * N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(z * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
x \cdot \left(1 - y \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \leq 1.5 \cdot 10^{-14}:\\
\;\;\;\;x \cdot \left(1 - z \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \left(x \cdot y\right)\\
\end{array}
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
if z < 1.4999999999999999e-14Initial program 98.4%
if 1.4999999999999999e-14 < z Initial program 90.9%
Applied egg-rr56.3%
[Start]90.9% | \[ x \cdot \left(1 - y \cdot z\right)
\] |
|---|---|
flip-- [=>]58.8% | \[ x \cdot \color{blue}{\frac{1 \cdot 1 - \left(y \cdot z\right) \cdot \left(y \cdot z\right)}{1 + y \cdot z}}
\] |
associate-*r/ [=>]56.3% | \[ \color{blue}{\frac{x \cdot \left(1 \cdot 1 - \left(y \cdot z\right) \cdot \left(y \cdot z\right)\right)}{1 + y \cdot z}}
\] |
metadata-eval [=>]56.3% | \[ \frac{x \cdot \left(\color{blue}{1} - \left(y \cdot z\right) \cdot \left(y \cdot z\right)\right)}{1 + y \cdot z}
\] |
pow2 [=>]56.3% | \[ \frac{x \cdot \left(1 - \color{blue}{{\left(y \cdot z\right)}^{2}}\right)}{1 + y \cdot z}
\] |
Simplified58.8%
[Start]56.3% | \[ \frac{x \cdot \left(1 - {\left(y \cdot z\right)}^{2}\right)}{1 + y \cdot z}
\] |
|---|---|
associate-/l* [=>]58.8% | \[ \color{blue}{\frac{x}{\frac{1 + y \cdot z}{1 - {\left(y \cdot z\right)}^{2}}}}
\] |
Taylor expanded in y around inf 43.7%
Simplified70.1%
[Start]43.7% | \[ \frac{x}{-\left(\frac{1}{{y}^{3} \cdot {z}^{3}} + \left(\frac{1}{{y}^{2} \cdot {z}^{2}} + \left(\frac{1}{{y}^{4} \cdot {z}^{4}} + \frac{1}{y \cdot z}\right)\right)\right)}
\] |
|---|---|
distribute-neg-in [=>]53.4% | \[ \frac{x}{\color{blue}{\left(-\frac{1}{{y}^{3} \cdot {z}^{3}}\right) + \left(-\left(\frac{1}{{y}^{2} \cdot {z}^{2}} + \left(\frac{1}{{y}^{4} \cdot {z}^{4}} + \frac{1}{y \cdot z}\right)\right)\right)}}
\] |
unsub-neg [=>]53.4% | \[ \frac{x}{\color{blue}{\left(-\frac{1}{{y}^{3} \cdot {z}^{3}}\right) - \left(\frac{1}{{y}^{2} \cdot {z}^{2}} + \left(\frac{1}{{y}^{4} \cdot {z}^{4}} + \frac{1}{y \cdot z}\right)\right)}}
\] |
cube-prod [<=]53.5% | \[ \frac{x}{\left(-\frac{1}{\color{blue}{{\left(y \cdot z\right)}^{3}}}\right) - \left(\frac{1}{{y}^{2} \cdot {z}^{2}} + \left(\frac{1}{{y}^{4} \cdot {z}^{4}} + \frac{1}{y \cdot z}\right)\right)}
\] |
distribute-neg-frac [=>]53.5% | \[ \frac{x}{\color{blue}{\frac{-1}{{\left(y \cdot z\right)}^{3}}} - \left(\frac{1}{{y}^{2} \cdot {z}^{2}} + \left(\frac{1}{{y}^{4} \cdot {z}^{4}} + \frac{1}{y \cdot z}\right)\right)}
\] |
metadata-eval [=>]53.5% | \[ \frac{x}{\frac{\color{blue}{-1}}{{\left(y \cdot z\right)}^{3}} - \left(\frac{1}{{y}^{2} \cdot {z}^{2}} + \left(\frac{1}{{y}^{4} \cdot {z}^{4}} + \frac{1}{y \cdot z}\right)\right)}
\] |
Taylor expanded in y around inf 88.3%
Simplified96.1%
[Start]88.3% | \[ -1 \cdot \left(y \cdot \left(z \cdot x\right)\right) + x
\] |
|---|---|
+-commutative [=>]88.3% | \[ \color{blue}{x + -1 \cdot \left(y \cdot \left(z \cdot x\right)\right)}
\] |
mul-1-neg [=>]88.3% | \[ x + \color{blue}{\left(-y \cdot \left(z \cdot x\right)\right)}
\] |
unsub-neg [=>]88.3% | \[ \color{blue}{x - y \cdot \left(z \cdot x\right)}
\] |
*-commutative [=>]88.3% | \[ x - \color{blue}{\left(z \cdot x\right) \cdot y}
\] |
associate-*l* [=>]96.1% | \[ x - \color{blue}{z \cdot \left(x \cdot y\right)}
\] |
Final simplification97.7%
| Alternative 1 | |
|---|---|
| Accuracy | 96.8% |
| Cost | 580 |
| Alternative 2 | |
|---|---|
| Accuracy | 97.8% |
| Cost | 708 |
| Alternative 3 | |
|---|---|
| Accuracy | 73.0% |
| Cost | 649 |
| Alternative 4 | |
|---|---|
| Accuracy | 75.8% |
| Cost | 649 |
| Alternative 5 | |
|---|---|
| Accuracy | 75.0% |
| Cost | 648 |
| Alternative 6 | |
|---|---|
| Accuracy | 50.5% |
| Cost | 64 |
herbie shell --seed 2023245
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))