Average Error: 7.5 → 0.3
Time: 4.5s
Precision: binary64
\[\frac{x + y}{1 - \frac{y}{z}}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \leq -7.0990859385572 \cdot 10^{-260}:\\ \;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{elif}\;\frac{x + y}{1 - \frac{y}{z}} \leq 0:\\ \;\;\;\;-\left(z + \frac{x \cdot z}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{1 - \frac{y}{z}} + \frac{x}{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 -7.0990859385572 \cdot 10^{-260}:\\
\;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{y}{1 - \frac{y}{z}} + \frac{x}{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))) -7.0990859385572e-260)
   (/ (+ x y) (- 1.0 (/ y z)))
   (if (<= (/ (+ x y) (- 1.0 (/ y z))) 0.0)
     (- (+ z (/ (* x z) y)))
     (+ (/ y (- 1.0 (/ y z))) (/ x (- 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))) <= -7.0990859385572e-260) {
		tmp = (x + y) / (1.0 - (y / z));
	} else if (((x + y) / (1.0 - (y / z))) <= 0.0) {
		tmp = -(z + ((x * z) / y));
	} else {
		tmp = (y / (1.0 - (y / z))) + (x / (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.2
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 3 regimes
  2. if (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < -7.09908593855719987e-260

    1. Initial program 0.1

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

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

    1. Initial program 55.7

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

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

      \[\leadsto \color{blue}{-\left(\frac{x}{\frac{y}{z}} + \left(z + \frac{z}{\frac{y}{z}}\right)\right)}\]
    4. Taylor expanded around 0 1.6

      \[\leadsto -\color{blue}{z \cdot \left(\frac{x}{y} + 1\right)}\]
    5. Simplified1.9

      \[\leadsto -\color{blue}{\left(z + \frac{z \cdot x}{y}\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}}\]
    2. Taylor expanded around 0 0.1

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

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

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

Reproduce

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