Average Error: 3.5 → 0.2
Time: 4.6s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.37421325320552428 \cdot 10^{73}:\\ \;\;\;\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\ \mathbf{elif}\;x \le 2.41284378300030768 \cdot 10^{-93}:\\ \;\;\;\;\mathsf{fma}\left(x, 1, \left(x \cdot \left(y - 1\right)\right) \cdot z\right) + \left(x \cdot z\right) \cdot \mathsf{fma}\left(-\sqrt{1}, \sqrt{1}, \sqrt{1} \cdot \sqrt{1}\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 1 + \left(x \cdot z\right) \cdot \left(y - 1\right)\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;x \le -2.37421325320552428 \cdot 10^{73}:\\
\;\;\;\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\

\mathbf{elif}\;x \le 2.41284378300030768 \cdot 10^{-93}:\\
\;\;\;\;\mathsf{fma}\left(x, 1, \left(x \cdot \left(y - 1\right)\right) \cdot z\right) + \left(x \cdot z\right) \cdot \mathsf{fma}\left(-\sqrt{1}, \sqrt{1}, \sqrt{1} \cdot \sqrt{1}\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r789278 = x;
        double r789279 = 1.0;
        double r789280 = y;
        double r789281 = r789279 - r789280;
        double r789282 = z;
        double r789283 = r789281 * r789282;
        double r789284 = r789279 - r789283;
        double r789285 = r789278 * r789284;
        return r789285;
}

double f(double x, double y, double z) {
        double r789286 = x;
        double r789287 = -2.3742132532055243e+73;
        bool r789288 = r789286 <= r789287;
        double r789289 = 1.0;
        double r789290 = y;
        double r789291 = r789289 - r789290;
        double r789292 = z;
        double r789293 = r789291 * r789292;
        double r789294 = r789289 - r789293;
        double r789295 = r789286 * r789294;
        double r789296 = 2.4128437830003077e-93;
        bool r789297 = r789286 <= r789296;
        double r789298 = r789290 - r789289;
        double r789299 = r789286 * r789298;
        double r789300 = r789299 * r789292;
        double r789301 = fma(r789286, r789289, r789300);
        double r789302 = r789286 * r789292;
        double r789303 = sqrt(r789289);
        double r789304 = -r789303;
        double r789305 = r789303 * r789303;
        double r789306 = fma(r789304, r789303, r789305);
        double r789307 = r789302 * r789306;
        double r789308 = r789301 + r789307;
        double r789309 = r789286 * r789289;
        double r789310 = r789302 * r789298;
        double r789311 = r789309 + r789310;
        double r789312 = r789297 ? r789308 : r789311;
        double r789313 = r789288 ? r789295 : r789312;
        return r789313;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.5
Target0.3
Herbie0.2
\[\begin{array}{l} \mathbf{if}\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \lt -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) \lt 3.8922376496639029 \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 x < -2.3742132532055243e+73

    1. Initial program 0.1

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

    if -2.3742132532055243e+73 < x < 2.4128437830003077e-93

    1. Initial program 5.7

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
    2. Using strategy rm
    3. Applied sub-neg5.7

      \[\leadsto x \cdot \color{blue}{\left(1 + \left(-\left(1 - y\right) \cdot z\right)\right)}\]
    4. Applied distribute-lft-in5.7

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

      \[\leadsto x \cdot 1 + \color{blue}{\left(x \cdot z\right) \cdot \left(y - 1\right)}\]
    6. Using strategy rm
    7. Applied add-sqr-sqrt2.7

      \[\leadsto x \cdot 1 + \left(x \cdot z\right) \cdot \left(y - \color{blue}{\sqrt{1} \cdot \sqrt{1}}\right)\]
    8. Applied add-cube-cbrt3.0

      \[\leadsto x \cdot 1 + \left(x \cdot z\right) \cdot \left(\color{blue}{\left(\sqrt[3]{y} \cdot \sqrt[3]{y}\right) \cdot \sqrt[3]{y}} - \sqrt{1} \cdot \sqrt{1}\right)\]
    9. Applied prod-diff3.0

      \[\leadsto x \cdot 1 + \left(x \cdot z\right) \cdot \color{blue}{\left(\mathsf{fma}\left(\sqrt[3]{y} \cdot \sqrt[3]{y}, \sqrt[3]{y}, -\sqrt{1} \cdot \sqrt{1}\right) + \mathsf{fma}\left(-\sqrt{1}, \sqrt{1}, \sqrt{1} \cdot \sqrt{1}\right)\right)}\]
    10. Applied distribute-lft-in3.0

      \[\leadsto x \cdot 1 + \color{blue}{\left(\left(x \cdot z\right) \cdot \mathsf{fma}\left(\sqrt[3]{y} \cdot \sqrt[3]{y}, \sqrt[3]{y}, -\sqrt{1} \cdot \sqrt{1}\right) + \left(x \cdot z\right) \cdot \mathsf{fma}\left(-\sqrt{1}, \sqrt{1}, \sqrt{1} \cdot \sqrt{1}\right)\right)}\]
    11. Applied associate-+r+3.0

      \[\leadsto \color{blue}{\left(x \cdot 1 + \left(x \cdot z\right) \cdot \mathsf{fma}\left(\sqrt[3]{y} \cdot \sqrt[3]{y}, \sqrt[3]{y}, -\sqrt{1} \cdot \sqrt{1}\right)\right) + \left(x \cdot z\right) \cdot \mathsf{fma}\left(-\sqrt{1}, \sqrt{1}, \sqrt{1} \cdot \sqrt{1}\right)}\]
    12. Simplified3.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, 1, \mathsf{fma}\left(\sqrt[3]{y} \cdot \sqrt[3]{y}, \sqrt[3]{y}, -1 \cdot 1\right) \cdot \left(x \cdot z\right)\right)} + \left(x \cdot z\right) \cdot \mathsf{fma}\left(-\sqrt{1}, \sqrt{1}, \sqrt{1} \cdot \sqrt{1}\right)\]
    13. Using strategy rm
    14. Applied associate-*r*0.7

      \[\leadsto \mathsf{fma}\left(x, 1, \color{blue}{\left(\mathsf{fma}\left(\sqrt[3]{y} \cdot \sqrt[3]{y}, \sqrt[3]{y}, -1 \cdot 1\right) \cdot x\right) \cdot z}\right) + \left(x \cdot z\right) \cdot \mathsf{fma}\left(-\sqrt{1}, \sqrt{1}, \sqrt{1} \cdot \sqrt{1}\right)\]
    15. Simplified0.4

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

    if 2.4128437830003077e-93 < x

    1. Initial program 0.7

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
    2. Using strategy rm
    3. Applied sub-neg0.7

      \[\leadsto x \cdot \color{blue}{\left(1 + \left(-\left(1 - y\right) \cdot z\right)\right)}\]
    4. Applied distribute-lft-in0.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.37421325320552428 \cdot 10^{73}:\\ \;\;\;\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\ \mathbf{elif}\;x \le 2.41284378300030768 \cdot 10^{-93}:\\ \;\;\;\;\mathsf{fma}\left(x, 1, \left(x \cdot \left(y - 1\right)\right) \cdot z\right) + \left(x \cdot z\right) \cdot \mathsf{fma}\left(-\sqrt{1}, \sqrt{1}, \sqrt{1} \cdot \sqrt{1}\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 1 + \left(x \cdot z\right) \cdot \left(y - 1\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020039 +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.618195973607049e+50) (+ x (* (- 1 y) (* (- z) x))) (if (< (* x (- 1 (* (- 1 y) z))) 3.892237649663903e+134) (- (* (* x y) z) (- (* x z) x)) (+ x (* (- 1 y) (* (- z) x)))))

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