Average Error: 6.3 → 1.7
Time: 3.4s
Precision: binary64
\[x + \frac{y \cdot \left(z - x\right)}{t} \]
\[\begin{array}{l} \mathbf{if}\;y \leq -1.060814198893335 \cdot 10^{-33}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\ \end{array} \]
x + \frac{y \cdot \left(z - x\right)}{t}
\begin{array}{l}
\mathbf{if}\;y \leq -1.060814198893335 \cdot 10^{-33}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\

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


\end{array}
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
(FPCore (x y z t)
 :precision binary64
 (if (<= y -1.060814198893335e-33)
   (fma y (/ (- z x) t) x)
   (fma (/ y t) (- z x) x)))
double code(double x, double y, double z, double t) {
	return x + ((y * (z - x)) / t);
}
double code(double x, double y, double z, double t) {
	double tmp;
	if (y <= -1.060814198893335e-33) {
		tmp = fma(y, ((z - x) / t), x);
	} else {
		tmp = fma((y / t), (z - x), x);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.3
Target2.1
Herbie1.7
\[x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right) \]

Derivation

  1. Split input into 2 regimes
  2. if y < -1.06081419889333503e-33

    1. Initial program 13.3

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Simplified1.4

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

    if -1.06081419889333503e-33 < y

    1. Initial program 4.3

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Taylor expanded in x around 0 4.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.060814198893335 \cdot 10^{-33}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2021313 
(FPCore (x y z t)
  :name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, D"
  :precision binary64

  :herbie-target
  (- x (+ (* x (/ y t)) (* (- z) (/ y t))))

  (+ x (/ (* y (- z x)) t)))