?

Average Accuracy: 94.7% → 96.9%
Time: 9.0s
Precision: binary64
Cost: 964

?

\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
\[\begin{array}{l} \mathbf{if}\;\left(1 - y\right) \cdot z \leq 10^{+160}:\\ \;\;\;\;x \cdot \left(1 + z \cdot \left(y + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(y \cdot x - x\right)\\ \end{array} \]
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
(FPCore (x y z)
 :precision binary64
 (if (<= (* (- 1.0 y) z) 1e+160)
   (* x (+ 1.0 (* z (+ y -1.0))))
   (* z (- (* y 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 (((1.0 - y) * z) <= 1e+160) {
		tmp = x * (1.0 + (z * (y + -1.0)));
	} else {
		tmp = z * ((y * 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 (((1.0d0 - y) * z) <= 1d+160) then
        tmp = x * (1.0d0 + (z * (y + (-1.0d0))))
    else
        tmp = z * ((y * 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 (((1.0 - y) * z) <= 1e+160) {
		tmp = x * (1.0 + (z * (y + -1.0)));
	} else {
		tmp = z * ((y * 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 ((1.0 - y) * z) <= 1e+160:
		tmp = x * (1.0 + (z * (y + -1.0)))
	else:
		tmp = z * ((y * 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 (Float64(Float64(1.0 - y) * z) <= 1e+160)
		tmp = Float64(x * Float64(1.0 + Float64(z * Float64(y + -1.0))));
	else
		tmp = Float64(z * Float64(Float64(y * 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 (((1.0 - y) * z) <= 1e+160)
		tmp = x * (1.0 + (z * (y + -1.0)));
	else
		tmp = z * ((y * 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[N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision], 1e+160], N[(x * N[(1.0 + N[(z * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;\left(1 - y\right) \cdot z \leq 10^{+160}:\\
\;\;\;\;x \cdot \left(1 + z \cdot \left(y + -1\right)\right)\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original94.7%
Target99.6%
Herbie96.9%
\[\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 (*.f64 (-.f64 1 y) z) < 1.00000000000000001e160

    1. Initial program 96.8%

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

    if 1.00000000000000001e160 < (*.f64 (-.f64 1 y) z)

    1. Initial program 78.5%

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

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

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

      [Start]98.0

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

      *-commutative [=>]98.0

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

      sub-neg [=>]98.0

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

      metadata-eval [=>]98.0

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

      distribute-rgt-in [=>]98.0

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

      *-commutative [<=]98.0

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

      neg-mul-1 [<=]98.0

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

      distribute-rgt-in [=>]98.0

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

      *-commutative [=>]98.0

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

      distribute-rgt-in [<=]98.0

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

      unsub-neg [=>]98.0

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

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

Alternatives

Alternative 1
Accuracy85.3%
Cost976
\[\begin{array}{l} t_0 := z \cdot \left(y \cdot x - x\right)\\ \mathbf{if}\;z \leq -620000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.35 \cdot 10^{-52}:\\ \;\;\;\;x - z \cdot x\\ \mathbf{elif}\;z \leq 9 \cdot 10^{-38}:\\ \;\;\;\;y \cdot \left(z \cdot x\right)\\ \mathbf{elif}\;z \leq 5 \cdot 10^{-10}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Accuracy69.9%
Cost784
\[\begin{array}{l} t_0 := x \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.35 \cdot 10^{-52}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 9.5 \cdot 10^{-40}:\\ \;\;\;\;x \cdot \left(y \cdot z\right)\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Accuracy69.9%
Cost784
\[\begin{array}{l} t_0 := x \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.35 \cdot 10^{-52}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 5 \cdot 10^{-40}:\\ \;\;\;\;y \cdot \left(z \cdot x\right)\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Accuracy98.4%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -0.85 \lor \neg \left(z \leq 0.0076\right):\\ \;\;\;\;z \cdot \left(y \cdot x - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + x \cdot \left(y \cdot z\right)\\ \end{array} \]
Alternative 5
Accuracy82.1%
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -3.5 \cdot 10^{+27}:\\ \;\;\;\;z \cdot \left(y \cdot x\right)\\ \mathbf{elif}\;y \leq 1.75 \cdot 10^{+65}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(z \cdot x\right)\\ \end{array} \]
Alternative 6
Accuracy82.0%
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -5.5 \cdot 10^{+26}:\\ \;\;\;\;z \cdot \left(y \cdot x\right)\\ \mathbf{elif}\;y \leq 1.95 \cdot 10^{+65}:\\ \;\;\;\;x - z \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(z \cdot x\right)\\ \end{array} \]
Alternative 7
Accuracy70.1%
Cost521
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;x \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Accuracy47.7%
Cost64
\[x \]

Error

Reproduce?

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