Average Error: 6.5 → 1.5
Time: 5.5s
Precision: binary64
\[x + \frac{y \cdot \left(z - x\right)}{t} \]
\[\begin{array}{l} t_1 := x + \frac{y \cdot \left(z - x\right)}{t}\\ \mathbf{if}\;t_1 \leq 1.2501739841339764 \cdot 10^{-262}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\ \mathbf{elif}\;t_1 \leq 3.572500380492467 \cdot 10^{+302}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\ \end{array} \]
x + \frac{y \cdot \left(z - x\right)}{t}
\begin{array}{l}
t_1 := x + \frac{y \cdot \left(z - x\right)}{t}\\
\mathbf{if}\;t_1 \leq 1.2501739841339764 \cdot 10^{-262}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\

\mathbf{elif}\;t_1 \leq 3.572500380492467 \cdot 10^{+302}:\\
\;\;\;\;t_1\\

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


\end{array}
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (+ x (/ (* y (- z x)) t))))
   (if (<= t_1 1.2501739841339764e-262)
     (fma (/ y t) (- z x) x)
     (if (<= t_1 3.572500380492467e+302) t_1 (fma y (/ (- z x) t) 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 t_1 = x + ((y * (z - x)) / t);
	double tmp;
	if (t_1 <= 1.2501739841339764e-262) {
		tmp = fma((y / t), (z - x), x);
	} else if (t_1 <= 3.572500380492467e+302) {
		tmp = t_1;
	} else {
		tmp = fma(y, ((z - x) / t), x);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

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

Derivation

  1. Split input into 3 regimes
  2. if (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < 1.25017398413397638e-262

    1. Initial program 6.8

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

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

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

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

    if 1.25017398413397638e-262 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < 3.5725003804924667e302

    1. Initial program 0.6

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

    if 3.5725003804924667e302 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t))

    1. Initial program 56.5

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)} \]
    3. Applied *-un-lft-identity_binary643.0

      \[\leadsto \mathsf{fma}\left(y, \frac{z - x}{\color{blue}{1 \cdot t}}, x\right) \]
    4. Applied *-un-lft-identity_binary643.0

      \[\leadsto \mathsf{fma}\left(y, \frac{\color{blue}{1 \cdot \left(z - x\right)}}{1 \cdot t}, x\right) \]
    5. Applied times-frac_binary643.0

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{\frac{1}{1} \cdot \frac{z - x}{t}}, x\right) \]
    6. Simplified3.0

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

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

Reproduce

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