Average Error: 45.3 → 24.4
Time: 4.0s
Precision: binary64
\[\mathsf{fma}\left(x, y, z\right) - \left(1 + \left(x \cdot y + z\right)\right) \]
\[\begin{array}{l} \mathbf{if}\;z \leq -2.1021206699534236 \lor \neg \left(z \leq 32767434791329.156\right):\\ \;\;\;\;\left(\mathsf{fma}\left(x, y, z\right) - z\right) - 1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, y, z\right) - \left(1 + \left(z + x \cdot y\right)\right)\\ \end{array} \]
\mathsf{fma}\left(x, y, z\right) - \left(1 + \left(x \cdot y + z\right)\right)
\begin{array}{l}
\mathbf{if}\;z \leq -2.1021206699534236 \lor \neg \left(z \leq 32767434791329.156\right):\\
\;\;\;\;\left(\mathsf{fma}\left(x, y, z\right) - z\right) - 1\\

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


\end{array}
(FPCore (x y z) :precision binary64 (- (fma x y z) (+ 1.0 (+ (* x y) z))))
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -2.1021206699534236) (not (<= z 32767434791329.156)))
   (- (- (fma x y z) z) 1.0)
   (- (fma x y z) (+ 1.0 (+ z (* x y))))))
double code(double x, double y, double z) {
	return fma(x, y, z) - (1.0 + ((x * y) + z));
}
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -2.1021206699534236) || !(z <= 32767434791329.156)) {
		tmp = (fma(x, y, z) - z) - 1.0;
	} else {
		tmp = fma(x, y, z) - (1.0 + (z + (x * y)));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original45.3
Target0
Herbie24.4
\[-1 \]

Derivation

  1. Split input into 2 regimes
  2. if z < -2.1021206699534236 or 32767434791329.156 < z

    1. Initial program 61.2

      \[\mathsf{fma}\left(x, y, z\right) - \left(1 + \left(x \cdot y + z\right)\right) \]
    2. Taylor expanded around 0 61.3

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, z\right) - \left(z + 1\right)} \]
    4. Using strategy rm
    5. Applied associate--r+_binary6419.2

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

    if -2.1021206699534236 < z < 32767434791329.156

    1. Initial program 29.6

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

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

Reproduce

herbie shell --seed 2021205 
(FPCore (x y z)
  :name "simple fma test"
  :precision binary64

  :herbie-target
  -1.0

  (- (fma x y z) (+ 1.0 (+ (* x y) z))))