Average Error: 7.7 → 0.3
Time: 18.8s
Precision: 64
\[\frac{x + y}{1 - \frac{y}{z}}\]
\[\begin{array}{l} \mathbf{if}\;y \le -3804463401516451582560274122539008 \lor \neg \left(y \le 9.040221842917234755744157583213251960827 \cdot 10^{67}\right):\\ \;\;\;\;\frac{1}{\frac{1}{y + x} - \frac{y}{y + x} \cdot \frac{1}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\ \end{array}\]
\frac{x + y}{1 - \frac{y}{z}}
\begin{array}{l}
\mathbf{if}\;y \le -3804463401516451582560274122539008 \lor \neg \left(y \le 9.040221842917234755744157583213251960827 \cdot 10^{67}\right):\\
\;\;\;\;\frac{1}{\frac{1}{y + x} - \frac{y}{y + x} \cdot \frac{1}{z}}\\

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

\end{array}
double f(double x, double y, double z) {
        double r407165 = x;
        double r407166 = y;
        double r407167 = r407165 + r407166;
        double r407168 = 1.0;
        double r407169 = z;
        double r407170 = r407166 / r407169;
        double r407171 = r407168 - r407170;
        double r407172 = r407167 / r407171;
        return r407172;
}

double f(double x, double y, double z) {
        double r407173 = y;
        double r407174 = -3.8044634015164516e+33;
        bool r407175 = r407173 <= r407174;
        double r407176 = 9.040221842917235e+67;
        bool r407177 = r407173 <= r407176;
        double r407178 = !r407177;
        bool r407179 = r407175 || r407178;
        double r407180 = 1.0;
        double r407181 = 1.0;
        double r407182 = x;
        double r407183 = r407173 + r407182;
        double r407184 = r407181 / r407183;
        double r407185 = r407173 / r407183;
        double r407186 = z;
        double r407187 = r407180 / r407186;
        double r407188 = r407185 * r407187;
        double r407189 = r407184 - r407188;
        double r407190 = r407180 / r407189;
        double r407191 = r407182 + r407173;
        double r407192 = r407173 / r407186;
        double r407193 = r407181 - r407192;
        double r407194 = r407191 / r407193;
        double r407195 = r407179 ? r407190 : r407194;
        return r407195;
}

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
Target4.2
Herbie0.3
\[\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 y < -3.8044634015164516e+33 or 9.040221842917235e+67 < y

    1. Initial program 17.8

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

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

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

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

      \[\leadsto \frac{1}{\frac{1}{y + x} - \color{blue}{\frac{\frac{y}{y + x}}{z}}}\]
    8. Using strategy rm
    9. Applied div-inv0.2

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

    if -3.8044634015164516e+33 < y < 9.040221842917235e+67

    1. Initial program 0.4

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

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

Reproduce

herbie shell --seed 2019304 +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.74293107626898565e171) (* (/ (+ y x) (- y)) z) (if (< y 3.55346624560867344e168) (/ (+ x y) (- 1 (/ y z))) (* (/ (+ y x) (- y)) z)))

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