Average Error: 12.6 → 0.8
Time: 17.4s
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.535710864543621228834700889446278683497 \cdot 10^{112}\right) \land \left(\frac{\left(y - z\right) \cdot x}{y} \le 4597572249704838144 \lor \neg \left(\frac{\left(y - z\right) \cdot x}{y} \le 1.095545649072277509917652984108949902858 \cdot 10^{260}\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.535710864543621228834700889446278683497 \cdot 10^{112}\right) \land \left(\frac{\left(y - z\right) \cdot x}{y} \le 4597572249704838144 \lor \neg \left(\frac{\left(y - z\right) \cdot x}{y} \le 1.095545649072277509917652984108949902858 \cdot 10^{260}\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 r546321 = x;
        double r546322 = y;
        double r546323 = z;
        double r546324 = r546322 - r546323;
        double r546325 = r546321 * r546324;
        double r546326 = r546325 / r546322;
        return r546326;
}

double f(double x, double y, double z) {
        double r546327 = y;
        double r546328 = z;
        double r546329 = r546327 - r546328;
        double r546330 = x;
        double r546331 = r546329 * r546330;
        double r546332 = r546331 / r546327;
        double r546333 = -inf.0;
        bool r546334 = r546332 <= r546333;
        double r546335 = -1.5357108645436212e+112;
        bool r546336 = r546332 <= r546335;
        double r546337 = !r546336;
        double r546338 = 4.597572249704838e+18;
        bool r546339 = r546332 <= r546338;
        double r546340 = 1.0955456490722775e+260;
        bool r546341 = r546332 <= r546340;
        double r546342 = !r546341;
        bool r546343 = r546339 || r546342;
        bool r546344 = r546337 && r546343;
        bool r546345 = r546334 || r546344;
        double r546346 = -r546330;
        double r546347 = r546328 / r546327;
        double r546348 = fma(r546346, r546347, r546330);
        double r546349 = r546345 ? r546348 : r546332;
        return r546349;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.6
Target2.8
Herbie0.8
\[\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.5357108645436212e+112 < (/ (* x (- y z)) y) < 4.597572249704838e+18 or 1.0955456490722775e+260 < (/ (* x (- y z)) y)

    1. Initial program 17.8

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

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

    if -inf.0 < (/ (* x (- y z)) y) < -1.5357108645436212e+112 or 4.597572249704838e+18 < (/ (* x (- y z)) y) < 1.0955456490722775e+260

    1. Initial program 0.2

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

    \[\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.535710864543621228834700889446278683497 \cdot 10^{112}\right) \land \left(\frac{\left(y - z\right) \cdot x}{y} \le 4597572249704838144 \lor \neg \left(\frac{\left(y - z\right) \cdot x}{y} \le 1.095545649072277509917652984108949902858 \cdot 10^{260}\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 2019174 +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))