Average Error: 3.0 → 0.1
Time: 17.1s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;z \le -348871686386691.0625 \lor \neg \left(z \le 10103.67382956603796628769487142562866211\right):\\ \;\;\;\;\mathsf{fma}\left(1, x, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y - 1, 1\right) \cdot x\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \le -348871686386691.0625 \lor \neg \left(z \le 10103.67382956603796628769487142562866211\right):\\
\;\;\;\;\mathsf{fma}\left(1, x, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r519903 = x;
        double r519904 = 1.0;
        double r519905 = y;
        double r519906 = r519904 - r519905;
        double r519907 = z;
        double r519908 = r519906 * r519907;
        double r519909 = r519904 - r519908;
        double r519910 = r519903 * r519909;
        return r519910;
}

double f(double x, double y, double z) {
        double r519911 = z;
        double r519912 = -348871686386691.06;
        bool r519913 = r519911 <= r519912;
        double r519914 = 10103.673829566038;
        bool r519915 = r519911 <= r519914;
        double r519916 = !r519915;
        bool r519917 = r519913 || r519916;
        double r519918 = 1.0;
        double r519919 = x;
        double r519920 = r519919 * r519911;
        double r519921 = y;
        double r519922 = r519921 - r519918;
        double r519923 = r519920 * r519922;
        double r519924 = fma(r519918, r519919, r519923);
        double r519925 = fma(r519911, r519922, r519918);
        double r519926 = r519925 * r519919;
        double r519927 = r519917 ? r519924 : r519926;
        return r519927;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.0
Target0.2
Herbie0.1
\[\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 < -348871686386691.06 or 10103.673829566038 < z

    1. Initial program 8.1

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

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

      \[\leadsto \color{blue}{\left(\left(\sqrt[3]{\mathsf{fma}\left(z, y - 1, 1\right)} \cdot \sqrt[3]{\mathsf{fma}\left(z, y - 1, 1\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(z, y - 1, 1\right)}\right)} \cdot x\]
    5. Applied associate-*l*9.2

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

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

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

    if -348871686386691.06 < z < 10103.673829566038

    1. Initial program 0.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -348871686386691.0625 \lor \neg \left(z \le 10103.67382956603796628769487142562866211\right):\\ \;\;\;\;\mathsf{fma}\left(1, x, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y - 1, 1\right) \cdot x\\ \end{array}\]

Reproduce

herbie shell --seed 2019212 +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))))