Average Error: 3.1 → 0.1
Time: 14.6s
Precision: 64
\[x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.957570734057136 \cdot 10^{-13}:\\ \;\;\;\;\left(z \cdot x\right) \cdot y + 1.0 \cdot \left(x - z \cdot x\right)\\ \mathbf{elif}\;x \le 6.0021867161161834 \cdot 10^{-139}:\\ \;\;\;\;\left(\left(y - 1.0\right) \cdot x\right) \cdot z + 1.0 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(z \cdot x\right) \cdot y + 1.0 \cdot \left(x - z \cdot x\right)\\ \end{array}\]
x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;x \le -4.957570734057136 \cdot 10^{-13}:\\
\;\;\;\;\left(z \cdot x\right) \cdot y + 1.0 \cdot \left(x - z \cdot x\right)\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r34910090 = x;
        double r34910091 = 1.0;
        double r34910092 = y;
        double r34910093 = r34910091 - r34910092;
        double r34910094 = z;
        double r34910095 = r34910093 * r34910094;
        double r34910096 = r34910091 - r34910095;
        double r34910097 = r34910090 * r34910096;
        return r34910097;
}

double f(double x, double y, double z) {
        double r34910098 = x;
        double r34910099 = -4.957570734057136e-13;
        bool r34910100 = r34910098 <= r34910099;
        double r34910101 = z;
        double r34910102 = r34910101 * r34910098;
        double r34910103 = y;
        double r34910104 = r34910102 * r34910103;
        double r34910105 = 1.0;
        double r34910106 = r34910098 - r34910102;
        double r34910107 = r34910105 * r34910106;
        double r34910108 = r34910104 + r34910107;
        double r34910109 = 6.0021867161161834e-139;
        bool r34910110 = r34910098 <= r34910109;
        double r34910111 = r34910103 - r34910105;
        double r34910112 = r34910111 * r34910098;
        double r34910113 = r34910112 * r34910101;
        double r34910114 = r34910105 * r34910098;
        double r34910115 = r34910113 + r34910114;
        double r34910116 = r34910110 ? r34910115 : r34910108;
        double r34910117 = r34910100 ? r34910108 : r34910116;
        return r34910117;
}

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.1
Target0.2
Herbie0.1
\[\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 x < -4.957570734057136e-13 or 6.0021867161161834e-139 < x

    1. Initial program 0.8

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

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

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

      \[\leadsto \color{blue}{\left(z \cdot \left(y - 1.0\right)\right) \cdot x + 1.0 \cdot x}\]
    6. Taylor expanded around inf 0.8

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

      \[\leadsto \color{blue}{\left(x \cdot z\right) \cdot \left(y - 1.0\right)} + 1.0 \cdot x\]
    8. Using strategy rm
    9. Applied sub-neg0.2

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

      \[\leadsto \color{blue}{\left(\left(x \cdot z\right) \cdot y + \left(x \cdot z\right) \cdot \left(-1.0\right)\right)} + 1.0 \cdot x\]
    11. Applied associate-+l+0.2

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

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

    if -4.957570734057136e-13 < x < 6.0021867161161834e-139

    1. Initial program 5.9

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.957570734057136 \cdot 10^{-13}:\\ \;\;\;\;\left(z \cdot x\right) \cdot y + 1.0 \cdot \left(x - z \cdot x\right)\\ \mathbf{elif}\;x \le 6.0021867161161834 \cdot 10^{-139}:\\ \;\;\;\;\left(\left(y - 1.0\right) \cdot x\right) \cdot z + 1.0 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(z \cdot x\right) \cdot y + 1.0 \cdot \left(x - z \cdot x\right)\\ \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))))