Average Error: 14.6 → 0.3
Time: 38.9s
Precision: 64
Internal Precision: 384
\[\frac{\left(x \cdot 2.0\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -2.552896654563677 \cdot 10^{-77}:\\ \;\;\;\;\frac{x \cdot 2.0}{1} \cdot \frac{y}{x - y}\\ \mathbf{if}\;y \le 4.907722326036034 \cdot 10^{-19}:\\ \;\;\;\;\frac{x}{x - y} \cdot \frac{2.0}{\frac{1}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2.0}{\frac{x - y}{y}}\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Target

Original14.6
Target0.3
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;x \lt -1.7210442634149447 \cdot 10^{+81}:\\ \;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\ \mathbf{if}\;x \lt 8.364504563556443 \cdot 10^{+16}:\\ \;\;\;\;\frac{x \cdot 2.0}{\frac{x - y}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if y < -2.552896654563677e-77

    1. Initial program 12.4

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

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

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

    if -2.552896654563677e-77 < y < 4.907722326036034e-19

    1. Initial program 15.9

      \[\frac{\left(x \cdot 2.0\right) \cdot y}{x - y}\]
    2. Using strategy rm
    3. Applied associate-/l*16.8

      \[\leadsto \color{blue}{\frac{x \cdot 2.0}{\frac{x - y}{y}}}\]
    4. Using strategy rm
    5. Applied div-inv16.9

      \[\leadsto \frac{x \cdot 2.0}{\color{blue}{\left(x - y\right) \cdot \frac{1}{y}}}\]
    6. Applied times-frac0.2

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

    if 4.907722326036034e-19 < y

    1. Initial program 15.2

      \[\frac{\left(x \cdot 2.0\right) \cdot y}{x - y}\]
    2. Using strategy rm
    3. Applied associate-/l*0.2

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

Runtime

Time bar (total: 38.9s)Debug log

herbie shell --seed '#(1567391828 2030694642 2833800258 828025724 3004380912 3532991858)' +o setup:early-exit
(FPCore (x y)
  :name "Linear.Projection:perspective from linear-1.19.1.3, B"

  :herbie-target
  (if (< x -1.7210442634149447e+81) (* (/ (* 2.0 x) (- x y)) y) (if (< x 8.364504563556443e+16) (/ (* x 2.0) (/ (- x y) y)) (* (/ (* 2.0 x) (- x y)) y)))

  (/ (* (* x 2.0) y) (- x y)))