Average Error: 29.9 → 14.3
Time: 8.1s
Precision: 64
Internal precision: 128
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -1.1496000680102836 \cdot 10^{+163}:\\ \;\;\;\;-y\\ \mathbf{if}\;y \le 4.692828868299432 \cdot 10^{+91}:\\ \;\;\;\;\sqrt{{y}^2 + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Target

Original29.9
Comparison20.0
Herbie14.3
\[ \begin{array}{l} \mathbf{if}\;x \lt -1.1236950826599826 \cdot 10^{+145}:\\ \;\;\;\;-x\\ \mathbf{if}\;x \lt 1.116557621183362 \cdot 10^{+93}:\\ \;\;\;\;\sqrt{{x}^2 + {y}^2}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Derivation

  1. Split input into 3 regimes.
  2. if y < -1.1496000680102836e+163

    1. Initial program 59.5

      \[\sqrt{x \cdot x + y \cdot y}\]
    2. Applied simplify 59.5

      \[\leadsto \color{blue}{\sqrt{{y}^2 + x \cdot x}}\]
    3. Applied taylor 0

      \[\leadsto -1 \cdot y\]
    4. Taylor expanded around -inf 0

      \[\leadsto \color{blue}{-1 \cdot y}\]
    5. Applied simplify 0

      \[\leadsto \color{blue}{-y}\]

    if -1.1496000680102836e+163 < y < 4.692828868299432e+91

    1. Initial program 20.4

      \[\sqrt{x \cdot x + y \cdot y}\]
    2. Applied simplify 20.4

      \[\leadsto \color{blue}{\sqrt{{y}^2 + x \cdot x}}\]

    if 4.692828868299432e+91 < y

    1. Initial program 47.2

      \[\sqrt{x \cdot x + y \cdot y}\]
    2. Applied simplify 47.2

      \[\leadsto \color{blue}{\sqrt{{y}^2 + x \cdot x}}\]
    3. Applied taylor 0

      \[\leadsto y\]
    4. Taylor expanded around inf 0

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

Runtime

Time bar (total: 8.1s) Debug log

Please include this information when filing a bug report:

herbie --seed '#(2720615825 1004056919 4120259589 2051053137 2275611525 1862790197)'
(FPCore (x y)
  :name "Data.Octree.Internal:octantDistance  from Octree-0.5.4.2"

  :target
  (if (< x -1.1236950826599826e+145) (- x) (if (< x 1.116557621183362e+93) (sqrt (+ (sqr x) (sqr y))) x))

  (sqrt (+ (* x x) (* y y))))