Average Error: 30.0 → 13.9
Time: 13.9s
Precision: 64
Internal Precision: 384
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -9.5730411458898 \cdot 10^{+118}:\\ \;\;\;\;-x\\ \mathbf{if}\;x \le 2.4528332963254056 \cdot 10^{-195}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{if}\;x \le 4.8611610197161825 \cdot 10^{-177}:\\ \;\;\;\;x\\ \mathbf{if}\;x \le 3.214839002159321 \cdot 10^{+154}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Target

Original30.0
Target15.1
Herbie13.9
\[\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 < -9.5730411458898e+118

    1. Initial program 51.6

      \[\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 -9.5730411458898e+118 < x < 2.4528332963254056e-195 or 4.8611610197161825e-177 < x < 3.214839002159321e+154

    1. Initial program 19.6

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

    if 2.4528332963254056e-195 < x < 4.8611610197161825e-177 or 3.214839002159321e+154 < x

    1. Initial program 59.7

      \[\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: 13.9s)Debug log

herbie shell --seed '#(1567391828 2030694642 2833800258 828025724 3004380912 3532991858)' +o setup:early-exit
(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))))