Average Error: 3.3 → 1.7
Time: 15.4s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;z \le -4.282959411379250635917467459315710473086 \cdot 10^{-35}:\\ \;\;\;\;\left(y - 1\right) \cdot \left(z \cdot x\right) + 1 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(\left(y - 1\right) \cdot z\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 -4.282959411379250635917467459315710473086 \cdot 10^{-35}:\\
\;\;\;\;\left(y - 1\right) \cdot \left(z \cdot x\right) + 1 \cdot x\\

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

\end{array}
double f(double x, double y, double z) {
        double r51309701 = x;
        double r51309702 = 1.0;
        double r51309703 = y;
        double r51309704 = r51309702 - r51309703;
        double r51309705 = z;
        double r51309706 = r51309704 * r51309705;
        double r51309707 = r51309702 - r51309706;
        double r51309708 = r51309701 * r51309707;
        return r51309708;
}

double f(double x, double y, double z) {
        double r51309709 = z;
        double r51309710 = -4.2829594113792506e-35;
        bool r51309711 = r51309709 <= r51309710;
        double r51309712 = y;
        double r51309713 = 1.0;
        double r51309714 = r51309712 - r51309713;
        double r51309715 = x;
        double r51309716 = r51309709 * r51309715;
        double r51309717 = r51309714 * r51309716;
        double r51309718 = r51309713 * r51309715;
        double r51309719 = r51309717 + r51309718;
        double r51309720 = r51309714 * r51309709;
        double r51309721 = r51309720 * r51309715;
        double r51309722 = r51309721 + r51309718;
        double r51309723 = r51309711 ? r51309719 : r51309722;
        return r51309723;
}

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.3
Target0.3
Herbie1.7
\[\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 < -4.2829594113792506e-35

    1. Initial program 7.0

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
    2. Simplified7.0

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

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

      \[\leadsto \color{blue}{\left(\left(y - 1\right) \cdot z\right) \cdot x + 1 \cdot x}\]
    6. Using strategy rm
    7. Applied associate-*l*0.2

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

    if -4.2829594113792506e-35 < z

    1. Initial program 2.2

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -4.282959411379250635917467459315710473086 \cdot 10^{-35}:\\ \;\;\;\;\left(y - 1\right) \cdot \left(z \cdot x\right) + 1 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(\left(y - 1\right) \cdot z\right) \cdot x + 1 \cdot x\\ \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))))