Average Error: 12.1 → 0.5
Time: 2.2s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} = -\infty:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le -1.0821387832362054 \cdot 10^{-173}:\\ \;\;\;\;\left(x \cdot \left(y + z\right)\right) \cdot \frac{1}{z}\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le 1.2688434278768279 \cdot 10^{79}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le 1.26550784375647793 \cdot 10^{293}:\\ \;\;\;\;\left(x \cdot \left(y + z\right)\right) \cdot \frac{1}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{y + z}}\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} = -\infty:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\

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

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

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

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

\end{array}
double f(double x, double y, double z) {
        double r437955 = x;
        double r437956 = y;
        double r437957 = z;
        double r437958 = r437956 + r437957;
        double r437959 = r437955 * r437958;
        double r437960 = r437959 / r437957;
        return r437960;
}

double f(double x, double y, double z) {
        double r437961 = x;
        double r437962 = y;
        double r437963 = z;
        double r437964 = r437962 + r437963;
        double r437965 = r437961 * r437964;
        double r437966 = r437965 / r437963;
        double r437967 = -inf.0;
        bool r437968 = r437966 <= r437967;
        double r437969 = r437962 / r437963;
        double r437970 = fma(r437969, r437961, r437961);
        double r437971 = -1.0821387832362054e-173;
        bool r437972 = r437966 <= r437971;
        double r437973 = 1.0;
        double r437974 = r437973 / r437963;
        double r437975 = r437965 * r437974;
        double r437976 = 1.2688434278768279e+79;
        bool r437977 = r437966 <= r437976;
        double r437978 = 1.265507843756478e+293;
        bool r437979 = r437966 <= r437978;
        double r437980 = r437963 / r437964;
        double r437981 = r437961 / r437980;
        double r437982 = r437979 ? r437975 : r437981;
        double r437983 = r437977 ? r437970 : r437982;
        double r437984 = r437972 ? r437975 : r437983;
        double r437985 = r437968 ? r437970 : r437984;
        return r437985;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.1
Target3.0
Herbie0.5
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 3 regimes
  2. if (/ (* x (+ y z)) z) < -inf.0 or -1.0821387832362054e-173 < (/ (* x (+ y z)) z) < 1.2688434278768279e+79

    1. Initial program 16.9

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

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

    if -inf.0 < (/ (* x (+ y z)) z) < -1.0821387832362054e-173 or 1.2688434278768279e+79 < (/ (* x (+ y z)) z) < 1.265507843756478e+293

    1. Initial program 0.3

      \[\frac{x \cdot \left(y + z\right)}{z}\]
    2. Using strategy rm
    3. Applied div-inv0.4

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

    if 1.265507843756478e+293 < (/ (* x (+ y z)) z)

    1. Initial program 57.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} = -\infty:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le -1.0821387832362054 \cdot 10^{-173}:\\ \;\;\;\;\left(x \cdot \left(y + z\right)\right) \cdot \frac{1}{z}\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le 1.2688434278768279 \cdot 10^{79}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le 1.26550784375647793 \cdot 10^{293}:\\ \;\;\;\;\left(x \cdot \left(y + z\right)\right) \cdot \frac{1}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{y + z}}\\ \end{array}\]

Reproduce

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