Average Error: 3.3 → 1.6
Time: 13.0s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\mathsf{fma}\left(x, 1, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\mathsf{fma}\left(x, 1, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)
double f(double x, double y, double z) {
        double r1262416 = x;
        double r1262417 = 1.0;
        double r1262418 = y;
        double r1262419 = r1262417 - r1262418;
        double r1262420 = z;
        double r1262421 = r1262419 * r1262420;
        double r1262422 = r1262417 - r1262421;
        double r1262423 = r1262416 * r1262422;
        return r1262423;
}

double f(double x, double y, double z) {
        double r1262424 = x;
        double r1262425 = 1.0;
        double r1262426 = z;
        double r1262427 = r1262424 * r1262426;
        double r1262428 = y;
        double r1262429 = r1262428 - r1262425;
        double r1262430 = r1262427 * r1262429;
        double r1262431 = fma(r1262424, r1262425, r1262430);
        return r1262431;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.3
Target0.2
Herbie1.6
\[\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. Initial program 3.3

    \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
  2. Taylor expanded around inf 3.3

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot y, z, 1 \cdot \left(x - x \cdot z\right)\right)}\]
  4. Taylor expanded around inf 3.3

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, 1, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)}\]
  6. Final simplification1.6

    \[\leadsto \mathsf{fma}\left(x, 1, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)\]

Reproduce

herbie shell --seed 2019235 +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.618195973607049e50) (+ x (* (- 1 y) (* (- z) x))) (if (< (* x (- 1 (* (- 1 y) z))) 3.8922376496639029e134) (- (* (* x y) z) (- (* x z) x)) (+ x (* (- 1 y) (* (- z) x)))))

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