Average Error: 12.4 → 2.0
Time: 13.8s
Precision: 64
Internal precision: 128
\[\frac{x \cdot \left(y - z\right)}{y}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \le 2.0215657871095714 \cdot 10^{+19}:\\ \;\;\;\;x - \frac{z}{y} \cdot x\\ \mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \le 8.388051692914339 \cdot 10^{+250}:\\ \;\;\;\;x - \frac{z \cdot x}{y}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{z}{y} \cdot x\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.4
Comparison3.1
Herbie2.0
\[ \begin{array}{l} \mathbf{if}\;z \lt -2.060202331921739 \cdot 10^{+104}:\\ \;\;\;\;x - \frac{z \cdot x}{y}\\ \mathbf{if}\;z \lt 1.6939766013828526 \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) < 2.0215657871095714e+19 or 8.388051692914339e+250 < (/ (* x (- y z)) y)

    1. Initial program 14.7

      \[\frac{x \cdot \left(y - z\right)}{y}\]
    2. Applied taylor 5.7

      \[\leadsto x - \frac{z \cdot x}{y}\]
    3. Taylor expanded around 0 5.7

      \[\leadsto \color{blue}{x - \frac{z \cdot x}{y}}\]
    4. Using strategy rm
    5. Applied associate-/l* 4.4

      \[\leadsto x - \color{blue}{\frac{z}{\frac{y}{x}}}\]
    6. Using strategy rm
    7. Applied associate-/r/ 2.3

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

    if 2.0215657871095714e+19 < (/ (* x (- y z)) y) < 8.388051692914339e+250

    1. Initial program 0.2

      \[\frac{x \cdot \left(y - z\right)}{y}\]
    2. Applied taylor 0.1

      \[\leadsto x - \frac{z \cdot x}{y}\]
    3. Taylor expanded around 0 0.1

      \[\leadsto \color{blue}{x - \frac{z \cdot x}{y}}\]
  3. Recombined 2 regimes into one program.
  4. Removed slow pow expressions

Runtime

Time bar (total: 13.8s) Debug log

Please include this information when filing a bug report:

herbie --seed '#(2326311576 2153080410 3212614167 3035849282 4056716154 2223879648)'
(FPCore (x y z)
  :name "Diagrams.Backend.Cairo.Internal:setTexture from diagrams-cairo-1.3.0.3"

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