Average Error: 12.2 → 2.6
Time: 10.7s
Precision: 64
\[\frac{x \cdot \left(y - z\right)}{y}\]
\[\begin{array}{l} \mathbf{if}\;z \le -3.959044911726634905220938628750773223279 \cdot 10^{51}:\\ \;\;\;\;x + \frac{-z}{\frac{y}{x}}\\ \mathbf{elif}\;z \le 2.65441430654303589246643061268787471633 \cdot 10^{-93}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{elif}\;z \le 4.507467681888386206278845817218710484276 \cdot 10^{241}:\\ \;\;\;\;x + \frac{-1}{y} \cdot \left(x \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{-z}{\frac{y}{x}}\\ \end{array}\]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
\mathbf{if}\;z \le -3.959044911726634905220938628750773223279 \cdot 10^{51}:\\
\;\;\;\;x + \frac{-z}{\frac{y}{x}}\\

\mathbf{elif}\;z \le 2.65441430654303589246643061268787471633 \cdot 10^{-93}:\\
\;\;\;\;\frac{x}{\frac{y}{y - z}}\\

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

\mathbf{else}:\\
\;\;\;\;x + \frac{-z}{\frac{y}{x}}\\

\end{array}
double f(double x, double y, double z) {
        double r663441 = x;
        double r663442 = y;
        double r663443 = z;
        double r663444 = r663442 - r663443;
        double r663445 = r663441 * r663444;
        double r663446 = r663445 / r663442;
        return r663446;
}

double f(double x, double y, double z) {
        double r663447 = z;
        double r663448 = -3.959044911726635e+51;
        bool r663449 = r663447 <= r663448;
        double r663450 = x;
        double r663451 = -r663447;
        double r663452 = y;
        double r663453 = r663452 / r663450;
        double r663454 = r663451 / r663453;
        double r663455 = r663450 + r663454;
        double r663456 = 2.654414306543036e-93;
        bool r663457 = r663447 <= r663456;
        double r663458 = r663452 - r663447;
        double r663459 = r663452 / r663458;
        double r663460 = r663450 / r663459;
        double r663461 = 4.507467681888386e+241;
        bool r663462 = r663447 <= r663461;
        double r663463 = -1.0;
        double r663464 = r663463 / r663452;
        double r663465 = r663450 * r663447;
        double r663466 = r663464 * r663465;
        double r663467 = r663450 + r663466;
        double r663468 = r663462 ? r663467 : r663455;
        double r663469 = r663457 ? r663460 : r663468;
        double r663470 = r663449 ? r663455 : r663469;
        return r663470;
}

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

Original12.2
Target3.1
Herbie2.6
\[\begin{array}{l} \mathbf{if}\;z \lt -2.060202331921739024383612783691266533098 \cdot 10^{104}:\\ \;\;\;\;x - \frac{z \cdot x}{y}\\ \mathbf{elif}\;z \lt 1.693976601382852594702773997610248441465 \cdot 10^{213}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if z < -3.959044911726635e+51 or 4.507467681888386e+241 < z

    1. Initial program 11.5

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

      \[\leadsto \color{blue}{\frac{x}{\frac{y}{y - z}}}\]
    4. Using strategy rm
    5. Applied div-inv10.1

      \[\leadsto \color{blue}{x \cdot \frac{1}{\frac{y}{y - z}}}\]
    6. Simplified10.1

      \[\leadsto x \cdot \color{blue}{\left(1 - \frac{z}{y}\right)}\]
    7. Using strategy rm
    8. Applied sub-neg10.1

      \[\leadsto x \cdot \color{blue}{\left(1 + \left(-\frac{z}{y}\right)\right)}\]
    9. Applied distribute-lft-in10.1

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

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

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

    if -3.959044911726635e+51 < z < 2.654414306543036e-93

    1. Initial program 13.3

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

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

    if 2.654414306543036e-93 < z < 4.507467681888386e+241

    1. Initial program 10.5

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

      \[\leadsto \color{blue}{\frac{x}{\frac{y}{y - z}}}\]
    4. Using strategy rm
    5. Applied div-inv4.5

      \[\leadsto \color{blue}{x \cdot \frac{1}{\frac{y}{y - z}}}\]
    6. Simplified4.4

      \[\leadsto x \cdot \color{blue}{\left(1 - \frac{z}{y}\right)}\]
    7. Using strategy rm
    8. Applied sub-neg4.4

      \[\leadsto x \cdot \color{blue}{\left(1 + \left(-\frac{z}{y}\right)\right)}\]
    9. Applied distribute-lft-in4.4

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

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

      \[\leadsto x + \color{blue}{\frac{-z}{\frac{y}{x}}}\]
    12. Using strategy rm
    13. Applied div-inv2.1

      \[\leadsto x + \frac{-z}{\color{blue}{y \cdot \frac{1}{x}}}\]
    14. Applied neg-mul-12.1

      \[\leadsto x + \frac{\color{blue}{-1 \cdot z}}{y \cdot \frac{1}{x}}\]
    15. Applied times-frac4.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -3.959044911726634905220938628750773223279 \cdot 10^{51}:\\ \;\;\;\;x + \frac{-z}{\frac{y}{x}}\\ \mathbf{elif}\;z \le 2.65441430654303589246643061268787471633 \cdot 10^{-93}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{elif}\;z \le 4.507467681888386206278845817218710484276 \cdot 10^{241}:\\ \;\;\;\;x + \frac{-1}{y} \cdot \left(x \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{-z}{\frac{y}{x}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019351 +o rules:numerics
(FPCore (x y z)
  :name "Diagrams.Backend.Cairo.Internal:setTexture from diagrams-cairo-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< z -2.060202331921739e+104) (- x (/ (* z x) y)) (if (< z 1.6939766013828526e+213) (/ x (/ y (- y z))) (* (- y z) (/ x y))))

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