Average Error: 3.4 → 0.1
Time: 16.2s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;z \le -3.5627093803727213 \cdot 10^{52} \lor \neg \left(z \le 0.26598517754739281\right):\\ \;\;\;\;1 \cdot x + z \cdot \left(x \cdot \left(y - 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(z \cdot \left(y - 1\right)\right) \cdot x + 1 \cdot x\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \le -3.5627093803727213 \cdot 10^{52} \lor \neg \left(z \le 0.26598517754739281\right):\\
\;\;\;\;1 \cdot x + z \cdot \left(x \cdot \left(y - 1\right)\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r944631 = x;
        double r944632 = 1.0;
        double r944633 = y;
        double r944634 = r944632 - r944633;
        double r944635 = z;
        double r944636 = r944634 * r944635;
        double r944637 = r944632 - r944636;
        double r944638 = r944631 * r944637;
        return r944638;
}

double f(double x, double y, double z) {
        double r944639 = z;
        double r944640 = -3.5627093803727213e+52;
        bool r944641 = r944639 <= r944640;
        double r944642 = 0.2659851775473928;
        bool r944643 = r944639 <= r944642;
        double r944644 = !r944643;
        bool r944645 = r944641 || r944644;
        double r944646 = 1.0;
        double r944647 = x;
        double r944648 = r944646 * r944647;
        double r944649 = y;
        double r944650 = r944649 - r944646;
        double r944651 = r944647 * r944650;
        double r944652 = r944639 * r944651;
        double r944653 = r944648 + r944652;
        double r944654 = r944639 * r944650;
        double r944655 = r944654 * r944647;
        double r944656 = r944655 + r944648;
        double r944657 = r944645 ? r944653 : r944656;
        return r944657;
}

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.1
\[\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 z < -3.5627093803727213e+52 or 0.2659851775473928 < z

    1. Initial program 9.7

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

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

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

      \[\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}{z \cdot \left(x \cdot \left(y - 1\right)\right)}\]

    if -3.5627093803727213e+52 < z < 0.2659851775473928

    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. Simplified5.2

      \[\leadsto 1 \cdot x + \color{blue}{z \cdot \left(x \cdot \left(y - 1\right)\right)}\]
    7. Using strategy rm
    8. Applied *-un-lft-identity5.2

      \[\leadsto 1 \cdot x + \color{blue}{\left(1 \cdot z\right)} \cdot \left(x \cdot \left(y - 1\right)\right)\]
    9. Applied associate-*l*5.2

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

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

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

Reproduce

herbie shell --seed 2020047 +o rules:numerics
(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))))