Average Error: 12.7 → 0.4
Time: 18.3s
Precision: 64
\[\frac{x \cdot \left(y - z\right)}{y}\]
\[\begin{array}{l} \mathbf{if}\;\frac{\left(y - z\right) \cdot x}{y} = -\infty \lor \neg \left(\frac{\left(y - z\right) \cdot x}{y} \le -1.423223902492036864077133582220964471534 \cdot 10^{-164}\right) \land \left(\frac{\left(y - z\right) \cdot x}{y} \le 4.388103829051850339400229496743255364066 \cdot 10^{-8} \lor \neg \left(\frac{\left(y - z\right) \cdot x}{y} \le 1.371845779701189839643426350159185586858 \cdot 10^{284}\right)\right):\\ \;\;\;\;\mathsf{fma}\left(-x, \frac{z}{y}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(y - z\right) \cdot x}{y}\\ \end{array}\]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
\mathbf{if}\;\frac{\left(y - z\right) \cdot x}{y} = -\infty \lor \neg \left(\frac{\left(y - z\right) \cdot x}{y} \le -1.423223902492036864077133582220964471534 \cdot 10^{-164}\right) \land \left(\frac{\left(y - z\right) \cdot x}{y} \le 4.388103829051850339400229496743255364066 \cdot 10^{-8} \lor \neg \left(\frac{\left(y - z\right) \cdot x}{y} \le 1.371845779701189839643426350159185586858 \cdot 10^{284}\right)\right):\\
\;\;\;\;\mathsf{fma}\left(-x, \frac{z}{y}, x\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r1486693 = x;
        double r1486694 = y;
        double r1486695 = z;
        double r1486696 = r1486694 - r1486695;
        double r1486697 = r1486693 * r1486696;
        double r1486698 = r1486697 / r1486694;
        return r1486698;
}

double f(double x, double y, double z) {
        double r1486699 = y;
        double r1486700 = z;
        double r1486701 = r1486699 - r1486700;
        double r1486702 = x;
        double r1486703 = r1486701 * r1486702;
        double r1486704 = r1486703 / r1486699;
        double r1486705 = -inf.0;
        bool r1486706 = r1486704 <= r1486705;
        double r1486707 = -1.4232239024920369e-164;
        bool r1486708 = r1486704 <= r1486707;
        double r1486709 = !r1486708;
        double r1486710 = 4.3881038290518503e-08;
        bool r1486711 = r1486704 <= r1486710;
        double r1486712 = 1.3718457797011898e+284;
        bool r1486713 = r1486704 <= r1486712;
        double r1486714 = !r1486713;
        bool r1486715 = r1486711 || r1486714;
        bool r1486716 = r1486709 && r1486715;
        bool r1486717 = r1486706 || r1486716;
        double r1486718 = -r1486702;
        double r1486719 = r1486700 / r1486699;
        double r1486720 = fma(r1486718, r1486719, r1486702);
        double r1486721 = r1486717 ? r1486720 : r1486704;
        return r1486721;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.7
Target2.9
Herbie0.4
\[\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 2 regimes
  2. if (/ (* x (- y z)) y) < -inf.0 or -1.4232239024920369e-164 < (/ (* x (- y z)) y) < 4.3881038290518503e-08 or 1.3718457797011898e+284 < (/ (* x (- y z)) y)

    1. Initial program 27.0

      \[\frac{x \cdot \left(y - z\right)}{y}\]
    2. Simplified0.6

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

    if -inf.0 < (/ (* x (- y z)) y) < -1.4232239024920369e-164 or 4.3881038290518503e-08 < (/ (* x (- y z)) y) < 1.3718457797011898e+284

    1. Initial program 0.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(y - z\right) \cdot x}{y} = -\infty \lor \neg \left(\frac{\left(y - z\right) \cdot x}{y} \le -1.423223902492036864077133582220964471534 \cdot 10^{-164}\right) \land \left(\frac{\left(y - z\right) \cdot x}{y} \le 4.388103829051850339400229496743255364066 \cdot 10^{-8} \lor \neg \left(\frac{\left(y - z\right) \cdot x}{y} \le 1.371845779701189839643426350159185586858 \cdot 10^{284}\right)\right):\\ \;\;\;\;\mathsf{fma}\left(-x, \frac{z}{y}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(y - z\right) \cdot x}{y}\\ \end{array}\]

Reproduce

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

  :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))