Average Error: 3.5 → 0.2
Time: 12.8s
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} \lor \neg \left(\left(1 - y\right) \cdot z \le 4.222476020056273824389986401275064120199 \cdot 10^{157}\right):\\ \;\;\;\;\mathsf{fma}\left(x, 1, \left(y - 1\right) \cdot \left(z \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(1 - y\right) \cdot z\right) \cdot \left(-x\right) + x \cdot 1\\ \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} \lor \neg \left(\left(1 - y\right) \cdot z \le 4.222476020056273824389986401275064120199 \cdot 10^{157}\right):\\
\;\;\;\;\mathsf{fma}\left(x, 1, \left(y - 1\right) \cdot \left(z \cdot x\right)\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r603136 = x;
        double r603137 = 1.0;
        double r603138 = y;
        double r603139 = r603137 - r603138;
        double r603140 = z;
        double r603141 = r603139 * r603140;
        double r603142 = r603137 - r603141;
        double r603143 = r603136 * r603142;
        return r603143;
}

double f(double x, double y, double z) {
        double r603144 = 1.0;
        double r603145 = y;
        double r603146 = r603144 - r603145;
        double r603147 = z;
        double r603148 = r603146 * r603147;
        double r603149 = -1.3788296404740831e+151;
        bool r603150 = r603148 <= r603149;
        double r603151 = 4.222476020056274e+157;
        bool r603152 = r603148 <= r603151;
        double r603153 = !r603152;
        bool r603154 = r603150 || r603153;
        double r603155 = x;
        double r603156 = r603145 - r603144;
        double r603157 = r603147 * r603155;
        double r603158 = r603156 * r603157;
        double r603159 = fma(r603155, r603144, r603158);
        double r603160 = -r603155;
        double r603161 = r603148 * r603160;
        double r603162 = r603155 * r603144;
        double r603163 = r603161 + r603162;
        double r603164 = r603154 ? r603159 : r603163;
        return r603164;
}

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.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 4.222476020056274e+157 < (* (- 1.0 y) z)

    1. Initial program 14.2

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

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

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

    if -1.3788296404740831e+151 < (* (- 1.0 y) z) < 4.222476020056274e+157

    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)}\]
    5. Simplified0.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(1 - y\right) \cdot z \le -1.378829640474083147545335691518842379245 \cdot 10^{151} \lor \neg \left(\left(1 - y\right) \cdot z \le 4.222476020056273824389986401275064120199 \cdot 10^{157}\right):\\ \;\;\;\;\mathsf{fma}\left(x, 1, \left(y - 1\right) \cdot \left(z \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(1 - y\right) \cdot z\right) \cdot \left(-x\right) + x \cdot 1\\ \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))))