Average Error: 12.3 → 2.3
Time: 12.6s
Precision: 64
\[\frac{x \cdot \left(y - z\right)}{y}\]
\[\begin{array}{l} \mathbf{if}\;z \le -8.641964883760676028697634483308586359187 \cdot 10^{195}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\frac{x}{\frac{y}{z}}\right)\\ \mathbf{elif}\;z \le -2.135421934910598903580057538097509586825 \cdot 10^{97}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\frac{\frac{x}{y}}{\frac{1}{z}}\right)\\ \mathbf{elif}\;z \le 3.023089069211749401356410852189364064413 \cdot 10^{56}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\frac{x}{\frac{y}{z}}\right)\\ \mathbf{elif}\;z \le 1.146116329563046779001996723315272963304 \cdot 10^{178}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\frac{\frac{x}{y}}{\frac{1}{z}}\right)\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \end{array}\]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
\mathbf{if}\;z \le -8.641964883760676028697634483308586359187 \cdot 10^{195}:\\
\;\;\;\;\mathsf{fma}\left(1, x, -\frac{x}{\frac{y}{z}}\right)\\

\mathbf{elif}\;z \le -2.135421934910598903580057538097509586825 \cdot 10^{97}:\\
\;\;\;\;\mathsf{fma}\left(1, x, -\frac{\frac{x}{y}}{\frac{1}{z}}\right)\\

\mathbf{elif}\;z \le 3.023089069211749401356410852189364064413 \cdot 10^{56}:\\
\;\;\;\;\mathsf{fma}\left(1, x, -\frac{x}{\frac{y}{z}}\right)\\

\mathbf{elif}\;z \le 1.146116329563046779001996723315272963304 \cdot 10^{178}:\\
\;\;\;\;\mathsf{fma}\left(1, x, -\frac{\frac{x}{y}}{\frac{1}{z}}\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r506722 = x;
        double r506723 = y;
        double r506724 = z;
        double r506725 = r506723 - r506724;
        double r506726 = r506722 * r506725;
        double r506727 = r506726 / r506723;
        return r506727;
}

double f(double x, double y, double z) {
        double r506728 = z;
        double r506729 = -8.641964883760676e+195;
        bool r506730 = r506728 <= r506729;
        double r506731 = 1.0;
        double r506732 = x;
        double r506733 = y;
        double r506734 = r506733 / r506728;
        double r506735 = r506732 / r506734;
        double r506736 = -r506735;
        double r506737 = fma(r506731, r506732, r506736);
        double r506738 = -2.135421934910599e+97;
        bool r506739 = r506728 <= r506738;
        double r506740 = r506732 / r506733;
        double r506741 = r506731 / r506728;
        double r506742 = r506740 / r506741;
        double r506743 = -r506742;
        double r506744 = fma(r506731, r506732, r506743);
        double r506745 = 3.0230890692117494e+56;
        bool r506746 = r506728 <= r506745;
        double r506747 = 1.1461163295630468e+178;
        bool r506748 = r506728 <= r506747;
        double r506749 = r506732 * r506728;
        double r506750 = r506749 / r506733;
        double r506751 = r506732 - r506750;
        double r506752 = r506748 ? r506744 : r506751;
        double r506753 = r506746 ? r506737 : r506752;
        double r506754 = r506739 ? r506744 : r506753;
        double r506755 = r506730 ? r506737 : r506754;
        return r506755;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.3
Target3.4
Herbie2.3
\[\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 < -8.641964883760676e+195 or -2.135421934910599e+97 < z < 3.0230890692117494e+56

    1. Initial program 12.5

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

      \[\leadsto \color{blue}{x - \frac{x \cdot z}{y}}\]
    3. Using strategy rm
    4. Applied clear-num3.5

      \[\leadsto x - \color{blue}{\frac{1}{\frac{y}{x \cdot z}}}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity3.5

      \[\leadsto \color{blue}{1 \cdot x} - \frac{1}{\frac{y}{x \cdot z}}\]
    7. Applied fma-neg3.5

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, x, -\frac{1}{\frac{y}{x \cdot z}}\right)}\]
    8. Simplified1.4

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

    if -8.641964883760676e+195 < z < -2.135421934910599e+97 or 3.0230890692117494e+56 < z < 1.1461163295630468e+178

    1. Initial program 11.1

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

      \[\leadsto \color{blue}{x - \frac{x \cdot z}{y}}\]
    3. Using strategy rm
    4. Applied clear-num7.5

      \[\leadsto x - \color{blue}{\frac{1}{\frac{y}{x \cdot z}}}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity7.5

      \[\leadsto \color{blue}{1 \cdot x} - \frac{1}{\frac{y}{x \cdot z}}\]
    7. Applied fma-neg7.5

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, x, -\frac{1}{\frac{y}{x \cdot z}}\right)}\]
    8. Simplified7.3

      \[\leadsto \mathsf{fma}\left(1, x, \color{blue}{-\frac{x}{\frac{y}{z}}}\right)\]
    9. Using strategy rm
    10. Applied div-inv7.4

      \[\leadsto \mathsf{fma}\left(1, x, -\frac{x}{\color{blue}{y \cdot \frac{1}{z}}}\right)\]
    11. Applied associate-/r*1.9

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

    if 1.1461163295630468e+178 < z

    1. Initial program 13.3

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

      \[\leadsto \color{blue}{x - \frac{x \cdot z}{y}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -8.641964883760676028697634483308586359187 \cdot 10^{195}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\frac{x}{\frac{y}{z}}\right)\\ \mathbf{elif}\;z \le -2.135421934910598903580057538097509586825 \cdot 10^{97}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\frac{\frac{x}{y}}{\frac{1}{z}}\right)\\ \mathbf{elif}\;z \le 3.023089069211749401356410852189364064413 \cdot 10^{56}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\frac{x}{\frac{y}{z}}\right)\\ \mathbf{elif}\;z \le 1.146116329563046779001996723315272963304 \cdot 10^{178}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\frac{\frac{x}{y}}{\frac{1}{z}}\right)\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \end{array}\]

Reproduce

herbie shell --seed 2019208 +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.060202331921739e104) (- x (/ (* z x) y)) (if (< z 1.69397660138285259e213) (/ x (/ y (- y z))) (* (- y z) (/ x y))))

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