Average Error: 12.2 → 1.6
Time: 13.0s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.459073850942770749159394653374215512439 \cdot 10^{-97}:\\ \;\;\;\;x + x \cdot \frac{y}{z}\\ \mathbf{elif}\;x \le 6.417038597580476198640985321546549672309 \cdot 10^{-13}:\\ \;\;\;\;\frac{1}{z} \cdot \left(y \cdot x\right) + x\\ \mathbf{else}:\\ \;\;\;\;x + x \cdot \frac{y}{z}\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \le -4.459073850942770749159394653374215512439 \cdot 10^{-97}:\\
\;\;\;\;x + x \cdot \frac{y}{z}\\

\mathbf{elif}\;x \le 6.417038597580476198640985321546549672309 \cdot 10^{-13}:\\
\;\;\;\;\frac{1}{z} \cdot \left(y \cdot x\right) + x\\

\mathbf{else}:\\
\;\;\;\;x + x \cdot \frac{y}{z}\\

\end{array}
double f(double x, double y, double z) {
        double r18012279 = x;
        double r18012280 = y;
        double r18012281 = z;
        double r18012282 = r18012280 + r18012281;
        double r18012283 = r18012279 * r18012282;
        double r18012284 = r18012283 / r18012281;
        return r18012284;
}

double f(double x, double y, double z) {
        double r18012285 = x;
        double r18012286 = -4.459073850942771e-97;
        bool r18012287 = r18012285 <= r18012286;
        double r18012288 = y;
        double r18012289 = z;
        double r18012290 = r18012288 / r18012289;
        double r18012291 = r18012285 * r18012290;
        double r18012292 = r18012285 + r18012291;
        double r18012293 = 6.417038597580476e-13;
        bool r18012294 = r18012285 <= r18012293;
        double r18012295 = 1.0;
        double r18012296 = r18012295 / r18012289;
        double r18012297 = r18012288 * r18012285;
        double r18012298 = r18012296 * r18012297;
        double r18012299 = r18012298 + r18012285;
        double r18012300 = r18012294 ? r18012299 : r18012292;
        double r18012301 = r18012287 ? r18012292 : r18012300;
        return r18012301;
}

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

Original12.2
Target3.1
Herbie1.6
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -4.459073850942771e-97 or 6.417038597580476e-13 < x

    1. Initial program 18.6

      \[\frac{x \cdot \left(y + z\right)}{z}\]
    2. Simplified6.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{x}{z}, x\right)}\]
    3. Using strategy rm
    4. Applied fma-udef6.2

      \[\leadsto \color{blue}{y \cdot \frac{x}{z} + x}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt6.6

      \[\leadsto y \cdot \frac{x}{\color{blue}{\left(\sqrt[3]{z} \cdot \sqrt[3]{z}\right) \cdot \sqrt[3]{z}}} + x\]
    7. Applied *-un-lft-identity6.6

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

      \[\leadsto y \cdot \color{blue}{\left(\frac{1}{\sqrt[3]{z} \cdot \sqrt[3]{z}} \cdot \frac{x}{\sqrt[3]{z}}\right)} + x\]
    9. Applied associate-*r*1.9

      \[\leadsto \color{blue}{\left(y \cdot \frac{1}{\sqrt[3]{z} \cdot \sqrt[3]{z}}\right) \cdot \frac{x}{\sqrt[3]{z}}} + x\]
    10. Simplified1.9

      \[\leadsto \color{blue}{\frac{y}{\sqrt[3]{z} \cdot \sqrt[3]{z}}} \cdot \frac{x}{\sqrt[3]{z}} + x\]
    11. Using strategy rm
    12. Applied *-un-lft-identity1.9

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

      \[\leadsto \color{blue}{1 \cdot \left(\frac{y}{\sqrt[3]{z} \cdot \sqrt[3]{z}} \cdot \frac{x}{\sqrt[3]{z}}\right)} + x\]
    14. Simplified0.4

      \[\leadsto 1 \cdot \color{blue}{\frac{x}{\frac{z}{y}}} + x\]
    15. Using strategy rm
    16. Applied div-inv0.5

      \[\leadsto 1 \cdot \color{blue}{\left(x \cdot \frac{1}{\frac{z}{y}}\right)} + x\]
    17. Simplified0.5

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

    if -4.459073850942771e-97 < x < 6.417038597580476e-13

    1. Initial program 5.4

      \[\frac{x \cdot \left(y + z\right)}{z}\]
    2. Simplified3.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{x}{z}, x\right)}\]
    3. Using strategy rm
    4. Applied fma-udef3.2

      \[\leadsto \color{blue}{y \cdot \frac{x}{z} + x}\]
    5. Using strategy rm
    6. Applied div-inv3.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.459073850942770749159394653374215512439 \cdot 10^{-97}:\\ \;\;\;\;x + x \cdot \frac{y}{z}\\ \mathbf{elif}\;x \le 6.417038597580476198640985321546549672309 \cdot 10^{-13}:\\ \;\;\;\;\frac{1}{z} \cdot \left(y \cdot x\right) + x\\ \mathbf{else}:\\ \;\;\;\;x + x \cdot \frac{y}{z}\\ \end{array}\]

Reproduce

herbie shell --seed 2019172 +o rules:numerics
(FPCore (x y z)
  :name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"

  :herbie-target
  (/ x (/ z (+ y z)))

  (/ (* x (+ y z)) z))