?

Average Accuracy: 94.7% → 99.5%
Time: 8.0s
Precision: binary64
Cost: 7624

?

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

\mathbf{elif}\;t_0 \leq 10^{+276}:\\
\;\;\;\;x \cdot \left(1 - t_0\right)\\

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


\end{array}

Error?

Target

Original94.7%
Target99.7%
Herbie99.5%
\[\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 (-.f64 1 y) z) < -4.0000000000000003e128

    1. Initial program 81.9%

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

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

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

      [Start]97.4

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

      *-commutative [=>]97.4

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

      sub-neg [=>]97.4

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

      metadata-eval [=>]97.4

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

      distribute-rgt-in [=>]97.4

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

      *-commutative [<=]97.4

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

      neg-mul-1 [<=]97.4

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

      distribute-rgt-in [=>]97.4

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

      *-commutative [=>]97.4

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

      distribute-rgt-in [<=]97.4

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

      unsub-neg [=>]97.4

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

    if -4.0000000000000003e128 < (*.f64 (-.f64 1 y) z) < 1.0000000000000001e276

    1. Initial program 99.9%

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

    if 1.0000000000000001e276 < (*.f64 (-.f64 1 y) z)

    1. Initial program 43.9%

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

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

      [Start]43.9

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

      distribute-rgt-out-- [<=]43.9

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

      *-lft-identity [=>]43.9

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

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

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

      +-commutative [=>]43.9

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

      distribute-lft-neg-in [=>]43.9

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

      associate-*l* [=>]99.4

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

      fma-def [=>]99.4

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

      neg-sub0 [=>]99.4

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

      associate--r- [=>]99.4

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

      metadata-eval [=>]99.4

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

      +-commutative [=>]99.4

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

      *-commutative [<=]99.4

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

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

Alternatives

Alternative 1
Accuracy98.8%
Cost1352
\[\begin{array}{l} t_0 := \left(1 - y\right) \cdot z\\ \mathbf{if}\;t_0 \leq -4 \cdot 10^{+128}:\\ \;\;\;\;z \cdot \left(y \cdot x - x\right)\\ \mathbf{elif}\;t_0 \leq 4 \cdot 10^{+284}:\\ \;\;\;\;x \cdot \left(1 - t_0\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(z \cdot x\right)\\ \end{array} \]
Alternative 2
Accuracy66.5%
Cost848
\[\begin{array}{l} t_0 := x \cdot \left(-z\right)\\ t_1 := y \cdot \left(z \cdot x\right)\\ \mathbf{if}\;z \leq -2.95 \cdot 10^{+53}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -5.6 \cdot 10^{-6}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.4 \cdot 10^{+84}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Accuracy66.4%
Cost848
\[\begin{array}{l} t_0 := x \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -6.3 \cdot 10^{+59}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3 \cdot 10^{-6}:\\ \;\;\;\;z \cdot \left(y \cdot x\right)\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 7 \cdot 10^{+83}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(z \cdot x\right)\\ \end{array} \]
Alternative 4
Accuracy86.0%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -0.042 \lor \neg \left(z \leq 2.65 \cdot 10^{-5}\right):\\ \;\;\;\;z \cdot \left(y \cdot x - x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \end{array} \]
Alternative 5
Accuracy98.4%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -3 \lor \neg \left(z \leq 2.65 \cdot 10^{-5}\right):\\ \;\;\;\;z \cdot \left(y \cdot x - x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 + y \cdot z\right)\\ \end{array} \]
Alternative 6
Accuracy79.7%
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -2.7 \cdot 10^{+180}:\\ \;\;\;\;y \cdot \left(z \cdot x\right)\\ \mathbf{elif}\;y \leq 72000:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(y \cdot x\right)\\ \end{array} \]
Alternative 7
Accuracy69.5%
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
Accuracy48.0%
Cost64
\[x \]

Error

Reproduce?

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