?

Average Accuracy: 94.6% → 99.1%
Time: 9.9s
Precision: binary64
Cost: 841

?

\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
\[\begin{array}{l} \mathbf{if}\;x \leq -1.6 \cdot 10^{+122} \lor \neg \left(x \leq 5 \cdot 10^{+17}\right):\\ \;\;\;\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot \left(x \cdot \left(1 - y\right)\right)\\ \end{array} \]
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -1.6e+122) (not (<= x 5e+17)))
   (* x (- 1.0 (* (- 1.0 y) z)))
   (- x (* z (* x (- 1.0 y))))))
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 <= -1.6e+122) || !(x <= 5e+17)) {
		tmp = x * (1.0 - ((1.0 - y) * z));
	} else {
		tmp = x - (z * (x * (1.0 - y)));
	}
	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 <= (-1.6d+122)) .or. (.not. (x <= 5d+17))) then
        tmp = x * (1.0d0 - ((1.0d0 - y) * z))
    else
        tmp = x - (z * (x * (1.0d0 - y)))
    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 <= -1.6e+122) || !(x <= 5e+17)) {
		tmp = x * (1.0 - ((1.0 - y) * z));
	} else {
		tmp = x - (z * (x * (1.0 - y)));
	}
	return tmp;
}
def code(x, y, z):
	return x * (1.0 - ((1.0 - y) * z))
def code(x, y, z):
	tmp = 0
	if (x <= -1.6e+122) or not (x <= 5e+17):
		tmp = x * (1.0 - ((1.0 - y) * z))
	else:
		tmp = x - (z * (x * (1.0 - y)))
	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 <= -1.6e+122) || !(x <= 5e+17))
		tmp = Float64(x * Float64(1.0 - Float64(Float64(1.0 - y) * z)));
	else
		tmp = Float64(x - Float64(z * Float64(x * Float64(1.0 - y))));
	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 <= -1.6e+122) || ~((x <= 5e+17)))
		tmp = x * (1.0 - ((1.0 - y) * z));
	else
		tmp = x - (z * (x * (1.0 - y)));
	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[Or[LessEqual[x, -1.6e+122], N[Not[LessEqual[x, 5e+17]], $MachinePrecision]], N[(x * N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(z * N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{+122} \lor \neg \left(x \leq 5 \cdot 10^{+17}\right):\\
\;\;\;\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original94.6%
Target99.6%
Herbie99.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 2 regimes
  2. if x < -1.60000000000000006e122 or 5e17 < x

    1. Initial program 99.9%

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

    if -1.60000000000000006e122 < x < 5e17

    1. Initial program 92.5%

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
    2. Simplified92.5%

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

      [Start]92.5

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

      *-commutative [=>]92.5

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

      sub-neg [=>]92.5

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

      distribute-rgt-in [=>]92.5

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

      associate--r+ [=>]92.5

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

      *-lft-identity [=>]92.5

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

      sub-neg [=>]92.5

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

      distribute-lft-out-- [<=]92.5

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

      distribute-lft-in [=>]92.5

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

      *-rgt-identity [=>]92.5

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

      +-commutative [=>]92.5

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

      associate-+r- [<=]92.5

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

      *-commutative [=>]92.5

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

      cancel-sign-sub-inv [=>]92.5

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

      distribute-rgt-neg-in [=>]92.5

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

      distribute-rgt1-in [=>]92.5

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

      *-commutative [=>]92.5

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

      +-commutative [=>]92.5

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

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

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

      [Start]96.6

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

      +-commutative [=>]96.6

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

      mul-1-neg [=>]96.6

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

      unsub-neg [=>]96.6

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

      associate-*r* [=>]92.5

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

      *-commutative [=>]92.5

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

      associate-*l* [=>]98.8

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

      mul-1-neg [=>]98.8

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

      unsub-neg [=>]98.8

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

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

Alternatives

Alternative 1
Accuracy99.9%
Cost1352
\[\begin{array}{l} t_0 := \left(1 - y\right) \cdot z\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;y \cdot \left(x \cdot z\right)\\ \mathbf{elif}\;t_0 \leq 10^{+264}:\\ \;\;\;\;x \cdot \left(1 - t_0\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(x \cdot \left(y + -1\right)\right)\\ \end{array} \]
Alternative 2
Accuracy98.7%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -0.98 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;z \cdot \left(x \cdot \left(y + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 + y \cdot z\right)\\ \end{array} \]
Alternative 3
Accuracy80.7%
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -3.2 \cdot 10^{+127}:\\ \;\;\;\;x \cdot \left(y \cdot z\right)\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{+83}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot z\right)\\ \end{array} \]
Alternative 4
Accuracy80.9%
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{+126}:\\ \;\;\;\;x \cdot \left(y \cdot z\right)\\ \mathbf{elif}\;y \leq 6.8 \cdot 10^{+75}:\\ \;\;\;\;x - x \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot z\right)\\ \end{array} \]
Alternative 5
Accuracy68.9%
Cost521
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;z \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Accuracy47.6%
Cost64
\[x \]

Error

Reproduce?

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