Average Error: 7.7 → 0.1
Time: 14.1s
Precision: 64
\[\frac{x + y}{1 - \frac{y}{z}}\]
\[\begin{array}{l} \mathbf{if}\;\frac{y + x}{1 - \frac{y}{z}} \le -9.485713529026146195518605196585595984311 \cdot 10^{-306} \lor \neg \left(\frac{y + x}{1 - \frac{y}{z}} \le 0.0\right):\\ \;\;\;\;\frac{y + x}{1 - \frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1}{y + x} - \frac{\frac{1}{z}}{y + x} \cdot y}\\ \end{array}\]
\frac{x + y}{1 - \frac{y}{z}}
\begin{array}{l}
\mathbf{if}\;\frac{y + x}{1 - \frac{y}{z}} \le -9.485713529026146195518605196585595984311 \cdot 10^{-306} \lor \neg \left(\frac{y + x}{1 - \frac{y}{z}} \le 0.0\right):\\
\;\;\;\;\frac{y + x}{1 - \frac{y}{z}}\\

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

\end{array}
double f(double x, double y, double z) {
        double r531831 = x;
        double r531832 = y;
        double r531833 = r531831 + r531832;
        double r531834 = 1.0;
        double r531835 = z;
        double r531836 = r531832 / r531835;
        double r531837 = r531834 - r531836;
        double r531838 = r531833 / r531837;
        return r531838;
}

double f(double x, double y, double z) {
        double r531839 = y;
        double r531840 = x;
        double r531841 = r531839 + r531840;
        double r531842 = 1.0;
        double r531843 = z;
        double r531844 = r531839 / r531843;
        double r531845 = r531842 - r531844;
        double r531846 = r531841 / r531845;
        double r531847 = -9.485713529026146e-306;
        bool r531848 = r531846 <= r531847;
        double r531849 = 0.0;
        bool r531850 = r531846 <= r531849;
        double r531851 = !r531850;
        bool r531852 = r531848 || r531851;
        double r531853 = 1.0;
        double r531854 = r531842 / r531841;
        double r531855 = r531853 / r531843;
        double r531856 = r531855 / r531841;
        double r531857 = r531856 * r531839;
        double r531858 = r531854 - r531857;
        double r531859 = r531853 / r531858;
        double r531860 = r531852 ? r531846 : r531859;
        return r531860;
}

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.7
Target3.8
Herbie0.1
\[\begin{array}{l} \mathbf{if}\;y \lt -3.742931076268985646434612946949172132145 \cdot 10^{171}:\\ \;\;\;\;\frac{y + x}{-y} \cdot z\\ \mathbf{elif}\;y \lt 3.553466245608673435460441960303815115662 \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))) < -9.485713529026146e-306 or 0.0 < (/ (+ x y) (- 1.0 (/ y z)))

    1. Initial program 4.2

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

    if -9.485713529026146e-306 < (/ (+ x y) (- 1.0 (/ y z))) < 0.0

    1. Initial program 60.0

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

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

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

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

      \[\leadsto \frac{1}{\frac{1}{y + x} - \color{blue}{\frac{y}{\left(y + x\right) \cdot z}}}\]
    8. Using strategy rm
    9. Applied div-inv0.4

      \[\leadsto \frac{1}{\frac{1}{y + x} - \color{blue}{y \cdot \frac{1}{\left(y + x\right) \cdot z}}}\]
    10. Simplified0.3

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

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

Reproduce

herbie shell --seed 2019194 +o rules:numerics
(FPCore (x y z)
  :name "Graphics.Rendering.Chart.Backend.Diagrams:calcFontMetrics from Chart-diagrams-1.5.1, A"

  :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))))