Average Error: 3.4 → 2.4
Time: 7.0s
Precision: binary64
Cost: 712
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
\[\begin{array}{l} t_0 := x + y \cdot \left(z \cdot x\right)\\ \mathbf{if}\;y \leq -2355102573533962:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.49982573943127834:\\ \;\;\;\;x - z \cdot x\\ \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 (* y (* z x)))))
   (if (<= y -2355102573533962.0)
     t_0
     (if (<= y 0.49982573943127834) (- x (* z 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 + (y * (z * x));
	double tmp;
	if (y <= -2355102573533962.0) {
		tmp = t_0;
	} else if (y <= 0.49982573943127834) {
		tmp = x - (z * 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 + (y * (z * x))
    if (y <= (-2355102573533962.0d0)) then
        tmp = t_0
    else if (y <= 0.49982573943127834d0) then
        tmp = x - (z * 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 + (y * (z * x));
	double tmp;
	if (y <= -2355102573533962.0) {
		tmp = t_0;
	} else if (y <= 0.49982573943127834) {
		tmp = x - (z * 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 + (y * (z * x))
	tmp = 0
	if y <= -2355102573533962.0:
		tmp = t_0
	elif y <= 0.49982573943127834:
		tmp = x - (z * 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(y * Float64(z * x)))
	tmp = 0.0
	if (y <= -2355102573533962.0)
		tmp = t_0;
	elseif (y <= 0.49982573943127834)
		tmp = Float64(x - Float64(z * 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 + (y * (z * x));
	tmp = 0.0;
	if (y <= -2355102573533962.0)
		tmp = t_0;
	elseif (y <= 0.49982573943127834)
		tmp = x - (z * 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[(y * N[(z * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2355102573533962.0], t$95$0, If[LessEqual[y, 0.49982573943127834], N[(x - N[(z * x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
t_0 := x + y \cdot \left(z \cdot x\right)\\
\mathbf{if}\;y \leq -2355102573533962:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 0.49982573943127834:\\
\;\;\;\;x - z \cdot x\\

\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.3
Herbie2.4
\[\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 y < -2355102573533962 or 0.499825739431278337 < y

    1. Initial program 7.9

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, x \cdot y - x, x\right)} \]
    3. Taylor expanded in z around 0 8.1

      \[\leadsto \color{blue}{\left(y \cdot x - x\right) \cdot z + x} \]
    4. Taylor expanded in y around inf 4.2

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

    if -2355102573533962 < y < 0.499825739431278337

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, x \cdot y - x, x\right)} \]
    3. Taylor expanded in y around 0 0.9

      \[\leadsto \color{blue}{-1 \cdot \left(z \cdot x\right) + x} \]
    4. Simplified0.9

      \[\leadsto \color{blue}{x - x \cdot z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification2.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2355102573533962:\\ \;\;\;\;x + y \cdot \left(z \cdot x\right)\\ \mathbf{elif}\;y \leq 0.49982573943127834:\\ \;\;\;\;x - z \cdot x\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(z \cdot x\right)\\ \end{array} \]

Alternatives

Alternative 1
Error21.3
Cost1112
\[\begin{array}{l} t_0 := z \cdot \left(-x\right)\\ t_1 := z \cdot \left(y \cdot x\right)\\ \mathbf{if}\;z \leq -5.8 \cdot 10^{+186}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.2 \cdot 10^{+105}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.55 \cdot 10^{+28}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.8440667262099275:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.777232188605324 \cdot 10^{-14}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.6 \cdot 10^{+180}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error11.9
Cost848
\[\begin{array}{l} t_0 := z \cdot \left(y \cdot x\right)\\ \mathbf{if}\;y \leq -2.2638543130332096 \cdot 10^{+41}:\\ \;\;\;\;y \cdot \left(z \cdot x\right)\\ \mathbf{elif}\;y \leq 2009362665475139000:\\ \;\;\;\;x - z \cdot x\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{+136}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{+192}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error11.9
Cost848
\[\begin{array}{l} \mathbf{if}\;y \leq -2.2638543130332096 \cdot 10^{+41}:\\ \;\;\;\;y \cdot \left(z \cdot x\right)\\ \mathbf{elif}\;y \leq 422554249.6120175:\\ \;\;\;\;x - z \cdot x\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{+136}:\\ \;\;\;\;z \cdot \left(y \cdot x - x\right)\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{+192}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(y \cdot x\right)\\ \end{array} \]
Alternative 4
Error19.2
Cost520
\[\begin{array}{l} t_0 := z \cdot \left(-x\right)\\ \mathbf{if}\;z \leq -20488.52853859795:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.003565542402349825:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error33.6
Cost64
\[x \]

Error

Reproduce

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