Average Error: 13.2 → 3.5
Time: 2.2s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.408351243779353712662956544983038618186 \cdot 10^{-69}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{elif}\;x \le -1.011828300461219073932944869190865005589 \cdot 10^{-255}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\ \mathbf{elif}\;x \le 2.032174303077665638909923669538885498141 \cdot 10^{-220}:\\ \;\;\;\;\frac{x}{\frac{z}{y + z}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \le -4.408351243779353712662956544983038618186 \cdot 10^{-69}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\

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

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

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

\end{array}
double f(double x, double y, double z) {
        double r458785 = x;
        double r458786 = y;
        double r458787 = z;
        double r458788 = r458786 + r458787;
        double r458789 = r458785 * r458788;
        double r458790 = r458789 / r458787;
        return r458790;
}

double f(double x, double y, double z) {
        double r458791 = x;
        double r458792 = -4.4083512437793537e-69;
        bool r458793 = r458791 <= r458792;
        double r458794 = y;
        double r458795 = z;
        double r458796 = r458794 / r458795;
        double r458797 = fma(r458796, r458791, r458791);
        double r458798 = -1.0118283004612191e-255;
        bool r458799 = r458791 <= r458798;
        double r458800 = r458791 / r458795;
        double r458801 = fma(r458800, r458794, r458791);
        double r458802 = 2.0321743030776656e-220;
        bool r458803 = r458791 <= r458802;
        double r458804 = r458794 + r458795;
        double r458805 = r458795 / r458804;
        double r458806 = r458791 / r458805;
        double r458807 = r458803 ? r458806 : r458801;
        double r458808 = r458799 ? r458801 : r458807;
        double r458809 = r458793 ? r458797 : r458808;
        return r458809;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original13.2
Target2.9
Herbie3.5
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -4.4083512437793537e-69

    1. Initial program 18.5

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{z}, x, x\right)}\]

    if -4.4083512437793537e-69 < x < -1.0118283004612191e-255 or 2.0321743030776656e-220 < x

    1. Initial program 11.4

      \[\frac{x \cdot \left(y + z\right)}{z}\]
    2. Taylor expanded around 0 4.3

      \[\leadsto \color{blue}{\frac{x \cdot y}{z} + x}\]
    3. Simplified4.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{z}, y, x\right)}\]

    if -1.0118283004612191e-255 < x < 2.0321743030776656e-220

    1. Initial program 10.1

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

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{y + z}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification3.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.408351243779353712662956544983038618186 \cdot 10^{-69}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{elif}\;x \le -1.011828300461219073932944869190865005589 \cdot 10^{-255}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\ \mathbf{elif}\;x \le 2.032174303077665638909923669538885498141 \cdot 10^{-220}:\\ \;\;\;\;\frac{x}{\frac{z}{y + z}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020002 +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))