Average Error: 7.6 → 6.4
Time: 18.2s
Precision: 64
\[\frac{x + y}{1 - \frac{y}{z}}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \le -2.869692918571675329109593574597536633393 \cdot 10^{-291} \lor \neg \left(\frac{x + y}{1 - \frac{y}{z}} \le 0.0\right):\\ \;\;\;\;\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 -2.869692918571675329109593574597536633393 \cdot 10^{-291} \lor \neg \left(\frac{x + y}{1 - \frac{y}{z}} \le 0.0\right):\\
\;\;\;\;\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 r523171 = x;
        double r523172 = y;
        double r523173 = r523171 + r523172;
        double r523174 = 1.0;
        double r523175 = z;
        double r523176 = r523172 / r523175;
        double r523177 = r523174 - r523176;
        double r523178 = r523173 / r523177;
        return r523178;
}

double f(double x, double y, double z) {
        double r523179 = x;
        double r523180 = y;
        double r523181 = r523179 + r523180;
        double r523182 = 1.0;
        double r523183 = z;
        double r523184 = r523180 / r523183;
        double r523185 = r523182 - r523184;
        double r523186 = r523181 / r523185;
        double r523187 = -2.8696929185716753e-291;
        bool r523188 = r523186 <= r523187;
        double r523189 = 0.0;
        bool r523190 = r523186 <= r523189;
        double r523191 = !r523190;
        bool r523192 = r523188 || r523191;
        double r523193 = sqrt(r523181);
        double r523194 = sqrt(r523182);
        double r523195 = sqrt(r523180);
        double r523196 = sqrt(r523183);
        double r523197 = r523195 / r523196;
        double r523198 = r523194 + r523197;
        double r523199 = r523193 / r523198;
        double r523200 = r523194 - r523197;
        double r523201 = r523193 / r523200;
        double r523202 = r523199 * r523201;
        double r523203 = r523192 ? r523186 : r523202;
        return r523203;
}

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.2
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))) < -2.8696929185716753e-291 or 0.0 < (/ (+ x y) (- 1.0 (/ y z)))

    1. Initial program 4.1

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

    if -2.8696929185716753e-291 < (/ (+ x y) (- 1.0 (/ y z))) < 0.0

    1. Initial program 58.6

      \[\frac{x + y}{1 - \frac{y}{z}}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt62.2

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

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

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

      \[\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-squares63.3

      \[\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-sqrt63.4

      \[\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-frac63.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 -2.869692918571675329109593574597536633393 \cdot 10^{-291} \lor \neg \left(\frac{x + y}{1 - \frac{y}{z}} \le 0.0\right):\\ \;\;\;\;\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 2019323 +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))))