?

Average Accuracy: 94.3% → 99.9%
Time: 7.9s
Precision: binary64
Cost: 8136

?

\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
\[\begin{array}{l} t_0 := x \cdot \left(1 + z \cdot \left(y + -1\right)\right)\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;\left(1 - y\right) \cdot \frac{z}{\frac{-1}{x}}\\ \mathbf{elif}\;t_0 \leq 10^{+248}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot z, y + -1, x\right)\\ \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 (+ 1.0 (* z (+ y -1.0))))))
   (if (<= t_0 (- INFINITY))
     (* (- 1.0 y) (/ z (/ -1.0 x)))
     (if (<= t_0 1e+248) t_0 (fma (* x z) (+ y -1.0) 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 t_0 = x * (1.0 + (z * (y + -1.0)));
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = (1.0 - y) * (z / (-1.0 / x));
	} else if (t_0 <= 1e+248) {
		tmp = t_0;
	} else {
		tmp = fma((x * z), (y + -1.0), 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)
	t_0 = Float64(x * Float64(1.0 + Float64(z * Float64(y + -1.0))))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(Float64(1.0 - y) * Float64(z / Float64(-1.0 / x)));
	elseif (t_0 <= 1e+248)
		tmp = t_0;
	else
		tmp = fma(Float64(x * z), Float64(y + -1.0), x);
	end
	return 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[(1.0 + N[(z * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(1.0 - y), $MachinePrecision] * N[(z / N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+248], t$95$0, N[(N[(x * z), $MachinePrecision] * N[(y + -1.0), $MachinePrecision] + x), $MachinePrecision]]]]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
t_0 := x \cdot \left(1 + z \cdot \left(y + -1\right)\right)\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;\left(1 - y\right) \cdot \frac{z}{\frac{-1}{x}}\\

\mathbf{elif}\;t_0 \leq 10^{+248}:\\
\;\;\;\;t_0\\

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


\end{array}

Error?

Target

Original94.3%
Target99.7%
Herbie99.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 3 regimes
  2. if (*.f64 x (-.f64 1 (*.f64 (-.f64 1 y) z))) < -inf.0

    1. Initial program 0.0%

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

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

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

      [Start]99.6

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

      associate-*r* [=>]0.0

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

      sub-neg [=>]0.0

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

      metadata-eval [=>]0.0

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

      *-commutative [<=]0.0

      \[ \color{blue}{x \cdot \left(z \cdot \left(y + -1\right)\right)} \]
    4. Applied egg-rr99.4%

      \[\leadsto \color{blue}{\frac{x \cdot z}{\frac{1}{y + -1}}} \]
    5. Applied egg-rr99.6%

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

    if -inf.0 < (*.f64 x (-.f64 1 (*.f64 (-.f64 1 y) z))) < 1.00000000000000005e248

    1. Initial program 99.9%

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

    if 1.00000000000000005e248 < (*.f64 x (-.f64 1 (*.f64 (-.f64 1 y) z)))

    1. Initial program 65.8%

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

      \[\leadsto \color{blue}{{\left(\sqrt{x \cdot \left(1 - \left(1 - y\right) \cdot z\right)}\right)}^{2}} \]
    3. Taylor expanded in y around 0 99.8%

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

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

      [Start]99.8

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

      associate-*r* [=>]65.8

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

      distribute-rgt-out [=>]65.8

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

      +-commutative [<=]65.8

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

      sub-neg [=>]65.8

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

      mul-1-neg [<=]65.8

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

      *-commutative [<=]65.8

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

      associate-+r+ [<=]65.8

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

      *-commutative [=>]65.8

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

      distribute-lft-in [<=]65.8

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

      distribute-rgt-in [=>]65.8

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

      *-lft-identity [=>]65.8

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

      +-commutative [=>]65.8

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

      *-commutative [<=]65.8

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

      associate-*r* [=>]99.8

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

      *-commutative [<=]99.8

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

      fma-def [=>]99.8

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

      +-commutative [=>]99.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot \left(1 + z \cdot \left(y + -1\right)\right) \leq -\infty:\\ \;\;\;\;\left(1 - y\right) \cdot \frac{z}{\frac{-1}{x}}\\ \mathbf{elif}\;x \cdot \left(1 + z \cdot \left(y + -1\right)\right) \leq 10^{+248}:\\ \;\;\;\;x \cdot \left(1 + z \cdot \left(y + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot z, y + -1, x\right)\\ \end{array} \]

Alternatives

Alternative 1
Accuracy98.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^{+272}:\\ \;\;\;\;x \cdot \left(1 + z \cdot \left(y + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(x \cdot y\right)\\ \end{array} \]
Alternative 2
Accuracy68.4%
Cost981
\[\begin{array}{l} t_0 := x \cdot \left(-z\right)\\ t_1 := y \cdot \left(x \cdot z\right)\\ \mathbf{if}\;z \leq -180000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -8.2 \cdot 10^{-78}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 6 \cdot 10^{+130} \lor \neg \left(z \leq 4.4 \cdot 10^{+147}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Accuracy68.5%
Cost981
\[\begin{array}{l} t_0 := x \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -80000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -8.2 \cdot 10^{-78}:\\ \;\;\;\;x \cdot \left(y \cdot z\right)\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{+130} \lor \neg \left(z \leq 5 \cdot 10^{+147}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot z\right)\\ \end{array} \]
Alternative 4
Accuracy81.5%
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -2.55 \cdot 10^{+48}:\\ \;\;\;\;y \cdot \left(x \cdot z\right)\\ \mathbf{elif}\;y \leq 5.2 \cdot 10^{+140}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(x \cdot y\right)\\ \end{array} \]
Alternative 5
Accuracy81.5%
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -3.4 \cdot 10^{+49}:\\ \;\;\;\;\frac{x \cdot z}{\frac{1}{y}}\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{+139}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(x \cdot y\right)\\ \end{array} \]
Alternative 6
Accuracy69.4%
Cost521
\[\begin{array}{l} \mathbf{if}\;z \leq -1.12 \cdot 10^{-7} \lor \neg \left(z \leq 1\right):\\ \;\;\;\;x \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Accuracy47.3%
Cost64
\[x \]

Error

Reproduce?

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