Average Error: 29.9 → 14.0
Time: 18.1s
Precision: 64
Internal Precision: 384
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.993615069801488 \cdot 10^{+125}:\\ \;\;\;\;-x\\ \mathbf{if}\;x \le 2.447855958190132 \cdot 10^{-195}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{if}\;x \le 2.240485188259365 \cdot 10^{-180}:\\ \;\;\;\;x\\ \mathbf{if}\;x \le 5.62501088847094 \cdot 10^{+147}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Target

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

Derivation

  1. Split input into 3 regimes
  2. if x < -3.993615069801488e+125

    1. Initial program 52.8

      \[\sqrt{x \cdot x + y \cdot y}\]
    2. Taylor expanded around -inf 0

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Applied simplify0

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

    if -3.993615069801488e+125 < x < 2.447855958190132e-195 or 2.240485188259365e-180 < x < 5.62501088847094e+147

    1. Initial program 19.6

      \[\sqrt{x \cdot x + y \cdot y}\]

    if 2.447855958190132e-195 < x < 2.240485188259365e-180 or 5.62501088847094e+147 < x

    1. Initial program 58.1

      \[\sqrt{x \cdot x + y \cdot y}\]
    2. Taylor expanded around inf 0

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

Runtime

Time bar (total: 18.1s)Debug log

herbie shell --seed '#(1567391828 2030694642 2833800258 828025724 3004380912 3532991858)' +o setup:early-exit +o reduce:binary-search
(FPCore (x y)
  :name "Data.Octree.Internal:octantDistance  from Octree-0.5.4.2"

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

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