| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 1352 |
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
(FPCore (x y z)
:precision binary64
(if (<= z -1.42e-5)
(- x (/ (* z x) (/ 1.0 (- 1.0 y))))
(if (<= z 2e-25)
(* x (+ 1.0 (* z (+ y -1.0))))
(+ x (* z (* x (+ y -1.0)))))))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 (z <= -1.42e-5) {
tmp = x - ((z * x) / (1.0 / (1.0 - y)));
} else if (z <= 2e-25) {
tmp = x * (1.0 + (z * (y + -1.0)));
} else {
tmp = x + (z * (x * (y + -1.0)));
}
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 - ((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.42d-5)) then
tmp = x - ((z * x) / (1.0d0 / (1.0d0 - y)))
else if (z <= 2d-25) then
tmp = x * (1.0d0 + (z * (y + (-1.0d0))))
else
tmp = x + (z * (x * (y + (-1.0d0))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
return x * (1.0 - ((1.0 - y) * z));
}
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.42e-5) {
tmp = x - ((z * x) / (1.0 / (1.0 - y)));
} else if (z <= 2e-25) {
tmp = x * (1.0 + (z * (y + -1.0)));
} else {
tmp = x + (z * (x * (y + -1.0)));
}
return tmp;
}
def code(x, y, z): return x * (1.0 - ((1.0 - y) * z))
def code(x, y, z): tmp = 0 if z <= -1.42e-5: tmp = x - ((z * x) / (1.0 / (1.0 - y))) elif z <= 2e-25: tmp = x * (1.0 + (z * (y + -1.0))) else: tmp = x + (z * (x * (y + -1.0))) 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 (z <= -1.42e-5) tmp = Float64(x - Float64(Float64(z * x) / Float64(1.0 / Float64(1.0 - y)))); elseif (z <= 2e-25) tmp = Float64(x * Float64(1.0 + Float64(z * Float64(y + -1.0)))); else tmp = Float64(x + Float64(z * Float64(x * Float64(y + -1.0)))); end return tmp end
function tmp = code(x, y, z) tmp = x * (1.0 - ((1.0 - y) * z)); end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.42e-5) tmp = x - ((z * x) / (1.0 / (1.0 - y))); elseif (z <= 2e-25) tmp = x * (1.0 + (z * (y + -1.0))); else tmp = x + (z * (x * (y + -1.0))); end tmp_2 = 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[z, -1.42e-5], N[(x - N[(N[(z * x), $MachinePrecision] / N[(1.0 / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2e-25], N[(x * N[(1.0 + N[(z * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \leq -1.42 \cdot 10^{-5}:\\
\;\;\;\;x - \frac{z \cdot x}{\frac{1}{1 - y}}\\
\mathbf{elif}\;z \leq 2 \cdot 10^{-25}:\\
\;\;\;\;x \cdot \left(1 + z \cdot \left(y + -1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \left(x \cdot \left(y + -1\right)\right)\\
\end{array}
Results
| Original | 3.3 |
|---|---|
| Target | 0.2 |
| Herbie | 0.1 |
if z < -1.42e-5Initial program 7.9
Simplified7.9
[Start]7.9 | \[ x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\] |
|---|---|
*-commutative [=>]7.9 | \[ x \cdot \left(1 - \color{blue}{z \cdot \left(1 - y\right)}\right)
\] |
sub-neg [=>]7.9 | \[ x \cdot \left(1 - z \cdot \color{blue}{\left(1 + \left(-y\right)\right)}\right)
\] |
distribute-rgt-in [=>]7.9 | \[ x \cdot \left(1 - \color{blue}{\left(1 \cdot z + \left(-y\right) \cdot z\right)}\right)
\] |
associate--r+ [=>]7.9 | \[ x \cdot \color{blue}{\left(\left(1 - 1 \cdot z\right) - \left(-y\right) \cdot z\right)}
\] |
*-lft-identity [=>]7.9 | \[ x \cdot \left(\left(1 - \color{blue}{z}\right) - \left(-y\right) \cdot z\right)
\] |
sub-neg [=>]7.9 | \[ x \cdot \left(\color{blue}{\left(1 + \left(-z\right)\right)} - \left(-y\right) \cdot z\right)
\] |
distribute-lft-out-- [<=]7.9 | \[ \color{blue}{x \cdot \left(1 + \left(-z\right)\right) - x \cdot \left(\left(-y\right) \cdot z\right)}
\] |
distribute-lft-in [=>]7.9 | \[ \color{blue}{\left(x \cdot 1 + x \cdot \left(-z\right)\right)} - x \cdot \left(\left(-y\right) \cdot z\right)
\] |
*-rgt-identity [=>]7.9 | \[ \left(\color{blue}{x} + x \cdot \left(-z\right)\right) - x \cdot \left(\left(-y\right) \cdot z\right)
\] |
+-commutative [=>]7.9 | \[ \color{blue}{\left(x \cdot \left(-z\right) + x\right)} - x \cdot \left(\left(-y\right) \cdot z\right)
\] |
associate-+r- [<=]7.9 | \[ \color{blue}{x \cdot \left(-z\right) + \left(x - x \cdot \left(\left(-y\right) \cdot z\right)\right)}
\] |
*-commutative [=>]7.9 | \[ x \cdot \left(-z\right) + \left(x - \color{blue}{\left(\left(-y\right) \cdot z\right) \cdot x}\right)
\] |
cancel-sign-sub-inv [=>]7.9 | \[ x \cdot \left(-z\right) + \color{blue}{\left(x + \left(-\left(-y\right) \cdot z\right) \cdot x\right)}
\] |
distribute-rgt-neg-in [=>]7.9 | \[ x \cdot \left(-z\right) + \left(x + \color{blue}{\left(\left(-y\right) \cdot \left(-z\right)\right)} \cdot x\right)
\] |
distribute-rgt1-in [=>]7.9 | \[ x \cdot \left(-z\right) + \color{blue}{\left(\left(-y\right) \cdot \left(-z\right) + 1\right) \cdot x}
\] |
*-commutative [=>]7.9 | \[ x \cdot \left(-z\right) + \color{blue}{x \cdot \left(\left(-y\right) \cdot \left(-z\right) + 1\right)}
\] |
+-commutative [=>]7.9 | \[ \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 0.1
Simplified0.1
[Start]0.1 | \[ -1 \cdot \left(\left(1 + -1 \cdot y\right) \cdot \left(z \cdot x\right)\right) + x
\] |
|---|---|
+-commutative [=>]0.1 | \[ \color{blue}{x + -1 \cdot \left(\left(1 + -1 \cdot y\right) \cdot \left(z \cdot x\right)\right)}
\] |
mul-1-neg [=>]0.1 | \[ x + \color{blue}{\left(-\left(1 + -1 \cdot y\right) \cdot \left(z \cdot x\right)\right)}
\] |
unsub-neg [=>]0.1 | \[ \color{blue}{x - \left(1 + -1 \cdot y\right) \cdot \left(z \cdot x\right)}
\] |
associate-*r* [=>]7.9 | \[ x - \color{blue}{\left(\left(1 + -1 \cdot y\right) \cdot z\right) \cdot x}
\] |
*-commutative [=>]7.9 | \[ 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)
\] |
Applied egg-rr0.2
if -1.42e-5 < z < 2.00000000000000008e-25Initial program 0.1
if 2.00000000000000008e-25 < z Initial program 7.4
Simplified7.4
[Start]7.4 | \[ x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\] |
|---|---|
*-commutative [=>]7.4 | \[ x \cdot \left(1 - \color{blue}{z \cdot \left(1 - y\right)}\right)
\] |
sub-neg [=>]7.4 | \[ x \cdot \left(1 - z \cdot \color{blue}{\left(1 + \left(-y\right)\right)}\right)
\] |
distribute-rgt-in [=>]7.4 | \[ x \cdot \left(1 - \color{blue}{\left(1 \cdot z + \left(-y\right) \cdot z\right)}\right)
\] |
associate--r+ [=>]7.4 | \[ x \cdot \color{blue}{\left(\left(1 - 1 \cdot z\right) - \left(-y\right) \cdot z\right)}
\] |
*-lft-identity [=>]7.4 | \[ x \cdot \left(\left(1 - \color{blue}{z}\right) - \left(-y\right) \cdot z\right)
\] |
sub-neg [=>]7.4 | \[ x \cdot \left(\color{blue}{\left(1 + \left(-z\right)\right)} - \left(-y\right) \cdot z\right)
\] |
distribute-lft-out-- [<=]7.4 | \[ \color{blue}{x \cdot \left(1 + \left(-z\right)\right) - x \cdot \left(\left(-y\right) \cdot z\right)}
\] |
distribute-lft-in [=>]7.4 | \[ \color{blue}{\left(x \cdot 1 + x \cdot \left(-z\right)\right)} - x \cdot \left(\left(-y\right) \cdot z\right)
\] |
*-rgt-identity [=>]7.4 | \[ \left(\color{blue}{x} + x \cdot \left(-z\right)\right) - x \cdot \left(\left(-y\right) \cdot z\right)
\] |
+-commutative [=>]7.4 | \[ \color{blue}{\left(x \cdot \left(-z\right) + x\right)} - x \cdot \left(\left(-y\right) \cdot z\right)
\] |
associate-+r- [<=]7.4 | \[ \color{blue}{x \cdot \left(-z\right) + \left(x - x \cdot \left(\left(-y\right) \cdot z\right)\right)}
\] |
*-commutative [=>]7.4 | \[ x \cdot \left(-z\right) + \left(x - \color{blue}{\left(\left(-y\right) \cdot z\right) \cdot x}\right)
\] |
cancel-sign-sub-inv [=>]7.4 | \[ x \cdot \left(-z\right) + \color{blue}{\left(x + \left(-\left(-y\right) \cdot z\right) \cdot x\right)}
\] |
distribute-rgt-neg-in [=>]7.4 | \[ x \cdot \left(-z\right) + \left(x + \color{blue}{\left(\left(-y\right) \cdot \left(-z\right)\right)} \cdot x\right)
\] |
distribute-rgt1-in [=>]7.4 | \[ x \cdot \left(-z\right) + \color{blue}{\left(\left(-y\right) \cdot \left(-z\right) + 1\right) \cdot x}
\] |
*-commutative [=>]7.4 | \[ x \cdot \left(-z\right) + \color{blue}{x \cdot \left(\left(-y\right) \cdot \left(-z\right) + 1\right)}
\] |
+-commutative [=>]7.4 | \[ \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 0.1
Simplified0.3
[Start]0.1 | \[ -1 \cdot \left(\left(1 + -1 \cdot y\right) \cdot \left(z \cdot x\right)\right) + x
\] |
|---|---|
+-commutative [=>]0.1 | \[ \color{blue}{x + -1 \cdot \left(\left(1 + -1 \cdot y\right) \cdot \left(z \cdot x\right)\right)}
\] |
mul-1-neg [=>]0.1 | \[ x + \color{blue}{\left(-\left(1 + -1 \cdot y\right) \cdot \left(z \cdot x\right)\right)}
\] |
unsub-neg [=>]0.1 | \[ \color{blue}{x - \left(1 + -1 \cdot y\right) \cdot \left(z \cdot x\right)}
\] |
associate-*r* [=>]7.4 | \[ x - \color{blue}{\left(\left(1 + -1 \cdot y\right) \cdot z\right) \cdot x}
\] |
*-commutative [=>]7.4 | \[ x - \color{blue}{\left(z \cdot \left(1 + -1 \cdot y\right)\right)} \cdot x
\] |
associate-*l* [=>]0.3 | \[ x - \color{blue}{z \cdot \left(\left(1 + -1 \cdot y\right) \cdot x\right)}
\] |
mul-1-neg [=>]0.3 | \[ x - z \cdot \left(\left(1 + \color{blue}{\left(-y\right)}\right) \cdot x\right)
\] |
unsub-neg [=>]0.3 | \[ x - z \cdot \left(\color{blue}{\left(1 - y\right)} \cdot x\right)
\] |
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 1352 |
| Alternative 2 | |
|---|---|
| Error | 0.1 |
| Cost | 841 |
| Alternative 3 | |
|---|---|
| Error | 0.1 |
| Cost | 840 |
| Alternative 4 | |
|---|---|
| Error | 12.4 |
| Cost | 713 |
| Alternative 5 | |
|---|---|
| Error | 9.2 |
| Cost | 713 |
| Alternative 6 | |
|---|---|
| Error | 0.9 |
| Cost | 713 |
| Alternative 7 | |
|---|---|
| Error | 0.9 |
| Cost | 712 |
| Alternative 8 | |
|---|---|
| Error | 19.4 |
| Cost | 652 |
| Alternative 9 | |
|---|---|
| Error | 19.4 |
| Cost | 652 |
| Alternative 10 | |
|---|---|
| Error | 12.2 |
| Cost | 584 |
| Alternative 11 | |
|---|---|
| Error | 12.2 |
| Cost | 584 |
| Alternative 12 | |
|---|---|
| Error | 19.7 |
| Cost | 521 |
| Alternative 13 | |
|---|---|
| Error | 33.3 |
| Cost | 64 |
herbie shell --seed 2023059
(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))))