Average Error: 9.4 → 0.8
Time: 17.6s
Precision: 64
\[\frac{x \cdot \left(\left(y - z\right) + 1.0\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -7.983591363170175 \cdot 10^{-179}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, 1.0 \cdot \frac{x}{z} - x\right)\\ \mathbf{elif}\;x \le 5.0221248808098915 \cdot 10^{-179}:\\ \;\;\;\;\frac{\left(\left(y + 1.0\right) - z\right) \cdot x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{1.0 + \left(y - z\right)}}\\ \end{array}\]
\frac{x \cdot \left(\left(y - z\right) + 1.0\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \le -7.983591363170175 \cdot 10^{-179}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, 1.0 \cdot \frac{x}{z} - x\right)\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r29854265 = x;
        double r29854266 = y;
        double r29854267 = z;
        double r29854268 = r29854266 - r29854267;
        double r29854269 = 1.0;
        double r29854270 = r29854268 + r29854269;
        double r29854271 = r29854265 * r29854270;
        double r29854272 = r29854271 / r29854267;
        return r29854272;
}

double f(double x, double y, double z) {
        double r29854273 = x;
        double r29854274 = -7.983591363170175e-179;
        bool r29854275 = r29854273 <= r29854274;
        double r29854276 = z;
        double r29854277 = r29854273 / r29854276;
        double r29854278 = y;
        double r29854279 = 1.0;
        double r29854280 = r29854279 * r29854277;
        double r29854281 = r29854280 - r29854273;
        double r29854282 = fma(r29854277, r29854278, r29854281);
        double r29854283 = 5.0221248808098915e-179;
        bool r29854284 = r29854273 <= r29854283;
        double r29854285 = r29854278 + r29854279;
        double r29854286 = r29854285 - r29854276;
        double r29854287 = r29854286 * r29854273;
        double r29854288 = r29854287 / r29854276;
        double r29854289 = r29854278 - r29854276;
        double r29854290 = r29854279 + r29854289;
        double r29854291 = r29854276 / r29854290;
        double r29854292 = r29854273 / r29854291;
        double r29854293 = r29854284 ? r29854288 : r29854292;
        double r29854294 = r29854275 ? r29854282 : r29854293;
        return r29854294;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original9.4
Target0.5
Herbie0.8
\[\begin{array}{l} \mathbf{if}\;x \lt -2.71483106713436 \cdot 10^{-162}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \mathbf{elif}\;x \lt 3.874108816439546 \cdot 10^{-197}:\\ \;\;\;\;\left(x \cdot \left(\left(y - z\right) + 1.0\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 < -7.983591363170175e-179

    1. Initial program 13.0

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

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

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

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

    if -7.983591363170175e-179 < x < 5.0221248808098915e-179

    1. Initial program 0.1

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

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

      \[\leadsto \frac{x}{\color{blue}{z \cdot \frac{1}{\left(y - z\right) + 1.0}}}\]
    6. Applied *-un-lft-identity7.8

      \[\leadsto \frac{\color{blue}{1 \cdot x}}{z \cdot \frac{1}{\left(y - z\right) + 1.0}}\]
    7. Applied times-frac0.3

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

      \[\leadsto \frac{1}{z} \cdot \color{blue}{\left(\left(\left(y - z\right) + 1.0\right) \cdot x\right)}\]
    9. Using strategy rm
    10. Applied associate-*l/0.1

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

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

    if 5.0221248808098915e-179 < x

    1. Initial program 12.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -7.983591363170175 \cdot 10^{-179}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, 1.0 \cdot \frac{x}{z} - x\right)\\ \mathbf{elif}\;x \le 5.0221248808098915 \cdot 10^{-179}:\\ \;\;\;\;\frac{\left(\left(y + 1.0\right) - z\right) \cdot x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{1.0 + \left(y - z\right)}}\\ \end{array}\]

Reproduce

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

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

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