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 r22487446 = x;
        double r22487447 = y;
        double r22487448 = z;
        double r22487449 = r22487447 + r22487448;
        double r22487450 = r22487446 * r22487449;
        double r22487451 = r22487450 / r22487448;
        return r22487451;
}

double f(double x, double y, double z) {
        double r22487452 = x;
        double r22487453 = -4.459073850942771e-97;
        bool r22487454 = r22487452 <= r22487453;
        double r22487455 = y;
        double r22487456 = z;
        double r22487457 = r22487455 / r22487456;
        double r22487458 = r22487452 * r22487457;
        double r22487459 = r22487452 + r22487458;
        double r22487460 = 6.417038597580476e-13;
        bool r22487461 = r22487452 <= r22487460;
        double r22487462 = 1.0;
        double r22487463 = r22487462 / r22487456;
        double r22487464 = r22487455 * r22487452;
        double r22487465 = r22487463 * r22487464;
        double r22487466 = r22487465 + r22487452;
        double r22487467 = r22487461 ? r22487466 : r22487459;
        double r22487468 = r22487454 ? r22487459 : r22487467;
        return r22487468;
}

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))