Average Error: 10.1 → 0.2
Time: 14.7s
Precision: 64
\[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.8170706341410064 \cdot 10^{29}:\\ \;\;\;\;x \cdot \frac{1 + y}{z} - x\\ \mathbf{elif}\;x \le 9.5183273331390796 \cdot 10^{52}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, 1, \frac{x \cdot y}{z}\right) - x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{\left(y - z\right) + 1}}\\ \end{array}\]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \le -2.8170706341410064 \cdot 10^{29}:\\
\;\;\;\;x \cdot \frac{1 + y}{z} - x\\

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

\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{\left(y - z\right) + 1}}\\

\end{array}
double f(double x, double y, double z) {
        double r739732 = x;
        double r739733 = y;
        double r739734 = z;
        double r739735 = r739733 - r739734;
        double r739736 = 1.0;
        double r739737 = r739735 + r739736;
        double r739738 = r739732 * r739737;
        double r739739 = r739738 / r739734;
        return r739739;
}

double f(double x, double y, double z) {
        double r739740 = x;
        double r739741 = -2.8170706341410064e+29;
        bool r739742 = r739740 <= r739741;
        double r739743 = 1.0;
        double r739744 = y;
        double r739745 = r739743 + r739744;
        double r739746 = z;
        double r739747 = r739745 / r739746;
        double r739748 = r739740 * r739747;
        double r739749 = r739748 - r739740;
        double r739750 = 9.51832733313908e+52;
        bool r739751 = r739740 <= r739750;
        double r739752 = r739740 / r739746;
        double r739753 = r739740 * r739744;
        double r739754 = r739753 / r739746;
        double r739755 = fma(r739752, r739743, r739754);
        double r739756 = r739755 - r739740;
        double r739757 = r739744 - r739746;
        double r739758 = r739757 + r739743;
        double r739759 = r739746 / r739758;
        double r739760 = r739740 / r739759;
        double r739761 = r739751 ? r739756 : r739760;
        double r739762 = r739742 ? r739749 : r739761;
        return r739762;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original10.1
Target0.4
Herbie0.2
\[\begin{array}{l} \mathbf{if}\;x \lt -2.7148310671343599 \cdot 10^{-162}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \mathbf{elif}\;x \lt 3.87410881643954616 \cdot 10^{-197}:\\ \;\;\;\;\left(x \cdot \left(\left(y - z\right) + 1\right)\right) \cdot \frac{1}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -2.8170706341410064e+29

    1. Initial program 29.1

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

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

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(1 + y\right) - x}\]
    4. Using strategy rm
    5. Applied div-inv0.1

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

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

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

    if -2.8170706341410064e+29 < x < 9.51832733313908e+52

    1. Initial program 0.5

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

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}}\]
    4. Taylor expanded around 0 0.2

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

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

    if 9.51832733313908e+52 < x

    1. Initial program 30.6

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

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.8170706341410064 \cdot 10^{29}:\\ \;\;\;\;x \cdot \frac{1 + y}{z} - x\\ \mathbf{elif}\;x \le 9.5183273331390796 \cdot 10^{52}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, 1, \frac{x \cdot y}{z}\right) - x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{\left(y - z\right) + 1}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020042 +o rules:numerics
(FPCore (x y z)
  :name "Diagrams.TwoD.Segment.Bernstein:evaluateBernstein from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< x -2.71483106713436e-162) (- (* (+ 1 y) (/ x z)) x) (if (< x 3.874108816439546e-197) (* (* x (+ (- y z) 1)) (/ 1 z)) (- (* (+ 1 y) (/ x z)) x)))

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