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

\mathbf{elif}\;x \le 1.851010726972348577454326436110921617114 \cdot 10^{-12}:\\
\;\;\;\;x + \frac{y \cdot x}{z}\\

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

\end{array}
double f(double x, double y, double z) {
        double r16794352 = x;
        double r16794353 = y;
        double r16794354 = z;
        double r16794355 = r16794353 + r16794354;
        double r16794356 = r16794352 * r16794355;
        double r16794357 = r16794356 / r16794354;
        return r16794357;
}

double f(double x, double y, double z) {
        double r16794358 = x;
        double r16794359 = -4.459073850942771e-97;
        bool r16794360 = r16794358 <= r16794359;
        double r16794361 = y;
        double r16794362 = z;
        double r16794363 = r16794361 / r16794362;
        double r16794364 = r16794363 * r16794358;
        double r16794365 = r16794358 + r16794364;
        double r16794366 = 1.8510107269723486e-12;
        bool r16794367 = r16794358 <= r16794366;
        double r16794368 = r16794361 * r16794358;
        double r16794369 = r16794368 / r16794362;
        double r16794370 = r16794358 + r16794369;
        double r16794371 = r16794367 ? r16794370 : r16794365;
        double r16794372 = r16794360 ? r16794365 : r16794371;
        return r16794372;
}

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 1.8510107269723486e-12 < x

    1. Initial program 18.6

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

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

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

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

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

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

    if -4.459073850942771e-97 < x < 1.8510107269723486e-12

    1. Initial program 5.4

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

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

      \[\leadsto \color{blue}{\frac{x}{z} \cdot y + x}\]
    5. Using strategy rm
    6. Applied associate-*l/2.8

      \[\leadsto \color{blue}{\frac{x \cdot y}{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 + \frac{y}{z} \cdot x\\ \mathbf{elif}\;x \le 1.851010726972348577454326436110921617114 \cdot 10^{-12}:\\ \;\;\;\;x + \frac{y \cdot x}{z}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{z} \cdot x\\ \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))