Average Error: 12.6 → 0.4
Time: 2.8s
Precision: binary64
\[\frac{x \cdot \left(y - z\right)}{y}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} = -inf.0 \lor \neg \left(\frac{x \cdot \left(y - z\right)}{y} \le -2.7628643462198709 \cdot 10^{-73} \lor \neg \left(\frac{x \cdot \left(y - z\right)}{y} \le 50872713.96341228 \lor \neg \left(\frac{x \cdot \left(y - z\right)}{y} \le 3.95070729267632818 \cdot 10^{272}\right)\right)\right):\\ \;\;\;\;x + x \cdot \left(-\frac{z}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(y - z\right)}{y}\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.6
Target3.0
Herbie0.4
\[\begin{array}{l} \mathbf{if}\;z \lt -2.060202331921739 \cdot 10^{104}:\\ \;\;\;\;x - \frac{z \cdot x}{y}\\ \mathbf{elif}\;z \lt 1.69397660138285259 \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 -2.7628643462198709e-73 < (/ (* x (- y z)) y) < 50872713.96341228 or 3.95070729267632818e272 < (/ (* x (- y z)) y)

    1. Initial program 23.2

      \[\frac{x \cdot \left(y - z\right)}{y}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity23.2

      \[\leadsto \frac{x \cdot \left(y - z\right)}{\color{blue}{1 \cdot y}}\]
    4. Applied times-frac0.5

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

      \[\leadsto \color{blue}{x} \cdot \frac{y - z}{y}\]
    6. Using strategy rm
    7. Applied div-sub0.5

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

      \[\leadsto x \cdot \left(\color{blue}{1} - \frac{z}{y}\right)\]
    9. Using strategy rm
    10. Applied sub-neg0.5

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

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

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

    if -inf.0 < (/ (* x (- y z)) y) < -2.7628643462198709e-73 or 50872713.96341228 < (/ (* x (- y z)) y) < 3.95070729267632818e272

    1. Initial program 0.2

      \[\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{x \cdot \left(y - z\right)}{y} = -inf.0 \lor \neg \left(\frac{x \cdot \left(y - z\right)}{y} \le -2.7628643462198709 \cdot 10^{-73} \lor \neg \left(\frac{x \cdot \left(y - z\right)}{y} \le 50872713.96341228 \lor \neg \left(\frac{x \cdot \left(y - z\right)}{y} \le 3.95070729267632818 \cdot 10^{272}\right)\right)\right):\\ \;\;\;\;x + x \cdot \left(-\frac{z}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(y - z\right)}{y}\\ \end{array}\]

Reproduce

herbie shell --seed 2020174 
(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))