Average Error: 3.7 → 0.2
Time: 3.4s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;z \le -8.468958278259224291912566289483962982914 \cdot 10^{66}:\\ \;\;\;\;x \cdot 1 + \left(x \cdot z\right) \cdot \left(y - 1\right)\\ \mathbf{elif}\;z \le 19144349.1059049777686595916748046875:\\ \;\;\;\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, 1, \left(x \cdot \left(y - 1\right)\right) \cdot z\right) + \mathsf{fma}\left(-\sqrt{1}, \sqrt{1}, \sqrt{1} \cdot \sqrt{1}\right) \cdot \left(x \cdot z\right)\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \le -8.468958278259224291912566289483962982914 \cdot 10^{66}:\\
\;\;\;\;x \cdot 1 + \left(x \cdot z\right) \cdot \left(y - 1\right)\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r725204 = x;
        double r725205 = 1.0;
        double r725206 = y;
        double r725207 = r725205 - r725206;
        double r725208 = z;
        double r725209 = r725207 * r725208;
        double r725210 = r725205 - r725209;
        double r725211 = r725204 * r725210;
        return r725211;
}

double f(double x, double y, double z) {
        double r725212 = z;
        double r725213 = -8.468958278259224e+66;
        bool r725214 = r725212 <= r725213;
        double r725215 = x;
        double r725216 = 1.0;
        double r725217 = r725215 * r725216;
        double r725218 = r725215 * r725212;
        double r725219 = y;
        double r725220 = r725219 - r725216;
        double r725221 = r725218 * r725220;
        double r725222 = r725217 + r725221;
        double r725223 = 19144349.105904978;
        bool r725224 = r725212 <= r725223;
        double r725225 = r725216 - r725219;
        double r725226 = r725225 * r725212;
        double r725227 = r725216 - r725226;
        double r725228 = r725215 * r725227;
        double r725229 = r725215 * r725220;
        double r725230 = r725229 * r725212;
        double r725231 = fma(r725215, r725216, r725230);
        double r725232 = sqrt(r725216);
        double r725233 = -r725232;
        double r725234 = r725232 * r725232;
        double r725235 = fma(r725233, r725232, r725234);
        double r725236 = r725235 * r725218;
        double r725237 = r725231 + r725236;
        double r725238 = r725224 ? r725228 : r725237;
        double r725239 = r725214 ? r725222 : r725238;
        return r725239;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.7
Target0.2
Herbie0.2
\[\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 3 regimes
  2. if z < -8.468958278259224e+66

    1. Initial program 11.9

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

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

      \[\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)}\]

    if -8.468958278259224e+66 < z < 19144349.105904978

    1. Initial program 0.3

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

    if 19144349.105904978 < z

    1. Initial program 9.7

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

      \[\leadsto x \cdot \color{blue}{\left(1 + \left(-\left(1 - y\right) \cdot z\right)\right)}\]
    4. Applied distribute-lft-in9.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)}\]
    6. Using strategy rm
    7. Applied add-sqr-sqrt0.1

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

      \[\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-diff0.5

      \[\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-rgt-in0.5

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

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

      \[\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)} + \mathsf{fma}\left(-\sqrt{1}, \sqrt{1}, \sqrt{1} \cdot \sqrt{1}\right) \cdot \left(x \cdot z\right)\]
    13. Using strategy rm
    14. Applied associate-*r*0.5

      \[\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) + \mathsf{fma}\left(-\sqrt{1}, \sqrt{1}, \sqrt{1} \cdot \sqrt{1}\right) \cdot \left(x \cdot z\right)\]
    15. Simplified0.1

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

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

Reproduce

herbie shell --seed 2020001 +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))))