?

Average Error: 3.3 → 0.3
Time: 12.4s
Precision: binary64
Cost: 968

?

\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
\[\begin{array}{l} \mathbf{if}\;x \leq -6 \cdot 10^{+60}:\\ \;\;\;\;x + x \cdot \left(z \cdot \left(y + -1\right)\right)\\ \mathbf{elif}\;x \leq 2 \cdot 10^{-137}:\\ \;\;\;\;z \cdot \left(\left(y - 1\right) \cdot x\right) + x\\ \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 (<= x -6e+60)
   (+ x (* x (* z (+ y -1.0))))
   (if (<= x 2e-137)
     (+ (* z (* (- y 1.0) x)) x)
     (+ (* 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 (x <= -6e+60) {
		tmp = x + (x * (z * (y + -1.0)));
	} else if (x <= 2e-137) {
		tmp = (z * ((y - 1.0) * x)) + x;
	} 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 (x <= (-6d+60)) then
        tmp = x + (x * (z * (y + (-1.0d0))))
    else if (x <= 2d-137) then
        tmp = (z * ((y - 1.0d0) * x)) + x
    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 (x <= -6e+60) {
		tmp = x + (x * (z * (y + -1.0)));
	} else if (x <= 2e-137) {
		tmp = (z * ((y - 1.0) * x)) + x;
	} 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 x <= -6e+60:
		tmp = x + (x * (z * (y + -1.0)))
	elif x <= 2e-137:
		tmp = (z * ((y - 1.0) * x)) + x
	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 (x <= -6e+60)
		tmp = Float64(x + Float64(x * Float64(z * Float64(y + -1.0))));
	elseif (x <= 2e-137)
		tmp = Float64(Float64(z * Float64(Float64(y - 1.0) * x)) + x);
	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 (x <= -6e+60)
		tmp = x + (x * (z * (y + -1.0)));
	elseif (x <= 2e-137)
		tmp = (z * ((y - 1.0) * x)) + x;
	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[x, -6e+60], N[(x + N[(x * N[(z * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2e-137], N[(N[(z * N[(N[(y - 1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] + x), $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}\;x \leq -6 \cdot 10^{+60}:\\
\;\;\;\;x + x \cdot \left(z \cdot \left(y + -1\right)\right)\\

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

\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.3
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 x < -5.9999999999999997e60

    1. Initial program 0.1

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

      \[\leadsto \color{blue}{y \cdot \left(z \cdot x\right) + \left(1 - z\right) \cdot x} \]
    3. Taylor expanded in z around 0 12.1

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

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

      [Start]12.1

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

      rational.json-simplify-1 [=>]12.1

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

      rational.json-simplify-2 [=>]12.1

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

      rational.json-simplify-47 [=>]12.1

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

      rational.json-simplify-43 [=>]0.1

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

      rational.json-simplify-2 [=>]0.1

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

      rational.json-simplify-1 [=>]0.1

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

    if -5.9999999999999997e60 < x < 1.99999999999999996e-137

    1. Initial program 5.2

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

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

    if 1.99999999999999996e-137 < x

    1. Initial program 1.6

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

      \[\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}\;x \leq -6 \cdot 10^{+60}:\\ \;\;\;\;x + x \cdot \left(z \cdot \left(y + -1\right)\right)\\ \mathbf{elif}\;x \leq 2 \cdot 10^{-137}:\\ \;\;\;\;z \cdot \left(\left(y - 1\right) \cdot x\right) + x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(z \cdot x\right) + \left(1 - z\right) \cdot x\\ \end{array} \]

Alternatives

Alternative 1
Error29.1
Cost1640
\[\begin{array}{l} t_0 := z \cdot \left(-x\right)\\ t_1 := x \cdot \left(z \cdot y\right)\\ \mathbf{if}\;y \leq -3.65 \cdot 10^{+37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3.05 \cdot 10^{-18}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -9 \cdot 10^{-114}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -5.5 \cdot 10^{-212}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -7.8 \cdot 10^{-258}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -4.2 \cdot 10^{-288}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -7.5 \cdot 10^{-307}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.9 \cdot 10^{-164}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.22 \cdot 10^{-123}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 5.2 \cdot 10^{+46}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error28.3
Cost1640
\[\begin{array}{l} t_0 := z \cdot \left(-x\right)\\ \mathbf{if}\;y \leq -3.4 \cdot 10^{+37}:\\ \;\;\;\;x \cdot \left(z \cdot y\right)\\ \mathbf{elif}\;y \leq -7.3 \cdot 10^{-19}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -9 \cdot 10^{-114}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -4.6 \cdot 10^{-212}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -6.8 \cdot 10^{-258}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.1 \cdot 10^{-288}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{-307}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{-164}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{-124}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 7 \cdot 10^{+45}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(y \cdot x\right)\\ \end{array} \]
Alternative 3
Error0.4
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{+62}:\\ \;\;\;\;x + x \cdot \left(z \cdot \left(y + -1\right)\right)\\ \mathbf{elif}\;x \leq 6.8 \cdot 10^{-69}:\\ \;\;\;\;z \cdot \left(\left(y - 1\right) \cdot x\right) + x\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\ \end{array} \]
Alternative 4
Error1.0
Cost712
\[\begin{array}{l} t_0 := z \cdot \left(\left(y - 1\right) \cdot x\right)\\ \mathbf{if}\;z \leq -4200000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.165:\\ \;\;\;\;x + x \cdot \left(z \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error2.1
Cost708
\[\begin{array}{l} \mathbf{if}\;z \leq -4 \cdot 10^{+136}:\\ \;\;\;\;z \cdot \left(\left(y - 1\right) \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\ \end{array} \]
Alternative 6
Error12.3
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -2.6 \cdot 10^{+37}:\\ \;\;\;\;x \cdot \left(z \cdot y\right)\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{+47}:\\ \;\;\;\;\left(1 - z\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(y \cdot x\right)\\ \end{array} \]
Alternative 7
Error19.4
Cost520
\[\begin{array}{l} t_0 := z \cdot \left(-x\right)\\ \mathbf{if}\;z \leq -4200000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error33.3
Cost64
\[x \]

Error

Reproduce?

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