Average Error: 7.5 → 6.3
Time: 8.8s
Precision: 64
\[\frac{x + y}{1 - \frac{y}{z}}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \le -2.925931943862631 \cdot 10^{-271} \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}{\frac{\sqrt{y}}{\sqrt{z}} + \sqrt{1}}}{\frac{\sqrt{1} - \frac{\sqrt{y}}{\sqrt{z}}}{x + y}}\\ \end{array}\]
\frac{x + y}{1 - \frac{y}{z}}
\begin{array}{l}
\mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \le -2.925931943862631 \cdot 10^{-271} \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}{\frac{\sqrt{y}}{\sqrt{z}} + \sqrt{1}}}{\frac{\sqrt{1} - \frac{\sqrt{y}}{\sqrt{z}}}{x + y}}\\

\end{array}
double f(double x, double y, double z) {
        double r693669 = x;
        double r693670 = y;
        double r693671 = r693669 + r693670;
        double r693672 = 1.0;
        double r693673 = z;
        double r693674 = r693670 / r693673;
        double r693675 = r693672 - r693674;
        double r693676 = r693671 / r693675;
        return r693676;
}

double f(double x, double y, double z) {
        double r693677 = x;
        double r693678 = y;
        double r693679 = r693677 + r693678;
        double r693680 = 1.0;
        double r693681 = z;
        double r693682 = r693678 / r693681;
        double r693683 = r693680 - r693682;
        double r693684 = r693679 / r693683;
        double r693685 = -2.925931943862631e-271;
        bool r693686 = r693684 <= r693685;
        double r693687 = 0.0;
        bool r693688 = r693684 <= r693687;
        double r693689 = !r693688;
        bool r693690 = r693686 || r693689;
        double r693691 = 1.0;
        double r693692 = sqrt(r693678);
        double r693693 = sqrt(r693681);
        double r693694 = r693692 / r693693;
        double r693695 = sqrt(r693680);
        double r693696 = r693694 + r693695;
        double r693697 = r693691 / r693696;
        double r693698 = r693695 - r693694;
        double r693699 = r693698 / r693679;
        double r693700 = r693697 / r693699;
        double r693701 = r693690 ? r693684 : r693700;
        return r693701;
}

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
Target3.9
Herbie6.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.925931943862631e-271 or 0.0 < (/ (+ x y) (- 1.0 (/ y z)))

    1. Initial program 0.1

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

    if -2.925931943862631e-271 < (/ (+ x y) (- 1.0 (/ y z))) < 0.0

    1. Initial program 57.2

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

      \[\leadsto \color{blue}{\frac{1}{\frac{1 - \frac{y}{z}}{x + y}}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity57.2

      \[\leadsto \frac{1}{\frac{1 - \frac{y}{z}}{\color{blue}{1 \cdot \left(x + y\right)}}}\]
    6. Applied add-sqr-sqrt59.5

      \[\leadsto \frac{1}{\frac{1 - \frac{y}{\color{blue}{\sqrt{z} \cdot \sqrt{z}}}}{1 \cdot \left(x + y\right)}}\]
    7. Applied add-sqr-sqrt61.9

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

      \[\leadsto \frac{1}{\frac{1 - \color{blue}{\frac{\sqrt{y}}{\sqrt{z}} \cdot \frac{\sqrt{y}}{\sqrt{z}}}}{1 \cdot \left(x + y\right)}}\]
    9. Applied add-sqr-sqrt61.9

      \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}} - \frac{\sqrt{y}}{\sqrt{z}} \cdot \frac{\sqrt{y}}{\sqrt{z}}}{1 \cdot \left(x + y\right)}}\]
    10. Applied difference-of-squares61.9

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{1} + \frac{\sqrt{y}}{\sqrt{z}}}{1} \cdot \frac{\sqrt{1} - \frac{\sqrt{y}}{\sqrt{z}}}{x + y}}}\]
    12. Applied associate-/r*47.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \le -2.925931943862631 \cdot 10^{-271} \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}{\frac{\sqrt{y}}{\sqrt{z}} + \sqrt{1}}}{\frac{\sqrt{1} - \frac{\sqrt{y}}{\sqrt{z}}}{x + y}}\\ \end{array}\]

Reproduce

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