Average Error: 3.5 → 0.2
Time: 12.2s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.97935724292898741 \cdot 10^{-117} \lor \neg \left(x \le 2.02073659466729 \cdot 10^{-115}\right):\\ \;\;\;\;x \cdot 1 + \left(y \cdot \left(x \cdot z\right) + \left(-1\right) \cdot \left(x \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 1 + \left(\left(y \cdot x\right) \cdot z + \left(-1\right) \cdot \left(x \cdot z\right)\right)\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;x \le -2.97935724292898741 \cdot 10^{-117} \lor \neg \left(x \le 2.02073659466729 \cdot 10^{-115}\right):\\
\;\;\;\;x \cdot 1 + \left(y \cdot \left(x \cdot z\right) + \left(-1\right) \cdot \left(x \cdot z\right)\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r508127 = x;
        double r508128 = 1.0;
        double r508129 = y;
        double r508130 = r508128 - r508129;
        double r508131 = z;
        double r508132 = r508130 * r508131;
        double r508133 = r508128 - r508132;
        double r508134 = r508127 * r508133;
        return r508134;
}

double f(double x, double y, double z) {
        double r508135 = x;
        double r508136 = -2.9793572429289874e-117;
        bool r508137 = r508135 <= r508136;
        double r508138 = 2.0207365946672857e-115;
        bool r508139 = r508135 <= r508138;
        double r508140 = !r508139;
        bool r508141 = r508137 || r508140;
        double r508142 = 1.0;
        double r508143 = r508135 * r508142;
        double r508144 = y;
        double r508145 = z;
        double r508146 = r508135 * r508145;
        double r508147 = r508144 * r508146;
        double r508148 = -r508142;
        double r508149 = r508148 * r508146;
        double r508150 = r508147 + r508149;
        double r508151 = r508143 + r508150;
        double r508152 = r508144 * r508135;
        double r508153 = r508152 * r508145;
        double r508154 = r508153 + r508149;
        double r508155 = r508143 + r508154;
        double r508156 = r508141 ? r508151 : r508155;
        return r508156;
}

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.5
Target0.2
Herbie0.2
\[\begin{array}{l} \mathbf{if}\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \lt -1.618195973607049 \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.8922376496639029 \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 x < -2.9793572429289874e-117 or 2.0207365946672857e-115 < x

    1. Initial program 1.1

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

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

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

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

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

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

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

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

    if -2.9793572429289874e-117 < x < 2.0207365946672857e-115

    1. Initial program 7.5

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

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

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

      \[\leadsto x \cdot 1 + \color{blue}{\left(x \cdot z\right) \cdot \left(y - 1\right)}\]
    6. Using strategy rm
    7. Applied sub-neg3.8

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

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

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

      \[\leadsto x \cdot 1 + \left(y \cdot \left(x \cdot z\right) + \color{blue}{\left(-1\right) \cdot \left(x \cdot z\right)}\right)\]
    11. Using strategy rm
    12. Applied associate-*r*0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.97935724292898741 \cdot 10^{-117} \lor \neg \left(x \le 2.02073659466729 \cdot 10^{-115}\right):\\ \;\;\;\;x \cdot 1 + \left(y \cdot \left(x \cdot z\right) + \left(-1\right) \cdot \left(x \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 1 + \left(\left(y \cdot x\right) \cdot z + \left(-1\right) \cdot \left(x \cdot z\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020042 
(FPCore (x y z)
  :name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, J"
  :precision binary64

  :herbie-target
  (if (< (* x (- 1 (* (- 1 y) z))) -1.618195973607049e+50) (+ x (* (- 1 y) (* (- z) x))) (if (< (* x (- 1 (* (- 1 y) z))) 3.892237649663903e+134) (- (* (* x y) z) (- (* x z) x)) (+ x (* (- 1 y) (* (- z) x)))))

  (* x (- 1 (* (- 1 y) z))))