Average Error: 3.4 → 1.2
Time: 6.8s
Precision: binary64
Cost: 840
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
\[\begin{array}{l} t_0 := x \cdot \left(1 + z \cdot \left(y + -1\right)\right)\\ \mathbf{if}\;x \leq -1 \cdot 10^{+138}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.5524451704913054 \cdot 10^{-168}:\\ \;\;\;\;x + z \cdot \left(x \cdot y - x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (+ 1.0 (* z (+ y -1.0))))))
   (if (<= x -1e+138)
     t_0
     (if (<= x 1.5524451704913054e-168) (+ x (* z (- (* x y) x))) t_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 t_0 = x * (1.0 + (z * (y + -1.0)));
	double tmp;
	if (x <= -1e+138) {
		tmp = t_0;
	} else if (x <= 1.5524451704913054e-168) {
		tmp = x + (z * ((x * y) - x));
	} else {
		tmp = t_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) :: t_0
    real(8) :: tmp
    t_0 = x * (1.0d0 + (z * (y + (-1.0d0))))
    if (x <= (-1d+138)) then
        tmp = t_0
    else if (x <= 1.5524451704913054d-168) then
        tmp = x + (z * ((x * y) - x))
    else
        tmp = t_0
    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 t_0 = x * (1.0 + (z * (y + -1.0)));
	double tmp;
	if (x <= -1e+138) {
		tmp = t_0;
	} else if (x <= 1.5524451704913054e-168) {
		tmp = x + (z * ((x * y) - x));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	return x * (1.0 - ((1.0 - y) * z))
def code(x, y, z):
	t_0 = x * (1.0 + (z * (y + -1.0)))
	tmp = 0
	if x <= -1e+138:
		tmp = t_0
	elif x <= 1.5524451704913054e-168:
		tmp = x + (z * ((x * y) - x))
	else:
		tmp = t_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)
	t_0 = Float64(x * Float64(1.0 + Float64(z * Float64(y + -1.0))))
	tmp = 0.0
	if (x <= -1e+138)
		tmp = t_0;
	elseif (x <= 1.5524451704913054e-168)
		tmp = Float64(x + Float64(z * Float64(Float64(x * y) - x)));
	else
		tmp = t_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)
	t_0 = x * (1.0 + (z * (y + -1.0)));
	tmp = 0.0;
	if (x <= -1e+138)
		tmp = t_0;
	elseif (x <= 1.5524451704913054e-168)
		tmp = x + (z * ((x * y) - x));
	else
		tmp = t_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_] := Block[{t$95$0 = N[(x * N[(1.0 + N[(z * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1e+138], t$95$0, If[LessEqual[x, 1.5524451704913054e-168], N[(x + N[(z * N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
t_0 := x \cdot \left(1 + z \cdot \left(y + -1\right)\right)\\
\mathbf{if}\;x \leq -1 \cdot 10^{+138}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 1.5524451704913054 \cdot 10^{-168}:\\
\;\;\;\;x + z \cdot \left(x \cdot y - x\right)\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original3.4
Target0.2
Herbie1.2
\[\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 2 regimes
  2. if x < -1e138 or 1.5524451704913054e-168 < x

    1. Initial program 1.5

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

    if -1e138 < x < 1.5524451704913054e-168

    1. Initial program 4.9

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
    2. Simplified1.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, x \cdot y - x, x\right)} \]
    3. Applied egg-rr1.0

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

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

Alternatives

Alternative 1
Error20.6
Cost980
\[\begin{array}{l} t_0 := x \cdot \left(-z\right)\\ t_1 := x \cdot \left(y \cdot z\right)\\ \mathbf{if}\;z \leq -58000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.3208976595093053 \cdot 10^{-71}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1100:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4.4 \cdot 10^{+44}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 9 \cdot 10^{+71}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error20.7
Cost980
\[\begin{array}{l} t_0 := x \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -58000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.3208976595093053 \cdot 10^{-71}:\\ \;\;\;\;z \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;z \leq 1100:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4.4 \cdot 10^{+44}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 9 \cdot 10^{+71}:\\ \;\;\;\;x \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.2
Cost840
\[\begin{array}{l} t_0 := x + z \cdot \left(x \cdot y - x\right)\\ \mathbf{if}\;z \leq -4.0483219142097575 \cdot 10^{-61}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 10^{-20}:\\ \;\;\;\;x + x \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error2.2
Cost712
\[\begin{array}{l} t_0 := x + y \cdot \left(x \cdot z\right)\\ \mathbf{if}\;y \leq -2.285844912751982:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.014191937481997147:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error3.1
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -2.285844912751982:\\ \;\;\;\;x + y \cdot \left(x \cdot z\right)\\ \mathbf{elif}\;y \leq 0.014191937481997147:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;x + x \cdot \left(y \cdot z\right)\\ \end{array} \]
Alternative 6
Error1.0
Cost712
\[\begin{array}{l} t_0 := z \cdot \left(x \cdot y - x\right)\\ \mathbf{if}\;z \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x + x \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error12.3
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -3.2 \cdot 10^{+87}:\\ \;\;\;\;z \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;y \leq 51746012972654550:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y \cdot z\right)\\ \end{array} \]
Alternative 8
Error12.2
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -3.2 \cdot 10^{+87}:\\ \;\;\;\;y \cdot \left(x \cdot z\right)\\ \mathbf{elif}\;y \leq 51746012972654550:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y \cdot z\right)\\ \end{array} \]
Alternative 9
Error19.2
Cost520
\[\begin{array}{l} t_0 := x \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1100:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error33.1
Cost64
\[x \]

Error

Reproduce

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