Average Error: 3.3 → 0.7
Time: 10.3s
Precision: binary64
Cost: 840
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
\[\begin{array}{l} t_0 := x - z \cdot \left(x \cdot \left(1 - y\right)\right)\\ \mathbf{if}\;z \leq -3.890153177467269 \cdot 10^{-114}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.726291940718604 \cdot 10^{-100}:\\ \;\;\;\;x + x \cdot \left(y \cdot z\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 (* z (* x (- 1.0 y))))))
   (if (<= z -3.890153177467269e-114)
     t_0
     (if (<= z 5.726291940718604e-100) (+ x (* x (* y z))) 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 - (z * (x * (1.0 - y)));
	double tmp;
	if (z <= -3.890153177467269e-114) {
		tmp = t_0;
	} else if (z <= 5.726291940718604e-100) {
		tmp = x + (x * (y * z));
	} 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 - (z * (x * (1.0d0 - y)))
    if (z <= (-3.890153177467269d-114)) then
        tmp = t_0
    else if (z <= 5.726291940718604d-100) then
        tmp = x + (x * (y * z))
    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 - (z * (x * (1.0 - y)));
	double tmp;
	if (z <= -3.890153177467269e-114) {
		tmp = t_0;
	} else if (z <= 5.726291940718604e-100) {
		tmp = x + (x * (y * z));
	} 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 - (z * (x * (1.0 - y)))
	tmp = 0
	if z <= -3.890153177467269e-114:
		tmp = t_0
	elif z <= 5.726291940718604e-100:
		tmp = x + (x * (y * z))
	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(z * Float64(x * Float64(1.0 - y))))
	tmp = 0.0
	if (z <= -3.890153177467269e-114)
		tmp = t_0;
	elseif (z <= 5.726291940718604e-100)
		tmp = Float64(x + Float64(x * Float64(y * z)));
	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 - (z * (x * (1.0 - y)));
	tmp = 0.0;
	if (z <= -3.890153177467269e-114)
		tmp = t_0;
	elseif (z <= 5.726291940718604e-100)
		tmp = x + (x * (y * z));
	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[(z * N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -3.890153177467269e-114], t$95$0, If[LessEqual[z, 5.726291940718604e-100], N[(x + N[(x * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
t_0 := x - z \cdot \left(x \cdot \left(1 - y\right)\right)\\
\mathbf{if}\;z \leq -3.890153177467269 \cdot 10^{-114}:\\
\;\;\;\;t_0\\

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

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original3.3
Target0.2
Herbie0.7
\[\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 z < -3.8901531774672687e-114 or 5.72629194071860393e-100 < z

    1. Initial program 5.4

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

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

    if -3.8901531774672687e-114 < z < 5.72629194071860393e-100

    1. Initial program 0.0

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

      \[\leadsto x \cdot \left(1 - \color{blue}{-1 \cdot \left(y \cdot z\right)}\right) \]
    3. Simplified0.0

      \[\leadsto x \cdot \left(1 - \color{blue}{y \cdot \left(-z\right)}\right) \]
      Proof
      (*.f64 y (neg.f64 z)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 y z))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (*.f64 y z))): 0 points increase in error, 0 points decrease in error
    4. Applied egg-rr0.0

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

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

Alternatives

Alternative 1
Error0.2
Cost13448
\[\begin{array}{l} t_0 := \mathsf{fma}\left(x, \mathsf{fma}\left(y, z, -z\right), x\right)\\ \mathbf{if}\;x \leq -1 \cdot 10^{+46}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 10^{+52}:\\ \;\;\;\;x - z \cdot \left(x \cdot \left(1 - y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error12.6
Cost848
\[\begin{array}{l} \mathbf{if}\;y \leq -59112491098.83583:\\ \;\;\;\;y \cdot \left(x \cdot z\right)\\ \mathbf{elif}\;y \leq 2.7589720906385247 \cdot 10^{+46}:\\ \;\;\;\;x - x \cdot z\\ \mathbf{elif}\;y \leq 3.0505171212470736 \cdot 10^{+56}:\\ \;\;\;\;z \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;y \leq 1.9 \cdot 10^{+93}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y \cdot z\right)\\ \end{array} \]
Alternative 3
Error0.2
Cost840
\[\begin{array}{l} t_0 := x \cdot \left(1 + z \cdot \left(y + -1\right)\right)\\ \mathbf{if}\;x \leq -1 \cdot 10^{+46}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 10^{+52}:\\ \;\;\;\;x - z \cdot \left(x \cdot \left(1 - y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error4.1
Cost712
\[\begin{array}{l} t_0 := x + x \cdot \left(y \cdot z\right)\\ \mathbf{if}\;y \leq -29206476.914263066:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.044394713733484935:\\ \;\;\;\;x - x \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error1.0
Cost712
\[\begin{array}{l} t_0 := \left(y + -1\right) \cdot \left(x \cdot z\right)\\ \mathbf{if}\;z \leq -25.552361768011703:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.827764119351436 \cdot 10^{-8}:\\ \;\;\;\;x + x \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error1.0
Cost712
\[\begin{array}{l} t_0 := z \cdot \left(x \cdot \left(y + -1\right)\right)\\ \mathbf{if}\;z \leq -25.552361768011703:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.827764119351436 \cdot 10^{-8}:\\ \;\;\;\;x + x \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error18.8
Cost520
\[\begin{array}{l} t_0 := x \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -25.552361768011703:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 8.640531797436794 \cdot 10^{-8}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error32.7
Cost64
\[x \]

Error

Reproduce

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