Average Error: 6.8 → 2.1
Time: 7.9s
Precision: binary64
\[x + \frac{y \cdot \left(z - x\right)}{t} \]
\[\begin{array}{l} \mathbf{if}\;z \leq -5.7190163307483135 \cdot 10^{-77}:\\ \;\;\;\;x + \frac{y}{t} \cdot \left(z - x\right)\\ \mathbf{elif}\;z \leq -6.611843170999734 \cdot 10^{-264}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z}{t} - \frac{x}{t}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_1 := \mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\ \mathbf{if}\;z \leq 1.7432692600882257 \cdot 10^{-152}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.1627240810470034 \cdot 10^{-97}:\\ \;\;\;\;\begin{array}{l} t_2 := \sqrt[3]{y \cdot \frac{x}{t}}\\ \left(x + \frac{z \cdot y}{t}\right) - t_2 \cdot \left(t_2 \cdot t_2\right) \end{array}\\ \mathbf{elif}\;z \leq 6.146152116507481 \cdot 10^{-87}:\\ \;\;\;\;x + \frac{y \cdot \left(z - x\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array}\\ \end{array} \]
x + \frac{y \cdot \left(z - x\right)}{t}
\begin{array}{l}
\mathbf{if}\;z \leq -5.7190163307483135 \cdot 10^{-77}:\\
\;\;\;\;x + \frac{y}{t} \cdot \left(z - x\right)\\

\mathbf{elif}\;z \leq -6.611843170999734 \cdot 10^{-264}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z}{t} - \frac{x}{t}, x\right)\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\
\mathbf{if}\;z \leq 1.7432692600882257 \cdot 10^{-152}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \leq 1.1627240810470034 \cdot 10^{-97}:\\
\;\;\;\;\begin{array}{l}
t_2 := \sqrt[3]{y \cdot \frac{x}{t}}\\
\left(x + \frac{z \cdot y}{t}\right) - t_2 \cdot \left(t_2 \cdot t_2\right)
\end{array}\\

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

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}\\


\end{array}
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
(FPCore (x y z t)
 :precision binary64
 (if (<= z -5.7190163307483135e-77)
   (+ x (* (/ y t) (- z x)))
   (if (<= z -6.611843170999734e-264)
     (fma y (- (/ z t) (/ x t)) x)
     (let* ((t_1 (fma (/ y t) (- z x) x)))
       (if (<= z 1.7432692600882257e-152)
         t_1
         (if (<= z 1.1627240810470034e-97)
           (let* ((t_2 (cbrt (* y (/ x t)))))
             (- (+ x (/ (* z y) t)) (* t_2 (* t_2 t_2))))
           (if (<= z 6.146152116507481e-87)
             (+ x (/ (* y (- z x)) t))
             t_1)))))))
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 (z <= -5.7190163307483135e-77) {
		tmp = x + ((y / t) * (z - x));
	} else if (z <= -6.611843170999734e-264) {
		tmp = fma(y, ((z / t) - (x / t)), x);
	} else {
		double t_1 = fma((y / t), (z - x), x);
		double tmp_1;
		if (z <= 1.7432692600882257e-152) {
			tmp_1 = t_1;
		} else if (z <= 1.1627240810470034e-97) {
			double t_2 = cbrt(y * (x / t));
			tmp_1 = (x + ((z * y) / t)) - (t_2 * (t_2 * t_2));
		} else if (z <= 6.146152116507481e-87) {
			tmp_1 = x + ((y * (z - x)) / t);
		} else {
			tmp_1 = t_1;
		}
		tmp = tmp_1;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.8
Target1.9
Herbie2.1
\[x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right) \]

Derivation

  1. Split input into 5 regimes
  2. if z < -5.71901633074831347e-77

    1. Initial program 8.3

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

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

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

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

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

    if -5.71901633074831347e-77 < z < -6.6118431709997337e-264

    1. Initial program 4.9

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

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

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

    if -6.6118431709997337e-264 < z < 1.7432692600882257e-152 or 6.14615211650748113e-87 < z

    1. Initial program 6.9

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

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

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

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

    if 1.7432692600882257e-152 < z < 1.16272408104700338e-97

    1. Initial program 4.0

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

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

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

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

      \[\leadsto \left(\frac{y \cdot z}{t} + x\right) - \color{blue}{\left(\sqrt[3]{\frac{x}{t} \cdot y} \cdot \sqrt[3]{\frac{x}{t} \cdot y}\right)} \cdot \sqrt[3]{\frac{y \cdot x}{t}} \]
    6. Simplified3.8

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

    if 1.16272408104700338e-97 < z < 6.14615211650748113e-87

    1. Initial program 2.7

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification2.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -5.7190163307483135 \cdot 10^{-77}:\\ \;\;\;\;x + \frac{y}{t} \cdot \left(z - x\right)\\ \mathbf{elif}\;z \leq -6.611843170999734 \cdot 10^{-264}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z}{t} - \frac{x}{t}, x\right)\\ \mathbf{elif}\;z \leq 1.7432692600882257 \cdot 10^{-152}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\ \mathbf{elif}\;z \leq 1.1627240810470034 \cdot 10^{-97}:\\ \;\;\;\;\left(x + \frac{z \cdot y}{t}\right) - \sqrt[3]{y \cdot \frac{x}{t}} \cdot \left(\sqrt[3]{y \cdot \frac{x}{t}} \cdot \sqrt[3]{y \cdot \frac{x}{t}}\right)\\ \mathbf{elif}\;z \leq 6.146152116507481 \cdot 10^{-87}:\\ \;\;\;\;x + \frac{y \cdot \left(z - x\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\ \end{array} \]

Reproduce

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