Average Error: 3.6 → 0.1
Time: 15.1s
Precision: binary64
Cost: 840
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
\[\begin{array}{l} \mathbf{if}\;z \leq -5000000:\\ \;\;\;\;y \cdot \left(z \cdot x\right) + \left(1 - z\right) \cdot x\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{-55}:\\ \;\;\;\;x \cdot \left(z \cdot \left(y + -1\right)\right) + x\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(\left(y - 1\right) \cdot x\right) + x\\ \end{array} \]
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
(FPCore (x y z)
 :precision binary64
 (if (<= z -5000000.0)
   (+ (* y (* z x)) (* (- 1.0 z) x))
   (if (<= z 2.5e-55)
     (+ (* x (* z (+ y -1.0))) x)
     (+ (* z (* (- y 1.0) x)) 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 <= -5000000.0) {
		tmp = (y * (z * x)) + ((1.0 - z) * x);
	} else if (z <= 2.5e-55) {
		tmp = (x * (z * (y + -1.0))) + x;
	} else {
		tmp = (z * ((y - 1.0) * x)) + 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 <= (-5000000.0d0)) then
        tmp = (y * (z * x)) + ((1.0d0 - z) * x)
    else if (z <= 2.5d-55) then
        tmp = (x * (z * (y + (-1.0d0)))) + x
    else
        tmp = (z * ((y - 1.0d0) * x)) + 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 <= -5000000.0) {
		tmp = (y * (z * x)) + ((1.0 - z) * x);
	} else if (z <= 2.5e-55) {
		tmp = (x * (z * (y + -1.0))) + x;
	} else {
		tmp = (z * ((y - 1.0) * x)) + 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 <= -5000000.0:
		tmp = (y * (z * x)) + ((1.0 - z) * x)
	elif z <= 2.5e-55:
		tmp = (x * (z * (y + -1.0))) + x
	else:
		tmp = (z * ((y - 1.0) * x)) + 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 <= -5000000.0)
		tmp = Float64(Float64(y * Float64(z * x)) + Float64(Float64(1.0 - z) * x));
	elseif (z <= 2.5e-55)
		tmp = Float64(Float64(x * Float64(z * Float64(y + -1.0))) + x);
	else
		tmp = Float64(Float64(z * Float64(Float64(y - 1.0) * x)) + 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 <= -5000000.0)
		tmp = (y * (z * x)) + ((1.0 - z) * x);
	elseif (z <= 2.5e-55)
		tmp = (x * (z * (y + -1.0))) + x;
	else
		tmp = (z * ((y - 1.0) * x)) + 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, -5000000.0], N[(N[(y * N[(z * x), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.5e-55], N[(N[(x * N[(z * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(N[(z * N[(N[(y - 1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \leq -5000000:\\
\;\;\;\;y \cdot \left(z \cdot x\right) + \left(1 - z\right) \cdot x\\

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

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original3.6
Target0.2
Herbie0.1
\[\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 < -5e6

    1. Initial program 9.4

      \[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} \]

    if -5e6 < z < 2.5000000000000001e-55

    1. Initial program 0.1

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
    2. Applied egg-rr0.1

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

    if 2.5000000000000001e-55 < z

    1. Initial program 7.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} \]
    3. Simplified7.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \left(y + -1\right) \cdot z, x\right)} \]
      Proof
    4. Taylor expanded in z around 0 0.4

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

Alternatives

Alternative 1
Error26.5
Cost1112
\[\begin{array}{l} t_0 := y \cdot \left(z \cdot x\right)\\ \mathbf{if}\;y \leq -1.52 \cdot 10^{+128}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.4 \cdot 10^{-98}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -1.4 \cdot 10^{-131}:\\ \;\;\;\;-z \cdot x\\ \mathbf{elif}\;y \leq 1.26 \cdot 10^{+23}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 9.2 \cdot 10^{+51}:\\ \;\;\;\;x \cdot \left(y \cdot z\right)\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{+70}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error26.4
Cost1112
\[\begin{array}{l} t_0 := y \cdot \left(z \cdot x\right)\\ \mathbf{if}\;y \leq -1.18 \cdot 10^{+128}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.52 \cdot 10^{-99}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -1.05 \cdot 10^{-131}:\\ \;\;\;\;-z \cdot x\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{+25}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.45 \cdot 10^{+51}:\\ \;\;\;\;\left(x \cdot y\right) \cdot z\\ \mathbf{elif}\;y \leq 5.2 \cdot 10^{+69}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error21.5
Cost1048
\[\begin{array}{l} t_0 := -z \cdot x\\ t_1 := x \cdot \left(y \cdot z\right)\\ \mathbf{if}\;z \leq -2.7 \cdot 10^{+49}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.2 \cdot 10^{+31}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2 \cdot 10^{-68}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -2.2 \cdot 10^{-131}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7.8 \cdot 10^{-5}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error10.7
Cost976
\[\begin{array}{l} t_0 := \left(1 - z\right) \cdot x\\ t_1 := z \cdot \left(\left(y - 1\right) \cdot x\right)\\ \mathbf{if}\;z \leq -4.4 \cdot 10^{+16}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -7 \cdot 10^{-69}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.2 \cdot 10^{-131}:\\ \;\;\;\;x \cdot \left(y \cdot z\right)\\ \mathbf{elif}\;z \leq 10^{-14}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error11.0
Cost976
\[\begin{array}{l} t_0 := \left(1 - z\right) \cdot x\\ t_1 := \left(z \cdot x\right) \cdot \left(y + -1\right)\\ \mathbf{if}\;z \leq -4.4 \cdot 10^{+16}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.2 \cdot 10^{-57}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.2 \cdot 10^{-131}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 10^{-14}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(\left(y - 1\right) \cdot x\right)\\ \end{array} \]
Alternative 6
Error11.8
Cost848
\[\begin{array}{l} t_0 := y \cdot \left(z \cdot x\right)\\ \mathbf{if}\;y \leq -3.3 \cdot 10^{+140}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{+32}:\\ \;\;\;\;\left(1 - z\right) \cdot x\\ \mathbf{elif}\;y \leq 4 \cdot 10^{+51}:\\ \;\;\;\;\left(x \cdot y\right) \cdot z\\ \mathbf{elif}\;y \leq 3.9 \cdot 10^{+70}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error0.5
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -4.2 \cdot 10^{+136}:\\ \;\;\;\;\left(z \cdot x\right) \cdot \left(y + -1\right)\\ \mathbf{elif}\;z \leq 6400:\\ \;\;\;\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(\left(y - 1\right) \cdot x\right)\\ \end{array} \]
Alternative 8
Error0.5
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -4.4 \cdot 10^{+136}:\\ \;\;\;\;\left(z \cdot x\right) \cdot \left(y + -1\right)\\ \mathbf{elif}\;z \leq 6400:\\ \;\;\;\;x \cdot \left(z \cdot \left(y + -1\right)\right) + x\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(\left(y - 1\right) \cdot x\right)\\ \end{array} \]
Alternative 9
Error0.5
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -4.5 \cdot 10^{+136}:\\ \;\;\;\;\left(z \cdot x\right) \cdot \left(y + -1\right)\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-59}:\\ \;\;\;\;x \cdot \left(z \cdot \left(y + -1\right)\right) + x\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(\left(y - 1\right) \cdot x\right) + x\\ \end{array} \]
Alternative 10
Error0.9
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -1.05:\\ \;\;\;\;\left(z \cdot x\right) \cdot \left(y + -1\right)\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x \cdot \left(y \cdot z\right) + x\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(\left(y - 1\right) \cdot x\right)\\ \end{array} \]
Alternative 11
Error19.6
Cost520
\[\begin{array}{l} t_0 := -z \cdot x\\ \mathbf{if}\;z \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 7.8 \cdot 10^{-5}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 12
Error33.2
Cost64
\[x \]

Error

Reproduce

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