Average Error: 12.7 → 0.4
Time: 2.6s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \le -1.6524337457710603 \cdot 10^{302}:\\ \;\;\;\;\frac{x}{\frac{z}{y + z}}\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le -4.4143415528853468 \cdot 10^{91}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le 1.8789407496119731 \cdot 10^{-47}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le 3.0241590046493684 \cdot 10^{292}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \le -1.6524337457710603 \cdot 10^{302}:\\
\;\;\;\;\frac{x}{\frac{z}{y + z}}\\

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

\mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le 1.8789407496119731 \cdot 10^{-47}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\

\mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le 3.0241590046493684 \cdot 10^{292}:\\
\;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\

\end{array}
double f(double x, double y, double z) {
        double r681497 = x;
        double r681498 = y;
        double r681499 = z;
        double r681500 = r681498 + r681499;
        double r681501 = r681497 * r681500;
        double r681502 = r681501 / r681499;
        return r681502;
}

double f(double x, double y, double z) {
        double r681503 = x;
        double r681504 = y;
        double r681505 = z;
        double r681506 = r681504 + r681505;
        double r681507 = r681503 * r681506;
        double r681508 = r681507 / r681505;
        double r681509 = -1.6524337457710603e+302;
        bool r681510 = r681508 <= r681509;
        double r681511 = r681505 / r681506;
        double r681512 = r681503 / r681511;
        double r681513 = -4.414341552885347e+91;
        bool r681514 = r681508 <= r681513;
        double r681515 = 1.878940749611973e-47;
        bool r681516 = r681508 <= r681515;
        double r681517 = r681504 / r681505;
        double r681518 = fma(r681517, r681503, r681503);
        double r681519 = 3.0241590046493684e+292;
        bool r681520 = r681508 <= r681519;
        double r681521 = r681520 ? r681508 : r681518;
        double r681522 = r681516 ? r681518 : r681521;
        double r681523 = r681514 ? r681508 : r681522;
        double r681524 = r681510 ? r681512 : r681523;
        return r681524;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.7
Target3.0
Herbie0.4
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 3 regimes
  2. if (/ (* x (+ y z)) z) < -1.6524337457710603e+302

    1. Initial program 61.7

      \[\frac{x \cdot \left(y + z\right)}{z}\]
    2. Using strategy rm
    3. Applied associate-/l*0.7

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

    if -1.6524337457710603e+302 < (/ (* x (+ y z)) z) < -4.414341552885347e+91 or 1.878940749611973e-47 < (/ (* x (+ y z)) z) < 3.0241590046493684e+292

    1. Initial program 0.2

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

    if -4.414341552885347e+91 < (/ (* x (+ y z)) z) < 1.878940749611973e-47 or 3.0241590046493684e+292 < (/ (* x (+ y z)) z)

    1. Initial program 14.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{z}, x, x\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \le -1.6524337457710603 \cdot 10^{302}:\\ \;\;\;\;\frac{x}{\frac{z}{y + z}}\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le -4.4143415528853468 \cdot 10^{91}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le 1.8789407496119731 \cdot 10^{-47}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le 3.0241590046493684 \cdot 10^{292}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \end{array}\]

Reproduce

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

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

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