Average Error: 3.1 → 0.1
Time: 13.6s
Precision: 64
\[x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.957570734057136 \cdot 10^{-13}:\\ \;\;\;\;\left(x - z \cdot x\right) \cdot 1.0 + \left(z \cdot x\right) \cdot y\\ \mathbf{elif}\;x \le 6.0021867161161834 \cdot 10^{-139}:\\ \;\;\;\;\left(\left(x \cdot \left(y - 1.0\right)\right) \cdot z + \mathsf{fma}\left(1.0, -1, 1.0\right) \cdot \left(z \cdot x\right)\right) + 1.0 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(x - z \cdot x\right) \cdot 1.0 + \left(z \cdot x\right) \cdot y\\ \end{array}\]
x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;x \le -4.957570734057136 \cdot 10^{-13}:\\
\;\;\;\;\left(x - z \cdot x\right) \cdot 1.0 + \left(z \cdot x\right) \cdot y\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r38242155 = x;
        double r38242156 = 1.0;
        double r38242157 = y;
        double r38242158 = r38242156 - r38242157;
        double r38242159 = z;
        double r38242160 = r38242158 * r38242159;
        double r38242161 = r38242156 - r38242160;
        double r38242162 = r38242155 * r38242161;
        return r38242162;
}

double f(double x, double y, double z) {
        double r38242163 = x;
        double r38242164 = -4.957570734057136e-13;
        bool r38242165 = r38242163 <= r38242164;
        double r38242166 = z;
        double r38242167 = r38242166 * r38242163;
        double r38242168 = r38242163 - r38242167;
        double r38242169 = 1.0;
        double r38242170 = r38242168 * r38242169;
        double r38242171 = y;
        double r38242172 = r38242167 * r38242171;
        double r38242173 = r38242170 + r38242172;
        double r38242174 = 6.0021867161161834e-139;
        bool r38242175 = r38242163 <= r38242174;
        double r38242176 = r38242171 - r38242169;
        double r38242177 = r38242163 * r38242176;
        double r38242178 = r38242177 * r38242166;
        double r38242179 = -1.0;
        double r38242180 = fma(r38242169, r38242179, r38242169);
        double r38242181 = r38242180 * r38242167;
        double r38242182 = r38242178 + r38242181;
        double r38242183 = r38242169 * r38242163;
        double r38242184 = r38242182 + r38242183;
        double r38242185 = r38242175 ? r38242184 : r38242173;
        double r38242186 = r38242165 ? r38242173 : r38242185;
        return r38242186;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.1
Target0.2
Herbie0.1
\[\begin{array}{l} \mathbf{if}\;x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right) \lt -1.618195973607049 \cdot 10^{+50}:\\ \;\;\;\;x + \left(1.0 - y\right) \cdot \left(\left(-z\right) \cdot x\right)\\ \mathbf{elif}\;x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right) \lt 3.892237649663903 \cdot 10^{+134}:\\ \;\;\;\;\left(x \cdot y\right) \cdot z - \left(x \cdot z - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(1.0 - y\right) \cdot \left(\left(-z\right) \cdot x\right)\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -4.957570734057136e-13 or 6.0021867161161834e-139 < x

    1. Initial program 0.8

      \[x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)\]
    2. Simplified0.8

      \[\leadsto \color{blue}{x \cdot \mathsf{fma}\left(z, y - 1.0, 1.0\right)}\]
    3. Using strategy rm
    4. Applied fma-udef0.8

      \[\leadsto x \cdot \color{blue}{\left(z \cdot \left(y - 1.0\right) + 1.0\right)}\]
    5. Applied distribute-lft-in0.8

      \[\leadsto \color{blue}{x \cdot \left(z \cdot \left(y - 1.0\right)\right) + x \cdot 1.0}\]
    6. Using strategy rm
    7. Applied associate-*r*0.2

      \[\leadsto \color{blue}{\left(x \cdot z\right) \cdot \left(y - 1.0\right)} + x \cdot 1.0\]
    8. Using strategy rm
    9. Applied sub-neg0.2

      \[\leadsto \left(x \cdot z\right) \cdot \color{blue}{\left(y + \left(-1.0\right)\right)} + x \cdot 1.0\]
    10. Applied distribute-lft-in0.2

      \[\leadsto \color{blue}{\left(\left(x \cdot z\right) \cdot y + \left(x \cdot z\right) \cdot \left(-1.0\right)\right)} + x \cdot 1.0\]
    11. Applied associate-+l+0.2

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

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

    if -4.957570734057136e-13 < x < 6.0021867161161834e-139

    1. Initial program 5.9

      \[x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)\]
    2. Simplified5.9

      \[\leadsto \color{blue}{x \cdot \mathsf{fma}\left(z, y - 1.0, 1.0\right)}\]
    3. Using strategy rm
    4. Applied fma-udef5.9

      \[\leadsto x \cdot \color{blue}{\left(z \cdot \left(y - 1.0\right) + 1.0\right)}\]
    5. Applied distribute-lft-in5.9

      \[\leadsto \color{blue}{x \cdot \left(z \cdot \left(y - 1.0\right)\right) + x \cdot 1.0}\]
    6. Using strategy rm
    7. Applied add-cube-cbrt5.9

      \[\leadsto x \cdot \left(z \cdot \left(y - \color{blue}{\left(\sqrt[3]{1.0} \cdot \sqrt[3]{1.0}\right) \cdot \sqrt[3]{1.0}}\right)\right) + x \cdot 1.0\]
    8. Applied add-sqr-sqrt34.5

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

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

      \[\leadsto x \cdot \color{blue}{\left(z \cdot \mathsf{fma}\left(\sqrt{y}, \sqrt{y}, -\sqrt[3]{1.0} \cdot \left(\sqrt[3]{1.0} \cdot \sqrt[3]{1.0}\right)\right) + z \cdot \mathsf{fma}\left(-\sqrt[3]{1.0}, \sqrt[3]{1.0} \cdot \sqrt[3]{1.0}, \sqrt[3]{1.0} \cdot \left(\sqrt[3]{1.0} \cdot \sqrt[3]{1.0}\right)\right)\right)} + x \cdot 1.0\]
    11. Applied distribute-lft-in34.5

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.957570734057136 \cdot 10^{-13}:\\ \;\;\;\;\left(x - z \cdot x\right) \cdot 1.0 + \left(z \cdot x\right) \cdot y\\ \mathbf{elif}\;x \le 6.0021867161161834 \cdot 10^{-139}:\\ \;\;\;\;\left(\left(x \cdot \left(y - 1.0\right)\right) \cdot z + \mathsf{fma}\left(1.0, -1, 1.0\right) \cdot \left(z \cdot x\right)\right) + 1.0 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(x - z \cdot x\right) \cdot 1.0 + \left(z \cdot x\right) \cdot y\\ \end{array}\]

Reproduce

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

  :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))))