?

Average Error: 3.2 → 0.3
Time: 15.5s
Precision: binary64
Cost: 968

?

\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
\[\begin{array}{l} \mathbf{if}\;z \leq -9500000000000:\\ \;\;\;\;z \cdot \left(\left(y - 1\right) \cdot x\right) + x\\ \mathbf{elif}\;z \leq 10^{-105}:\\ \;\;\;\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(z \cdot x\right) + \left(1 - z\right) \cdot x\\ \end{array} \]
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
(FPCore (x y z)
 :precision binary64
 (if (<= z -9500000000000.0)
   (+ (* z (* (- y 1.0) x)) x)
   (if (<= z 1e-105)
     (* x (- 1.0 (* (- 1.0 y) z)))
     (+ (* y (* z x)) (* (- 1.0 z) x)))))
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 <= -9500000000000.0) {
		tmp = (z * ((y - 1.0) * x)) + x;
	} else if (z <= 1e-105) {
		tmp = x * (1.0 - ((1.0 - y) * z));
	} else {
		tmp = (y * (z * x)) + ((1.0 - 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 - ((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 <= (-9500000000000.0d0)) then
        tmp = (z * ((y - 1.0d0) * x)) + x
    else if (z <= 1d-105) then
        tmp = x * (1.0d0 - ((1.0d0 - y) * z))
    else
        tmp = (y * (z * x)) + ((1.0d0 - z) * x)
    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 <= -9500000000000.0) {
		tmp = (z * ((y - 1.0) * x)) + x;
	} else if (z <= 1e-105) {
		tmp = x * (1.0 - ((1.0 - y) * z));
	} else {
		tmp = (y * (z * x)) + ((1.0 - z) * x);
	}
	return tmp;
}
def code(x, y, z):
	return x * (1.0 - ((1.0 - y) * z))
def code(x, y, z):
	tmp = 0
	if z <= -9500000000000.0:
		tmp = (z * ((y - 1.0) * x)) + x
	elif z <= 1e-105:
		tmp = x * (1.0 - ((1.0 - y) * z))
	else:
		tmp = (y * (z * x)) + ((1.0 - z) * x)
	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 <= -9500000000000.0)
		tmp = Float64(Float64(z * Float64(Float64(y - 1.0) * x)) + x);
	elseif (z <= 1e-105)
		tmp = Float64(x * Float64(1.0 - Float64(Float64(1.0 - y) * z)));
	else
		tmp = Float64(Float64(y * Float64(z * x)) + Float64(Float64(1.0 - z) * x));
	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 <= -9500000000000.0)
		tmp = (z * ((y - 1.0) * x)) + x;
	elseif (z <= 1e-105)
		tmp = x * (1.0 - ((1.0 - y) * z));
	else
		tmp = (y * (z * x)) + ((1.0 - z) * x);
	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, -9500000000000.0], N[(N[(z * N[(N[(y - 1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[z, 1e-105], N[(x * N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y * N[(z * x), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \leq -9500000000000:\\
\;\;\;\;z \cdot \left(\left(y - 1\right) \cdot x\right) + x\\

\mathbf{elif}\;z \leq 10^{-105}:\\
\;\;\;\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot x\right) + \left(1 - z\right) \cdot x\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original3.2
Target0.2
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right) < -1.618195973607049 \cdot 10^{+50}:\\ \;\;\;\;x + \left(1 - y\right) \cdot \left(\left(-z\right) \cdot x\right)\\ \mathbf{elif}\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right) < 3.892237649663903 \cdot 10^{+134}:\\ \;\;\;\;\left(x \cdot y\right) \cdot z - \left(x \cdot z - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(1 - y\right) \cdot \left(\left(-z\right) \cdot x\right)\\ \end{array} \]

Derivation?

  1. Split input into 3 regimes
  2. if z < -9.5e12

    1. Initial program 8.5

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
    2. Taylor expanded in z around 0 0.1

      \[\leadsto \color{blue}{z \cdot \left(\left(y - 1\right) \cdot x\right) + x} \]

    if -9.5e12 < z < 9.99999999999999965e-106

    1. Initial program 0.1

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]

    if 9.99999999999999965e-106 < z

    1. Initial program 5.5

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
    2. Taylor expanded in y around 0 0.8

      \[\leadsto \color{blue}{y \cdot \left(z \cdot x\right) + \left(1 - z\right) \cdot x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -9500000000000:\\ \;\;\;\;z \cdot \left(\left(y - 1\right) \cdot x\right) + x\\ \mathbf{elif}\;z \leq 10^{-105}:\\ \;\;\;\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(z \cdot x\right) + \left(1 - z\right) \cdot x\\ \end{array} \]

Alternatives

Alternative 1
Error21.2
Cost1376
\[\begin{array}{l} t_0 := z \cdot \left(-x\right)\\ t_1 := y \cdot \left(z \cdot x\right)\\ \mathbf{if}\;z \leq -5.2 \cdot 10^{+93}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -8.8 \cdot 10^{+38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.85 \cdot 10^{+14}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.1 \cdot 10^{-53}:\\ \;\;\;\;x \cdot \left(z \cdot y\right)\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{-10}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 50000000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.55 \cdot 10^{+81}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.4 \cdot 10^{+216}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error21.3
Cost1376
\[\begin{array}{l} t_0 := z \cdot \left(-x\right)\\ t_1 := z \cdot \left(y \cdot x\right)\\ \mathbf{if}\;z \leq -6.5 \cdot 10^{+93}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -8.4 \cdot 10^{+46}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.85 \cdot 10^{+14}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -8.6 \cdot 10^{-57}:\\ \;\;\;\;x \cdot \left(z \cdot y\right)\\ \mathbf{elif}\;z \leq 1.1 \cdot 10^{-9}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 55000000000000:\\ \;\;\;\;y \cdot \left(z \cdot x\right)\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{+75}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.4 \cdot 10^{+214}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.2
Cost1352
\[\begin{array}{l} t_0 := \left(1 - y\right) \cdot z\\ t_1 := z \cdot \left(\left(y - 1\right) \cdot x\right)\\ \mathbf{if}\;t_0 \leq -2 \cdot 10^{+184}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 4 \cdot 10^{+175}:\\ \;\;\;\;x \cdot \left(1 - t_0\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error19.7
Cost848
\[\begin{array}{l} t_0 := z \cdot \left(-x\right)\\ t_1 := x \cdot \left(z \cdot y\right)\\ \mathbf{if}\;z \leq -3.1 \cdot 10^{+14}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -9.2 \cdot 10^{-57}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 10^{-10}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 95000000000000:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error4.2
Cost844
\[\begin{array}{l} t_0 := x \cdot \left(1 + y \cdot z\right)\\ \mathbf{if}\;y \leq -1.22 \cdot 10^{+219}:\\ \;\;\;\;z \cdot \left(y \cdot x\right)\\ \mathbf{elif}\;y \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;\left(1 - z\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error0.1
Cost840
\[\begin{array}{l} t_0 := z \cdot \left(\left(y - 1\right) \cdot x\right) + x\\ \mathbf{if}\;z \leq -50000000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 600000000000:\\ \;\;\;\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error1.3
Cost712
\[\begin{array}{l} t_0 := z \cdot \left(\left(y - 1\right) \cdot x\right)\\ \mathbf{if}\;z \leq -350000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4.6:\\ \;\;\;\;x \cdot \left(1 + y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error12.2
Cost584
\[\begin{array}{l} t_0 := z \cdot \left(y \cdot x\right)\\ \mathbf{if}\;y \leq -1 \cdot 10^{+46}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.76 \cdot 10^{+160}:\\ \;\;\;\;\left(1 - z\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error19.3
Cost520
\[\begin{array}{l} t_0 := z \cdot \left(-x\right)\\ \mathbf{if}\;z \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error33.2
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023068 
(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))))