Average Error: 3.3 → 1.0
Time: 12.0s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;z \le -1.044720147495814947738710748278359989149 \cdot 10^{-121} \lor \neg \left(z \le 7.111877045651439551412938008198758963312 \cdot 10^{-147}\right):\\ \;\;\;\;\left(-\left(x \cdot z\right) \cdot \left(1 - y\right)\right) + x \cdot 1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(\mathsf{fma}\left(z, 1 - y, 1\right) \cdot \left(1 - \left(1 - y\right) \cdot z\right)\right)}{1 + \left(1 - y\right) \cdot z}\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \le -1.044720147495814947738710748278359989149 \cdot 10^{-121} \lor \neg \left(z \le 7.111877045651439551412938008198758963312 \cdot 10^{-147}\right):\\
\;\;\;\;\left(-\left(x \cdot z\right) \cdot \left(1 - y\right)\right) + x \cdot 1\\

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

\end{array}
double f(double x, double y, double z) {
        double r512217 = x;
        double r512218 = 1.0;
        double r512219 = y;
        double r512220 = r512218 - r512219;
        double r512221 = z;
        double r512222 = r512220 * r512221;
        double r512223 = r512218 - r512222;
        double r512224 = r512217 * r512223;
        return r512224;
}

double f(double x, double y, double z) {
        double r512225 = z;
        double r512226 = -1.044720147495815e-121;
        bool r512227 = r512225 <= r512226;
        double r512228 = 7.11187704565144e-147;
        bool r512229 = r512225 <= r512228;
        double r512230 = !r512229;
        bool r512231 = r512227 || r512230;
        double r512232 = x;
        double r512233 = r512232 * r512225;
        double r512234 = 1.0;
        double r512235 = y;
        double r512236 = r512234 - r512235;
        double r512237 = r512233 * r512236;
        double r512238 = -r512237;
        double r512239 = r512232 * r512234;
        double r512240 = r512238 + r512239;
        double r512241 = fma(r512225, r512236, r512234);
        double r512242 = r512236 * r512225;
        double r512243 = r512234 - r512242;
        double r512244 = r512241 * r512243;
        double r512245 = r512232 * r512244;
        double r512246 = r512234 + r512242;
        double r512247 = r512245 / r512246;
        double r512248 = r512231 ? r512240 : r512247;
        return r512248;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.3
Target0.3
Herbie1.0
\[\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 z < -1.044720147495815e-121 or 7.11187704565144e-147 < z

    1. Initial program 5.1

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

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

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

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

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

    if -1.044720147495815e-121 < z < 7.11187704565144e-147

    1. Initial program 0.0

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

      \[\leadsto x \cdot \color{blue}{\frac{1 \cdot 1 - \left(\left(1 - y\right) \cdot z\right) \cdot \left(\left(1 - y\right) \cdot z\right)}{1 + \left(1 - y\right) \cdot z}}\]
    4. Applied associate-*r/1.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -1.044720147495814947738710748278359989149 \cdot 10^{-121} \lor \neg \left(z \le 7.111877045651439551412938008198758963312 \cdot 10^{-147}\right):\\ \;\;\;\;\left(-\left(x \cdot z\right) \cdot \left(1 - y\right)\right) + x \cdot 1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(\mathsf{fma}\left(z, 1 - y, 1\right) \cdot \left(1 - \left(1 - y\right) \cdot z\right)\right)}{1 + \left(1 - y\right) \cdot z}\\ \end{array}\]

Reproduce

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