Average Error: 6.5 → 0.9
Time: 45.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}\\ t_2 := \mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\ \mathbf{if}\;t_1 \leq -2.8509297525329996 \cdot 10^{+295}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 3.7240731990415964 \cdot 10^{+256}:\\ \;\;\;\;\left(x + \frac{y \cdot z}{t}\right) - \frac{x \cdot y}{t}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \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}\\
t_2 := \mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\
\mathbf{if}\;t_1 \leq -2.8509297525329996 \cdot 10^{+295}:\\
\;\;\;\;t_2\\

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

\mathbf{else}:\\
\;\;\;\;t_2\\


\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))) (t_2 (fma (/ y t) (- z x) x)))
   (if (<= t_1 -2.8509297525329996e+295)
     t_2
     (if (<= t_1 3.7240731990415964e+256)
       (- (+ x (/ (* y z) t)) (/ (* x y) t))
       t_2))))
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 t_2 = fma((y / t), (z - x), x);
	double tmp;
	if (t_1 <= -2.8509297525329996e+295) {
		tmp = t_2;
	} else if (t_1 <= 3.7240731990415964e+256) {
		tmp = (x + ((y * z) / t)) - ((x * y) / t);
	} else {
		tmp = t_2;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.5
Target2.0
Herbie0.9
\[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)) < -2.8509297525329996e295 or 3.7240731990415964e256 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t))

    1. Initial program 38.6

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

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

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

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

    if -2.8509297525329996e295 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < 3.7240731990415964e256

    1. Initial program 0.7

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

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

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

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

Reproduce

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