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}:\\ \;\;\;\;\frac{\sqrt{x + y}}{\sqrt{1} + \frac{\sqrt{y}}{\sqrt{z}}} \cdot \frac{\sqrt{x + y}}{\sqrt{1} - \frac{\sqrt{y}}{\sqrt{z}}}\\ \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}:\\
\;\;\;\;\frac{\sqrt{x + y}}{\sqrt{1} + \frac{\sqrt{y}}{\sqrt{z}}} \cdot \frac{\sqrt{x + y}}{\sqrt{1} - \frac{\sqrt{y}}{\sqrt{z}}}\\

\end{array}
double f(double x, double y, double z) {
        double r589159 = x;
        double r589160 = y;
        double r589161 = r589159 + r589160;
        double r589162 = 1.0;
        double r589163 = z;
        double r589164 = r589160 / r589163;
        double r589165 = r589162 - r589164;
        double r589166 = r589161 / r589165;
        return r589166;
}

double f(double x, double y, double z) {
        double r589167 = x;
        double r589168 = y;
        double r589169 = r589167 + r589168;
        double r589170 = 1.0;
        double r589171 = z;
        double r589172 = r589168 / r589171;
        double r589173 = r589170 - r589172;
        double r589174 = r589169 / r589173;
        double r589175 = -9.340220995992204e-288;
        bool r589176 = r589174 <= r589175;
        double r589177 = -0.0;
        bool r589178 = r589174 <= r589177;
        double r589179 = !r589178;
        bool r589180 = r589176 || r589179;
        double r589181 = 1.0;
        double r589182 = r589181 * r589174;
        double r589183 = sqrt(r589169);
        double r589184 = sqrt(r589170);
        double r589185 = sqrt(r589168);
        double r589186 = sqrt(r589171);
        double r589187 = r589185 / r589186;
        double r589188 = r589184 + r589187;
        double r589189 = r589183 / r589188;
        double r589190 = r589184 - r589187;
        double r589191 = r589183 / r589190;
        double r589192 = r589189 * r589191;
        double r589193 = r589180 ? r589182 : r589192;
        return r589193;
}

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 add-sqr-sqrt58.1

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

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

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

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

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

      \[\leadsto \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)}\]
    9. Applied times-frac35.4

      \[\leadsto \color{blue}{\frac{\sqrt{x + y}}{\sqrt{1} + \frac{\sqrt{y}}{\sqrt{z}}} \cdot \frac{\sqrt{x + y}}{\sqrt{1} - \frac{\sqrt{y}}{\sqrt{z}}}}\]
  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}:\\ \;\;\;\;\frac{\sqrt{x + y}}{\sqrt{1} + \frac{\sqrt{y}}{\sqrt{z}}} \cdot \frac{\sqrt{x + y}}{\sqrt{1} - \frac{\sqrt{y}}{\sqrt{z}}}\\ \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))))