Average Error: 7.4 → 0.3
Time: 10.0s
Precision: 64
\[\frac{x + y}{1 - \frac{y}{z}}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \le -2.2519815773743544 \cdot 10^{-277} \lor \neg \left(\frac{x + y}{1 - \frac{y}{z}} \le 2.33409700591582791 \cdot 10^{148}\right):\\ \;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1}{y + x} - \frac{\frac{y}{y + x}}{z}}\\ \end{array}\]
\frac{x + y}{1 - \frac{y}{z}}
\begin{array}{l}
\mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \le -2.2519815773743544 \cdot 10^{-277} \lor \neg \left(\frac{x + y}{1 - \frac{y}{z}} \le 2.33409700591582791 \cdot 10^{148}\right):\\
\;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\

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

\end{array}
double f(double x, double y, double z) {
        double r690742 = x;
        double r690743 = y;
        double r690744 = r690742 + r690743;
        double r690745 = 1.0;
        double r690746 = z;
        double r690747 = r690743 / r690746;
        double r690748 = r690745 - r690747;
        double r690749 = r690744 / r690748;
        return r690749;
}

double f(double x, double y, double z) {
        double r690750 = x;
        double r690751 = y;
        double r690752 = r690750 + r690751;
        double r690753 = 1.0;
        double r690754 = z;
        double r690755 = r690751 / r690754;
        double r690756 = r690753 - r690755;
        double r690757 = r690752 / r690756;
        double r690758 = -2.2519815773743544e-277;
        bool r690759 = r690757 <= r690758;
        double r690760 = 2.334097005915828e+148;
        bool r690761 = r690757 <= r690760;
        double r690762 = !r690761;
        bool r690763 = r690759 || r690762;
        double r690764 = 1.0;
        double r690765 = r690751 + r690750;
        double r690766 = r690753 / r690765;
        double r690767 = r690751 / r690765;
        double r690768 = r690767 / r690754;
        double r690769 = r690766 - r690768;
        double r690770 = r690764 / r690769;
        double r690771 = r690763 ? r690757 : r690770;
        return r690771;
}

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.4
Target3.8
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;y \lt -3.74293107626898565 \cdot 10^{171}:\\ \;\;\;\;\frac{y + x}{-y} \cdot z\\ \mathbf{elif}\;y \lt 3.55346624560867344 \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 (/ (+ x y) (- 1.0 (/ y z))) < -2.2519815773743544e-277 or 2.334097005915828e+148 < (/ (+ x y) (- 1.0 (/ y z)))

    1. Initial program 0.1

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

    if -2.2519815773743544e-277 < (/ (+ x y) (- 1.0 (/ y z))) < 2.334097005915828e+148

    1. Initial program 16.0

      \[\frac{x + y}{1 - \frac{y}{z}}\]
    2. Using strategy rm
    3. Applied clear-num16.1

      \[\leadsto \color{blue}{\frac{1}{\frac{1 - \frac{y}{z}}{x + y}}}\]
    4. Using strategy rm
    5. Applied div-sub16.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \le -2.2519815773743544 \cdot 10^{-277} \lor \neg \left(\frac{x + y}{1 - \frac{y}{z}} \le 2.33409700591582791 \cdot 10^{148}\right):\\ \;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1}{y + x} - \frac{\frac{y}{y + x}}{z}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020047 +o rules:numerics
(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 (/ y z))) (* (/ (+ y x) (- y)) z)))

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