Average Error: 7.6 → 6.4
Time: 2.6s
Precision: 64
\[\frac{x + y}{1 - \frac{y}{z}}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \le -9.340220995992204435937211078763363155616 \cdot 10^{-288} \lor \neg \left(\frac{x + y}{1 - \frac{y}{z}} \le -0.0\right):\\ \;\;\;\;1 \cdot \frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{\sqrt{x + y}}{\sqrt{1} + \frac{\sqrt{y}}{\sqrt{z}}} \cdot \frac{\sqrt{x + y}}{\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 -9.340220995992204435937211078763363155616 \cdot 10^{-288} \lor \neg \left(\frac{x + y}{1 - \frac{y}{z}} \le -0.0\right):\\
\;\;\;\;1 \cdot \frac{x + y}{1 - \frac{y}{z}}\\

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

\end{array}
double f(double x, double y, double z) {
        double r575900 = x;
        double r575901 = y;
        double r575902 = r575900 + r575901;
        double r575903 = 1.0;
        double r575904 = z;
        double r575905 = r575901 / r575904;
        double r575906 = r575903 - r575905;
        double r575907 = r575902 / r575906;
        return r575907;
}

double f(double x, double y, double z) {
        double r575908 = x;
        double r575909 = y;
        double r575910 = r575908 + r575909;
        double r575911 = 1.0;
        double r575912 = z;
        double r575913 = r575909 / r575912;
        double r575914 = r575911 - r575913;
        double r575915 = r575910 / r575914;
        double r575916 = -9.340220995992204e-288;
        bool r575917 = r575915 <= r575916;
        double r575918 = -0.0;
        bool r575919 = r575915 <= r575918;
        double r575920 = !r575919;
        bool r575921 = r575917 || r575920;
        double r575922 = 1.0;
        double r575923 = r575922 * r575915;
        double r575924 = sqrt(r575910);
        double r575925 = sqrt(r575911);
        double r575926 = sqrt(r575909);
        double r575927 = sqrt(r575912);
        double r575928 = r575926 / r575927;
        double r575929 = r575925 + r575928;
        double r575930 = r575924 / r575929;
        double r575931 = r575925 - r575928;
        double r575932 = r575924 / r575931;
        double r575933 = r575930 * r575932;
        double r575934 = r575922 * r575933;
        double r575935 = r575921 ? r575923 : r575934;
        return r575935;
}

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
Target3.9
Herbie6.4
\[\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.340220995992204e-288 or -0.0 < (/ (+ x y) (- 1.0 (/ y z)))

    1. Initial program 4.1

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

      \[\leadsto \color{blue}{\left(x + y\right) \cdot \frac{1}{1 - \frac{y}{z}}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity4.2

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

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

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

    if -9.340220995992204e-288 < (/ (+ x y) (- 1.0 (/ y z))) < -0.0

    1. Initial program 57.3

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

      \[\leadsto \color{blue}{\left(x + y\right) \cdot \frac{1}{1 - \frac{y}{z}}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity57.3

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

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

      \[\leadsto 1 \cdot \color{blue}{\frac{x + y}{1 - \frac{y}{z}}}\]
    8. Using strategy rm
    9. Applied add-sqr-sqrt58.1

      \[\leadsto 1 \cdot \frac{x + y}{1 - \frac{y}{\color{blue}{\sqrt{z} \cdot \sqrt{z}}}}\]
    10. Applied add-sqr-sqrt61.0

      \[\leadsto 1 \cdot \frac{x + y}{1 - \frac{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}{\sqrt{z} \cdot \sqrt{z}}}\]
    11. Applied times-frac61.0

      \[\leadsto 1 \cdot \frac{x + y}{1 - \color{blue}{\frac{\sqrt{y}}{\sqrt{z}} \cdot \frac{\sqrt{y}}{\sqrt{z}}}}\]
    12. Applied add-sqr-sqrt61.0

      \[\leadsto 1 \cdot \frac{x + y}{\color{blue}{\sqrt{1} \cdot \sqrt{1}} - \frac{\sqrt{y}}{\sqrt{z}} \cdot \frac{\sqrt{y}}{\sqrt{z}}}\]
    13. Applied difference-of-squares61.0

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

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

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

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

Reproduce

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