Average Error: 3.4 → 0.2
Time: 9.9s
Precision: 64
\[x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;z \le -4.254742651428898 \cdot 10^{+33}:\\ \;\;\;\;\left(y - 1.0\right) \cdot \left(x \cdot z\right) + x \cdot 1.0\\ \mathbf{elif}\;z \le 2.0030901039446497 \cdot 10^{-87}:\\ \;\;\;\;x \cdot \left(\left(y - 1.0\right) \cdot z\right) + x \cdot 1.0\\ \mathbf{else}:\\ \;\;\;\;\left(y - 1.0\right) \cdot \left(x \cdot z\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 -4.254742651428898 \cdot 10^{+33}:\\
\;\;\;\;\left(y - 1.0\right) \cdot \left(x \cdot z\right) + x \cdot 1.0\\

\mathbf{elif}\;z \le 2.0030901039446497 \cdot 10^{-87}:\\
\;\;\;\;x \cdot \left(\left(y - 1.0\right) \cdot z\right) + x \cdot 1.0\\

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

\end{array}
double f(double x, double y, double z) {
        double r16393287 = x;
        double r16393288 = 1.0;
        double r16393289 = y;
        double r16393290 = r16393288 - r16393289;
        double r16393291 = z;
        double r16393292 = r16393290 * r16393291;
        double r16393293 = r16393288 - r16393292;
        double r16393294 = r16393287 * r16393293;
        return r16393294;
}

double f(double x, double y, double z) {
        double r16393295 = z;
        double r16393296 = -4.254742651428898e+33;
        bool r16393297 = r16393295 <= r16393296;
        double r16393298 = y;
        double r16393299 = 1.0;
        double r16393300 = r16393298 - r16393299;
        double r16393301 = x;
        double r16393302 = r16393301 * r16393295;
        double r16393303 = r16393300 * r16393302;
        double r16393304 = r16393301 * r16393299;
        double r16393305 = r16393303 + r16393304;
        double r16393306 = 2.0030901039446497e-87;
        bool r16393307 = r16393295 <= r16393306;
        double r16393308 = r16393300 * r16393295;
        double r16393309 = r16393301 * r16393308;
        double r16393310 = r16393309 + r16393304;
        double r16393311 = r16393307 ? r16393310 : r16393305;
        double r16393312 = r16393297 ? r16393305 : r16393311;
        return r16393312;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original3.4
Target0.3
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 < -4.254742651428898e+33 or 2.0030901039446497e-87 < z

    1. Initial program 7.3

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

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

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

      \[\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.4

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

    if -4.254742651428898e+33 < z < 2.0030901039446497e-87

    1. Initial program 0.1

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -4.254742651428898 \cdot 10^{+33}:\\ \;\;\;\;\left(y - 1.0\right) \cdot \left(x \cdot z\right) + x \cdot 1.0\\ \mathbf{elif}\;z \le 2.0030901039446497 \cdot 10^{-87}:\\ \;\;\;\;x \cdot \left(\left(y - 1.0\right) \cdot z\right) + x \cdot 1.0\\ \mathbf{else}:\\ \;\;\;\;\left(y - 1.0\right) \cdot \left(x \cdot z\right) + x \cdot 1.0\\ \end{array}\]

Reproduce

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