Average Error: 6.3 → 2.3
Time: 3.8s
Precision: binary64
\[x + \frac{y \cdot \left(z - x\right)}{t} \]
\[\begin{array}{l} \mathbf{if}\;x \leq 5.875674242652246 \cdot 10^{-297}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\ \mathbf{elif}\;x \leq 3.325314396267599 \cdot 10^{-150}:\\ \;\;\;\;x + \frac{y \cdot \left(z - x\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{1}{\frac{\frac{t}{y}}{z - x}}\\ \end{array} \]
x + \frac{y \cdot \left(z - x\right)}{t}
\begin{array}{l}
\mathbf{if}\;x \leq 5.875674242652246 \cdot 10^{-297}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\

\mathbf{elif}\;x \leq 3.325314396267599 \cdot 10^{-150}:\\
\;\;\;\;x + \frac{y \cdot \left(z - x\right)}{t}\\

\mathbf{else}:\\
\;\;\;\;x + \frac{1}{\frac{\frac{t}{y}}{z - x}}\\


\end{array}
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
(FPCore (x y z t)
 :precision binary64
 (if (<= x 5.875674242652246e-297)
   (fma (/ y t) (- z x) x)
   (if (<= x 3.325314396267599e-150)
     (+ x (/ (* y (- z x)) t))
     (+ x (/ 1.0 (/ (/ t y) (- z 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 (x <= 5.875674242652246e-297) {
		tmp = fma((y / t), (z - x), x);
	} else if (x <= 3.325314396267599e-150) {
		tmp = x + ((y * (z - x)) / t);
	} else {
		tmp = x + (1.0 / ((t / y) / (z - x)));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

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

Derivation

  1. Split input into 3 regimes
  2. if x < 5.87567424265224604e-297

    1. Initial program 5.9

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

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

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

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

    if 5.87567424265224604e-297 < x < 3.325314396267599e-150

    1. Initial program 5.6

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

    if 3.325314396267599e-150 < x

    1. Initial program 7.3

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

      \[\leadsto x + \color{blue}{\frac{1}{\frac{t}{y \cdot \left(z - x\right)}}} \]
    3. Applied associate-/r*_binary640.7

      \[\leadsto x + \frac{1}{\color{blue}{\frac{\frac{t}{y}}{z - x}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 5.875674242652246 \cdot 10^{-297}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\ \mathbf{elif}\;x \leq 3.325314396267599 \cdot 10^{-150}:\\ \;\;\;\;x + \frac{y \cdot \left(z - x\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{1}{\frac{\frac{t}{y}}{z - x}}\\ \end{array} \]

Reproduce

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