Average Error: 3.1 → 0.2
Time: 13.8s
Precision: 64
\[x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;z \le -2.035243254459298 \cdot 10^{-28}:\\ \;\;\;\;z \cdot \left(x \cdot y - x \cdot 1.0\right) + x \cdot 1.0\\ \mathbf{elif}\;z \le 5.312519142170575 \cdot 10^{+53}:\\ \;\;\;\;\mathsf{fma}\left(\left(y - 1.0\right) \cdot z, x, x \cdot 1.0\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(x \cdot y - x \cdot 1.0\right) + x \cdot 1.0\\ \end{array}\]
x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \le -2.035243254459298 \cdot 10^{-28}:\\
\;\;\;\;z \cdot \left(x \cdot y - x \cdot 1.0\right) + x \cdot 1.0\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r42055170 = x;
        double r42055171 = 1.0;
        double r42055172 = y;
        double r42055173 = r42055171 - r42055172;
        double r42055174 = z;
        double r42055175 = r42055173 * r42055174;
        double r42055176 = r42055171 - r42055175;
        double r42055177 = r42055170 * r42055176;
        return r42055177;
}

double f(double x, double y, double z) {
        double r42055178 = z;
        double r42055179 = -2.035243254459298e-28;
        bool r42055180 = r42055178 <= r42055179;
        double r42055181 = x;
        double r42055182 = y;
        double r42055183 = r42055181 * r42055182;
        double r42055184 = 1.0;
        double r42055185 = r42055181 * r42055184;
        double r42055186 = r42055183 - r42055185;
        double r42055187 = r42055178 * r42055186;
        double r42055188 = r42055187 + r42055185;
        double r42055189 = 5.312519142170575e+53;
        bool r42055190 = r42055178 <= r42055189;
        double r42055191 = r42055182 - r42055184;
        double r42055192 = r42055191 * r42055178;
        double r42055193 = fma(r42055192, r42055181, r42055185);
        double r42055194 = r42055190 ? r42055193 : r42055188;
        double r42055195 = r42055180 ? r42055188 : r42055194;
        return r42055195;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.1
Target0.2
Herbie0.2
\[\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 z < -2.035243254459298e-28 or 5.312519142170575e+53 < z

    1. Initial program 8.0

      \[x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)\]
    2. Simplified8.0

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

      \[\leadsto x \cdot \color{blue}{\left(z \cdot \left(y - 1.0\right) + 1.0\right)}\]
    5. Applied distribute-rgt-in8.0

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

      \[\leadsto \color{blue}{z \cdot \left(\left(y - 1.0\right) \cdot x\right)} + 1.0 \cdot x\]
    8. Taylor expanded around 0 0.2

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

    if -2.035243254459298e-28 < z < 5.312519142170575e+53

    1. Initial program 0.2

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

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

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

      \[\leadsto \color{blue}{\left(z \cdot \left(y - 1.0\right)\right) \cdot x + 1.0 \cdot x}\]
    6. Using strategy rm
    7. Applied fma-def0.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -2.035243254459298 \cdot 10^{-28}:\\ \;\;\;\;z \cdot \left(x \cdot y - x \cdot 1.0\right) + x \cdot 1.0\\ \mathbf{elif}\;z \le 5.312519142170575 \cdot 10^{+53}:\\ \;\;\;\;\mathsf{fma}\left(\left(y - 1.0\right) \cdot z, x, x \cdot 1.0\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(x \cdot y - x \cdot 1.0\right) + x \cdot 1.0\\ \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))))