Average Error: 7.9 → 0.3
Time: 4.9s
Precision: binary64
\[\frac{x + y}{1 - \frac{y}{z}} \]
\[\begin{array}{l} t_0 := \frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{if}\;t_0 \leq -1.7781855660516165 \cdot 10^{-256} \lor \neg \left(t_0 \leq 0\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_1 := \frac{z}{\sqrt[3]{-1}}\\ \mathsf{fma}\left(t_1, \frac{x}{y}, t_1\right) - \frac{z \cdot z}{y \cdot {\left(\sqrt[3]{-1}\right)}^{2}} \end{array}\\ \end{array} \]
\frac{x + y}{1 - \frac{y}{z}}
\begin{array}{l}
t_0 := \frac{x + y}{1 - \frac{y}{z}}\\
\mathbf{if}\;t_0 \leq -1.7781855660516165 \cdot 10^{-256} \lor \neg \left(t_0 \leq 0\right):\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_1 := \frac{z}{\sqrt[3]{-1}}\\
\mathsf{fma}\left(t_1, \frac{x}{y}, t_1\right) - \frac{z \cdot z}{y \cdot {\left(\sqrt[3]{-1}\right)}^{2}}
\end{array}\\


\end{array}
(FPCore (x y z) :precision binary64 (/ (+ x y) (- 1.0 (/ y z))))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (+ x y) (- 1.0 (/ y z)))))
   (if (or (<= t_0 -1.7781855660516165e-256) (not (<= t_0 0.0)))
     t_0
     (let* ((t_1 (/ z (cbrt -1.0))))
       (- (fma t_1 (/ x y) t_1) (/ (* z z) (* y (pow (cbrt -1.0) 2.0))))))))
double code(double x, double y, double z) {
	return (x + y) / (1.0 - (y / z));
}
double code(double x, double y, double z) {
	double t_0 = (x + y) / (1.0 - (y / z));
	double tmp;
	if ((t_0 <= -1.7781855660516165e-256) || !(t_0 <= 0.0)) {
		tmp = t_0;
	} else {
		double t_1 = z / cbrt(-1.0);
		tmp = fma(t_1, (x / y), t_1) - ((z * z) / (y * pow(cbrt(-1.0), 2.0)));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original7.9
Target4.0
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;y < -3.7429310762689856 \cdot 10^{+171}:\\ \;\;\;\;\frac{y + x}{-y} \cdot z\\ \mathbf{elif}\;y < 3.5534662456086734 \cdot 10^{+168}:\\ \;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{y + x}{-y} \cdot z\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < -1.7781855660516165e-256 or -0.0 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z)))

    1. Initial program 0.1

      \[\frac{x + y}{1 - \frac{y}{z}} \]

    if -1.7781855660516165e-256 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < -0.0

    1. Initial program 55.8

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Applied *-un-lft-identity_binary6455.8

      \[\leadsto \frac{x + y}{1 - \frac{y}{\color{blue}{1 \cdot z}}} \]
    3. Applied add-cube-cbrt_binary6455.9

      \[\leadsto \frac{x + y}{1 - \frac{\color{blue}{\left(\sqrt[3]{y} \cdot \sqrt[3]{y}\right) \cdot \sqrt[3]{y}}}{1 \cdot z}} \]
    4. Applied times-frac_binary6455.9

      \[\leadsto \frac{x + y}{1 - \color{blue}{\frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{1} \cdot \frac{\sqrt[3]{y}}{z}}} \]
    5. Applied cancel-sign-sub-inv_binary6455.9

      \[\leadsto \frac{x + y}{\color{blue}{1 + \left(-\frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{1}\right) \cdot \frac{\sqrt[3]{y}}{z}}} \]
    6. Applied add-cbrt-cube_binary6456.6

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

      \[\leadsto \frac{x + y}{1 + \left(-\frac{\sqrt[3]{\color{blue}{y \cdot y}}}{1}\right) \cdot \frac{\sqrt[3]{y}}{z}} \]
    8. Taylor expanded in y around -inf 1.6

      \[\leadsto \color{blue}{\left(\frac{z \cdot x}{y \cdot \sqrt[3]{-1}} + \frac{z}{\sqrt[3]{-1}}\right) - \frac{{z}^{2}}{y \cdot {\left(\sqrt[3]{-1}\right)}^{2}}} \]
    9. Simplified1.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \leq -1.7781855660516165 \cdot 10^{-256} \lor \neg \left(\frac{x + y}{1 - \frac{y}{z}} \leq 0\right):\\ \;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{\sqrt[3]{-1}}, \frac{x}{y}, \frac{z}{\sqrt[3]{-1}}\right) - \frac{z \cdot z}{y \cdot {\left(\sqrt[3]{-1}\right)}^{2}}\\ \end{array} \]

Reproduce

herbie shell --seed 2022088 
(FPCore (x y z)
  :name "Graphics.Rendering.Chart.Backend.Diagrams:calcFontMetrics from Chart-diagrams-1.5.1, A"
  :precision binary64

  :herbie-target
  (if (< y -3.7429310762689856e+171) (* (/ (+ y x) (- y)) z) (if (< y 3.5534662456086734e+168) (/ (+ x y) (- 1.0 (/ y z))) (* (/ (+ y x) (- y)) z)))

  (/ (+ x y) (- 1.0 (/ y z))))