Average Error: 7.5 → 0.2
Time: 16.0s
Precision: binary64
\[\frac{x + y}{1 - \frac{y}{z}}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \leq -2.7109266182334705 \cdot 10^{-272}:\\ \;\;\;\;\frac{x}{1 - \frac{y}{z}} + \frac{y}{1 - \frac{y}{z}}\\ \mathbf{elif}\;\frac{x + y}{1 - \frac{y}{z}} \leq 0:\\ \;\;\;\;-\left(\frac{x \cdot z}{y} + \left(z + \frac{z \cdot z}{y}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\ \end{array}\]
\frac{x + y}{1 - \frac{y}{z}}
\begin{array}{l}
\mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \leq -2.7109266182334705 \cdot 10^{-272}:\\
\;\;\;\;\frac{x}{1 - \frac{y}{z}} + \frac{y}{1 - \frac{y}{z}}\\

\mathbf{elif}\;\frac{x + y}{1 - \frac{y}{z}} \leq 0:\\
\;\;\;\;-\left(\frac{x \cdot z}{y} + \left(z + \frac{z \cdot z}{y}\right)\right)\\

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

\end{array}
(FPCore (x y z) :precision binary64 (/ (+ x y) (- 1.0 (/ y z))))
(FPCore (x y z)
 :precision binary64
 (if (<= (/ (+ x y) (- 1.0 (/ y z))) -2.7109266182334705e-272)
   (+ (/ x (- 1.0 (/ y z))) (/ y (- 1.0 (/ y z))))
   (if (<= (/ (+ x y) (- 1.0 (/ y z))) 0.0)
     (- (+ (/ (* x z) y) (+ z (/ (* z z) y))))
     (/ (+ x y) (- 1.0 (/ y z))))))
double code(double x, double y, double z) {
	return (x + y) / (1.0 - (y / z));
}
double code(double x, double y, double z) {
	double tmp;
	if (((x + y) / (1.0 - (y / z))) <= -2.7109266182334705e-272) {
		tmp = (x / (1.0 - (y / z))) + (y / (1.0 - (y / z)));
	} else if (((x + y) / (1.0 - (y / z))) <= 0.0) {
		tmp = -(((x * z) / y) + (z + ((z * z) / y)));
	} else {
		tmp = (x + y) / (1.0 - (y / z));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.5
Target4.0
Herbie0.2
\[\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 3 regimes
  2. if (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < -2.71092661823347047e-272

    1. Initial program 0.1

      \[\frac{x + y}{1 - \frac{y}{z}}\]
    2. Taylor expanded around 0 0.1

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

    if -2.71092661823347047e-272 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < -0.0

    1. Initial program 57.8

      \[\frac{x + y}{1 - \frac{y}{z}}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity_binary64_1644657.8

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

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

      \[\leadsto \color{blue}{\frac{\sqrt[3]{x + y} \cdot \sqrt[3]{x + y}}{1} \cdot \frac{\sqrt[3]{x + y}}{1 - \frac{y}{z}}}\]
    6. Simplified57.8

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

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

      \[\leadsto \color{blue}{-\left(\frac{x \cdot z}{y} + \left(z + \frac{{z}^{2}}{y}\right)\right)}\]
    9. Simplified0.6

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

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

    1. Initial program 0.1

      \[\frac{x + y}{1 - \frac{y}{z}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \leq -2.7109266182334705 \cdot 10^{-272}:\\ \;\;\;\;\frac{x}{1 - \frac{y}{z}} + \frac{y}{1 - \frac{y}{z}}\\ \mathbf{elif}\;\frac{x + y}{1 - \frac{y}{z}} \leq 0:\\ \;\;\;\;-\left(\frac{x \cdot z}{y} + \left(z + \frac{z \cdot z}{y}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\ \end{array}\]

Reproduce

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