Average Error: 10.5 → 0.3
Time: 28.9s
Precision: 64
\[\frac{x \cdot \left(\left(y - z\right) + 1.0\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -7.814855256918435 \cdot 10^{-142}:\\ \;\;\;\;\left(1.0 \cdot \frac{x}{z} + \frac{x}{z} \cdot y\right) - x\\ \mathbf{elif}\;x \le 4.0170515075320604 \cdot 10^{-115}:\\ \;\;\;\;\frac{1}{z} \cdot \left(x \cdot \left(\left(y - z\right) + 1.0\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1.0 \cdot \frac{x}{z} + \frac{x}{z} \cdot y\right) - x\\ \end{array}\]
\frac{x \cdot \left(\left(y - z\right) + 1.0\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \le -7.814855256918435 \cdot 10^{-142}:\\
\;\;\;\;\left(1.0 \cdot \frac{x}{z} + \frac{x}{z} \cdot y\right) - x\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r32353698 = x;
        double r32353699 = y;
        double r32353700 = z;
        double r32353701 = r32353699 - r32353700;
        double r32353702 = 1.0;
        double r32353703 = r32353701 + r32353702;
        double r32353704 = r32353698 * r32353703;
        double r32353705 = r32353704 / r32353700;
        return r32353705;
}

double f(double x, double y, double z) {
        double r32353706 = x;
        double r32353707 = -7.814855256918435e-142;
        bool r32353708 = r32353706 <= r32353707;
        double r32353709 = 1.0;
        double r32353710 = z;
        double r32353711 = r32353706 / r32353710;
        double r32353712 = r32353709 * r32353711;
        double r32353713 = y;
        double r32353714 = r32353711 * r32353713;
        double r32353715 = r32353712 + r32353714;
        double r32353716 = r32353715 - r32353706;
        double r32353717 = 4.0170515075320604e-115;
        bool r32353718 = r32353706 <= r32353717;
        double r32353719 = 1.0;
        double r32353720 = r32353719 / r32353710;
        double r32353721 = r32353713 - r32353710;
        double r32353722 = r32353721 + r32353709;
        double r32353723 = r32353706 * r32353722;
        double r32353724 = r32353720 * r32353723;
        double r32353725 = r32353718 ? r32353724 : r32353716;
        double r32353726 = r32353708 ? r32353716 : r32353725;
        return r32353726;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original10.5
Target0.4
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;x \lt -2.71483106713436 \cdot 10^{-162}:\\ \;\;\;\;\left(1.0 + 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.0}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(1.0 + y\right) \cdot \frac{x}{z} - x\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -7.814855256918435e-142 or 4.0170515075320604e-115 < x

    1. Initial program 16.4

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

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

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

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

    if -7.814855256918435e-142 < x < 4.0170515075320604e-115

    1. Initial program 0.2

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -7.814855256918435 \cdot 10^{-142}:\\ \;\;\;\;\left(1.0 \cdot \frac{x}{z} + \frac{x}{z} \cdot y\right) - x\\ \mathbf{elif}\;x \le 4.0170515075320604 \cdot 10^{-115}:\\ \;\;\;\;\frac{1}{z} \cdot \left(x \cdot \left(\left(y - z\right) + 1.0\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1.0 \cdot \frac{x}{z} + \frac{x}{z} \cdot y\right) - x\\ \end{array}\]

Reproduce

herbie shell --seed 2019165 
(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.0 y) (/ x z)) x) (if (< x 3.874108816439546e-197) (* (* x (+ (- y z) 1.0)) (/ 1.0 z)) (- (* (+ 1.0 y) (/ x z)) x)))

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