Average Error: 10.1 → 1.5
Time: 4.0s
Precision: 64
\[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\]
\[\frac{x}{z} \cdot \left(1 + y\right) - x\]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\frac{x}{z} \cdot \left(1 + y\right) - x
double f(double x, double y, double z) {
        double r567443 = x;
        double r567444 = y;
        double r567445 = z;
        double r567446 = r567444 - r567445;
        double r567447 = 1.0;
        double r567448 = r567446 + r567447;
        double r567449 = r567443 * r567448;
        double r567450 = r567449 / r567445;
        return r567450;
}

double f(double x, double y, double z) {
        double r567451 = x;
        double r567452 = z;
        double r567453 = r567451 / r567452;
        double r567454 = 1.0;
        double r567455 = y;
        double r567456 = r567454 + r567455;
        double r567457 = r567453 * r567456;
        double r567458 = r567457 - r567451;
        return r567458;
}

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.1
Target0.4
Herbie1.5
\[\begin{array}{l} \mathbf{if}\;x \lt -2.714831067134359919650240696134672137284 \cdot 10^{-162}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \mathbf{elif}\;x \lt 3.874108816439546156869494499878029491333 \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 2 regimes
  2. if z < -6505.692513803455 or 2.966491335278021e-23 < z

    1. Initial program 16.2

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

      \[\leadsto \color{blue}{\left(\frac{x \cdot y}{z} + 1 \cdot \frac{x}{z}\right) - x}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity5.5

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

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

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

    if -6505.692513803455 < z < 2.966491335278021e-23

    1. Initial program 0.1

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

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

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

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

Reproduce

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

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

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