Average Error: 4.7 → 0.7
Time: 2.2s
Precision: binary64
\[x + \frac{y \cdot \left(z - x\right)}{t} \]
\[\begin{array}{l} \mathbf{if}\;\begin{array}{l} t_1 := x + \frac{y \cdot \left(z - x\right)}{t}\\ t_1 \leq -\infty \lor \neg \left(t_1 \leq 7.007929757441067 \cdot 10^{+254}\right) \end{array}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y \cdot z, \frac{1}{t}, x\right) - \frac{x \cdot y}{t}\\ \end{array} \]
x + \frac{y \cdot \left(z - x\right)}{t}
\begin{array}{l}
\mathbf{if}\;\begin{array}{l}
t_1 := x + \frac{y \cdot \left(z - x\right)}{t}\\
t_1 \leq -\infty \lor \neg \left(t_1 \leq 7.007929757441067 \cdot 10^{+254}\right)
\end{array}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\

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


\end{array}
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
(FPCore (x y z t)
 :precision binary64
 (if (let* ((t_1 (+ x (/ (* y (- z x)) t))))
       (or (<= t_1 (- INFINITY)) (not (<= t_1 7.007929757441067e+254))))
   (fma (/ y t) (- z x) x)
   (- (fma (* y z) (/ 1.0 t) x) (/ (* x y) t))))
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 t_1 = x + ((y * (z - x)) / t);
	double tmp;
	if ((t_1 <= -((double) INFINITY)) || !(t_1 <= 7.007929757441067e+254)) {
		tmp = fma((y / t), (z - x), x);
	} else {
		tmp = fma((y * z), (1.0 / t), x) - ((x * y) / t);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.7
Target5.8
Herbie0.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 (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < -inf.0 or 7.007929757441067e254 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t))

    1. Initial program 11.6

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)} \]
    3. Taylor expanded in y around 0 20.0

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

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

    if -inf.0 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < 7.007929757441067e254

    1. Initial program 0.9

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)} \]
    3. Taylor expanded in y around 0 0.9

      \[\leadsto \color{blue}{\left(\frac{y \cdot z}{t} + x\right) - \frac{y \cdot x}{t}} \]
    4. Applied div-inv_binary640.9

      \[\leadsto \left(\color{blue}{\left(y \cdot z\right) \cdot \frac{1}{t}} + x\right) - \frac{y \cdot x}{t} \]
    5. Applied fma-def_binary640.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x + \frac{y \cdot \left(z - x\right)}{t} \leq -\infty \lor \neg \left(x + \frac{y \cdot \left(z - x\right)}{t} \leq 7.007929757441067 \cdot 10^{+254}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y \cdot z, \frac{1}{t}, x\right) - \frac{x \cdot y}{t}\\ \end{array} \]

Reproduce

herbie shell --seed 2022088 
(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)))