Average Error: 9.9 → 1.2
Time: 14.1s
Precision: 64
\[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.716741353213512542561167857708974654712 \cdot 10^{196}:\\ \;\;\;\;\frac{x}{\frac{z}{\left(y - z\right) + 1}}\\ \mathbf{elif}\;x \le 5.61926533510320507337176445760607473729 \cdot 10^{-243}:\\ \;\;\;\;\left(\frac{x \cdot y}{z} + 1 \cdot \frac{x}{z}\right) - x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} \cdot \left(y + 1\right) - x\\ \end{array}\]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \le -2.716741353213512542561167857708974654712 \cdot 10^{196}:\\
\;\;\;\;\frac{x}{\frac{z}{\left(y - z\right) + 1}}\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r720289 = x;
        double r720290 = y;
        double r720291 = z;
        double r720292 = r720290 - r720291;
        double r720293 = 1.0;
        double r720294 = r720292 + r720293;
        double r720295 = r720289 * r720294;
        double r720296 = r720295 / r720291;
        return r720296;
}

double f(double x, double y, double z) {
        double r720297 = x;
        double r720298 = -2.7167413532135125e+196;
        bool r720299 = r720297 <= r720298;
        double r720300 = z;
        double r720301 = y;
        double r720302 = r720301 - r720300;
        double r720303 = 1.0;
        double r720304 = r720302 + r720303;
        double r720305 = r720300 / r720304;
        double r720306 = r720297 / r720305;
        double r720307 = 5.619265335103205e-243;
        bool r720308 = r720297 <= r720307;
        double r720309 = r720297 * r720301;
        double r720310 = r720309 / r720300;
        double r720311 = r720297 / r720300;
        double r720312 = r720303 * r720311;
        double r720313 = r720310 + r720312;
        double r720314 = r720313 - r720297;
        double r720315 = r720301 + r720303;
        double r720316 = r720311 * r720315;
        double r720317 = r720316 - r720297;
        double r720318 = r720308 ? r720314 : r720317;
        double r720319 = r720299 ? r720306 : r720318;
        return r720319;
}

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

Original9.9
Target0.4
Herbie1.2
\[\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 3 regimes
  2. if x < -2.7167413532135125e+196

    1. Initial program 49.8

      \[\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}}}\]

    if -2.7167413532135125e+196 < x < 5.619265335103205e-243

    1. Initial program 4.4

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

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

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

      \[\leadsto \frac{x}{\color{blue}{1 \cdot z}} \cdot \left(y + 1\right) - x\]
    6. Applied add-cube-cbrt2.8

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

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

      \[\leadsto \color{blue}{\frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{1} \cdot \left(\frac{\sqrt[3]{x}}{z} \cdot \left(y + 1\right)\right)} - x\]
    9. Using strategy rm
    10. Applied distribute-lft-in3.2

      \[\leadsto \frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{1} \cdot \color{blue}{\left(\frac{\sqrt[3]{x}}{z} \cdot y + \frac{\sqrt[3]{x}}{z} \cdot 1\right)} - x\]
    11. Applied distribute-lft-in3.2

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

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

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

    if 5.619265335103205e-243 < x

    1. Initial program 11.6

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.716741353213512542561167857708974654712 \cdot 10^{196}:\\ \;\;\;\;\frac{x}{\frac{z}{\left(y - z\right) + 1}}\\ \mathbf{elif}\;x \le 5.61926533510320507337176445760607473729 \cdot 10^{-243}:\\ \;\;\;\;\left(\frac{x \cdot y}{z} + 1 \cdot \frac{x}{z}\right) - x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} \cdot \left(y + 1\right) - x\\ \end{array}\]

Reproduce

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