Average Error: 20.0 → 0.0
Time: 25.7s
Precision: 64
Internal Precision: 384
\[\sqrt{x \cdot x + y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.3432170256437628 \cdot 10^{+154}:\\ \;\;\;\;-\left(\frac{1}{2} \cdot \frac{y}{x} + x\right)\\ \mathbf{if}\;x \le 1.902380624814309 \cdot 10^{+130}:\\ \;\;\;\;\sqrt{x \cdot x + y}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{y}{x} + x\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Target

Original20.0
Target0.5
Herbie0.0
\[\begin{array}{l} \mathbf{if}\;x \lt -1.5097698010472593 \cdot 10^{+153}:\\ \;\;\;\;-\left(\frac{1}{2} \cdot \frac{y}{x} + x\right)\\ \mathbf{if}\;x \lt 5.582399551122541 \cdot 10^{+57}:\\ \;\;\;\;\sqrt{x \cdot x + y}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{y}{x} + x\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -1.3432170256437628e+154

    1. Initial program 59.5

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

      \[\leadsto \color{blue}{-\left(\frac{1}{2} \cdot \frac{y}{x} + x\right)}\]

    if -1.3432170256437628e+154 < x < 1.902380624814309e+130

    1. Initial program 0.0

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

    if 1.902380624814309e+130 < x

    1. Initial program 52.3

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

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

Runtime

Time bar (total: 25.7s)Debug log

herbie shell --seed '#(1567391828 2030694642 2833800258 828025724 3004380912 3532991858)' +o setup:early-exit +o reduce:binary-search
(FPCore (x y)
  :name "Linear.Quaternion:$clog from linear-1.19.1.3"

  :herbie-target
  (if (< x -1.5097698010472593e+153) (- (+ (* 1/2 (/ y x)) x)) (if (< x 5.582399551122541e+57) (sqrt (+ (* x x) y)) (+ (* 1/2 (/ y x)) x)))

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