Average Error: 7.6 → 6.2
Time: 11.4s
Precision: 64
\[\frac{x + y}{1 - \frac{y}{z}}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \le -1.156936849784811698189254638210437357448 \cdot 10^{-284} \lor \neg \left(\frac{x + y}{1 - \frac{y}{z}} \le 0.0\right):\\ \;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{\sqrt{1} + \frac{\sqrt{y}}{\sqrt{z}}}}{\frac{1}{y + x} \cdot \left(\sqrt{1} - \frac{\sqrt{y}}{\sqrt{z}}\right)}\\ \end{array}\]
\frac{x + y}{1 - \frac{y}{z}}
\begin{array}{l}
\mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \le -1.156936849784811698189254638210437357448 \cdot 10^{-284} \lor \neg \left(\frac{x + y}{1 - \frac{y}{z}} \le 0.0\right):\\
\;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{1} + \frac{\sqrt{y}}{\sqrt{z}}}}{\frac{1}{y + x} \cdot \left(\sqrt{1} - \frac{\sqrt{y}}{\sqrt{z}}\right)}\\

\end{array}
double f(double x, double y, double z) {
        double r819473 = x;
        double r819474 = y;
        double r819475 = r819473 + r819474;
        double r819476 = 1.0;
        double r819477 = z;
        double r819478 = r819474 / r819477;
        double r819479 = r819476 - r819478;
        double r819480 = r819475 / r819479;
        return r819480;
}

double f(double x, double y, double z) {
        double r819481 = x;
        double r819482 = y;
        double r819483 = r819481 + r819482;
        double r819484 = 1.0;
        double r819485 = z;
        double r819486 = r819482 / r819485;
        double r819487 = r819484 - r819486;
        double r819488 = r819483 / r819487;
        double r819489 = -1.1569368497848117e-284;
        bool r819490 = r819488 <= r819489;
        double r819491 = 0.0;
        bool r819492 = r819488 <= r819491;
        double r819493 = !r819492;
        bool r819494 = r819490 || r819493;
        double r819495 = 1.0;
        double r819496 = sqrt(r819484);
        double r819497 = sqrt(r819482);
        double r819498 = sqrt(r819485);
        double r819499 = r819497 / r819498;
        double r819500 = r819496 + r819499;
        double r819501 = r819495 / r819500;
        double r819502 = r819482 + r819481;
        double r819503 = r819495 / r819502;
        double r819504 = r819496 - r819499;
        double r819505 = r819503 * r819504;
        double r819506 = r819501 / r819505;
        double r819507 = r819494 ? r819488 : r819506;
        return r819507;
}

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.6
Target4.0
Herbie6.2
\[\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))) < -1.1569368497848117e-284 or 0.0 < (/ (+ x y) (- 1.0 (/ y z)))

    1. Initial program 4.0

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

    if -1.1569368497848117e-284 < (/ (+ x y) (- 1.0 (/ y z))) < 0.0

    1. Initial program 57.0

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(1 - \frac{y}{z}\right) \cdot \frac{1}{x + y}}}\]
    6. Applied associate-/r*57.1

      \[\leadsto \color{blue}{\frac{\frac{1}{1 - \frac{y}{z}}}{\frac{1}{x + y}}}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt61.3

      \[\leadsto \frac{\frac{1}{1 - \frac{y}{\color{blue}{\sqrt{z} \cdot \sqrt{z}}}}}{\frac{1}{x + y}}\]
    9. Applied add-sqr-sqrt62.8

      \[\leadsto \frac{\frac{1}{1 - \frac{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}{\sqrt{z} \cdot \sqrt{z}}}}{\frac{1}{x + y}}\]
    10. Applied times-frac62.8

      \[\leadsto \frac{\frac{1}{1 - \color{blue}{\frac{\sqrt{y}}{\sqrt{z}} \cdot \frac{\sqrt{y}}{\sqrt{z}}}}}{\frac{1}{x + y}}\]
    11. Applied add-sqr-sqrt62.8

      \[\leadsto \frac{\frac{1}{\color{blue}{\sqrt{1} \cdot \sqrt{1}} - \frac{\sqrt{y}}{\sqrt{z}} \cdot \frac{\sqrt{y}}{\sqrt{z}}}}{\frac{1}{x + y}}\]
    12. Applied difference-of-squares62.8

      \[\leadsto \frac{\frac{1}{\color{blue}{\left(\sqrt{1} + \frac{\sqrt{y}}{\sqrt{z}}\right) \cdot \left(\sqrt{1} - \frac{\sqrt{y}}{\sqrt{z}}\right)}}}{\frac{1}{x + y}}\]
    13. Applied *-un-lft-identity62.8

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

      \[\leadsto \frac{\color{blue}{\frac{1}{\sqrt{1} + \frac{\sqrt{y}}{\sqrt{z}}} \cdot \frac{1}{\sqrt{1} - \frac{\sqrt{y}}{\sqrt{z}}}}}{\frac{1}{x + y}}\]
    15. Applied associate-/l*59.2

      \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{1} + \frac{\sqrt{y}}{\sqrt{z}}}}{\frac{\frac{1}{x + y}}{\frac{1}{\sqrt{1} - \frac{\sqrt{y}}{\sqrt{z}}}}}}\]
    16. Simplified59.2

      \[\leadsto \frac{\frac{1}{\sqrt{1} + \frac{\sqrt{y}}{\sqrt{z}}}}{\color{blue}{\frac{1}{y + x} \cdot \left(\sqrt{1} - \frac{\sqrt{y}}{\sqrt{z}}\right)}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification6.2

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

Reproduce

herbie shell --seed 2019350 +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))))