Average Error: 3.7 → 0.1
Time: 17.0s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -15271779.56896043755114078521728515625 \lor \neg \left(x \le 2055229012769866.5\right):\\ \;\;\;\;\mathsf{fma}\left(1, x, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot y, z, 1 \cdot \left(x - x \cdot z\right)\right)\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;x \le -15271779.56896043755114078521728515625 \lor \neg \left(x \le 2055229012769866.5\right):\\
\;\;\;\;\mathsf{fma}\left(1, x, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r566558 = x;
        double r566559 = 1.0;
        double r566560 = y;
        double r566561 = r566559 - r566560;
        double r566562 = z;
        double r566563 = r566561 * r566562;
        double r566564 = r566559 - r566563;
        double r566565 = r566558 * r566564;
        return r566565;
}

double f(double x, double y, double z) {
        double r566566 = x;
        double r566567 = -15271779.568960438;
        bool r566568 = r566566 <= r566567;
        double r566569 = 2055229012769866.5;
        bool r566570 = r566566 <= r566569;
        double r566571 = !r566570;
        bool r566572 = r566568 || r566571;
        double r566573 = 1.0;
        double r566574 = z;
        double r566575 = r566566 * r566574;
        double r566576 = y;
        double r566577 = r566576 - r566573;
        double r566578 = r566575 * r566577;
        double r566579 = fma(r566573, r566566, r566578);
        double r566580 = r566566 * r566576;
        double r566581 = r566566 - r566575;
        double r566582 = r566573 * r566581;
        double r566583 = fma(r566580, r566574, r566582);
        double r566584 = r566572 ? r566579 : r566583;
        return r566584;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.7
Target0.2
Herbie0.1
\[\begin{array}{l} \mathbf{if}\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \lt -1.618195973607048970493874632750554853795 \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) \lt 3.892237649663902900973248011051357504727 \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 < -15271779.568960438 or 2055229012769866.5 < x

    1. Initial program 0.1

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
    2. Using strategy rm
    3. Applied add-cube-cbrt1.3

      \[\leadsto \color{blue}{\left(\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \sqrt[3]{x}\right)} \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
    4. Applied associate-*l*1.3

      \[\leadsto \color{blue}{\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \left(\sqrt[3]{x} \cdot \left(1 - \left(1 - y\right) \cdot z\right)\right)}\]
    5. Taylor expanded around inf 0.1

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

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

    if -15271779.568960438 < x < 2055229012769866.5

    1. Initial program 5.9

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -15271779.56896043755114078521728515625 \lor \neg \left(x \le 2055229012769866.5\right):\\ \;\;\;\;\mathsf{fma}\left(1, x, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot y, z, 1 \cdot \left(x - x \cdot z\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019209 +o rules:numerics
(FPCore (x y z)
  :name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, J"
  :precision binary64

  :herbie-target
  (if (< (* x (- 1 (* (- 1 y) z))) -1.618195973607049e50) (+ x (* (- 1 y) (* (- z) x))) (if (< (* x (- 1 (* (- 1 y) z))) 3.8922376496639029e134) (- (* (* x y) z) (- (* x z) x)) (+ x (* (- 1 y) (* (- z) x)))))

  (* x (- 1 (* (- 1 y) z))))