Average Error: 3.5 → 0.4
Time: 13.5s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;\left(1 - y\right) \cdot z \le -1.378829640474083147545335691518842379245 \cdot 10^{151}:\\ \;\;\;\;\mathsf{fma}\left(y, z \cdot x, \left(x - z \cdot x\right) \cdot 1\right)\\ \mathbf{elif}\;\left(1 - y\right) \cdot z \le 1.483643942545468341004152368077787739246 \cdot 10^{84}:\\ \;\;\;\;\left(z \cdot \left(-\left(1 - y\right)\right)\right) \cdot x + x \cdot 1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, z \cdot x, \left(x - z \cdot x\right) \cdot 1\right)\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;\left(1 - y\right) \cdot z \le -1.378829640474083147545335691518842379245 \cdot 10^{151}:\\
\;\;\;\;\mathsf{fma}\left(y, z \cdot x, \left(x - z \cdot x\right) \cdot 1\right)\\

\mathbf{elif}\;\left(1 - y\right) \cdot z \le 1.483643942545468341004152368077787739246 \cdot 10^{84}:\\
\;\;\;\;\left(z \cdot \left(-\left(1 - y\right)\right)\right) \cdot x + x \cdot 1\\

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

\end{array}
double f(double x, double y, double z) {
        double r34962754 = x;
        double r34962755 = 1.0;
        double r34962756 = y;
        double r34962757 = r34962755 - r34962756;
        double r34962758 = z;
        double r34962759 = r34962757 * r34962758;
        double r34962760 = r34962755 - r34962759;
        double r34962761 = r34962754 * r34962760;
        return r34962761;
}

double f(double x, double y, double z) {
        double r34962762 = 1.0;
        double r34962763 = y;
        double r34962764 = r34962762 - r34962763;
        double r34962765 = z;
        double r34962766 = r34962764 * r34962765;
        double r34962767 = -1.3788296404740831e+151;
        bool r34962768 = r34962766 <= r34962767;
        double r34962769 = x;
        double r34962770 = r34962765 * r34962769;
        double r34962771 = r34962769 - r34962770;
        double r34962772 = r34962771 * r34962762;
        double r34962773 = fma(r34962763, r34962770, r34962772);
        double r34962774 = 1.4836439425454683e+84;
        bool r34962775 = r34962766 <= r34962774;
        double r34962776 = -r34962764;
        double r34962777 = r34962765 * r34962776;
        double r34962778 = r34962777 * r34962769;
        double r34962779 = r34962769 * r34962762;
        double r34962780 = r34962778 + r34962779;
        double r34962781 = r34962775 ? r34962780 : r34962773;
        double r34962782 = r34962768 ? r34962773 : r34962781;
        return r34962782;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.5
Target0.3
Herbie0.4
\[\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 (* (- 1.0 y) z) < -1.3788296404740831e+151 or 1.4836439425454683e+84 < (* (- 1.0 y) z)

    1. Initial program 11.5

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

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

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

    if -1.3788296404740831e+151 < (* (- 1.0 y) z) < 1.4836439425454683e+84

    1. Initial program 0.1

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

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

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

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

Reproduce

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