Average Error: 20.1 → 0.0
Time: 18.9s
Precision: 64
Internal Precision: 384
\[\sqrt{x \cdot x + y}\]
↓
\[\begin{array}{l}
\mathbf{if}\;x \le -2.013881564242057 \cdot 10^{+151}:\\
\;\;\;\;-\left(\frac{1}{2} \cdot \frac{y}{x} + x\right)\\
\mathbf{if}\;x \le 2.556265139380831 \cdot 10^{+130}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2} \cdot \frac{y}{x} + x\\
\end{array}\]
Target
| Original | 20.1 |
|---|
| Target | 0.5 |
|---|
| Herbie | 0.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
- Split input into 3 regimes
if x < -2.013881564242057e+151
Initial program 58.4
\[\sqrt{x \cdot x + y}\]
Taylor expanded around -inf 0
\[\leadsto \color{blue}{-\left(\frac{1}{2} \cdot \frac{y}{x} + x\right)}\]
if -2.013881564242057e+151 < x < 2.556265139380831e+130
Initial program 0.0
\[\sqrt{x \cdot x + y}\]
if 2.556265139380831e+130 < x
Initial program 52.6
\[\sqrt{x \cdot x + y}\]
Taylor expanded around inf 0
\[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{y}{x} + x}\]
- Recombined 3 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1567391828 2030694642 2833800258 828025724 3004380912 3532991858)' +o setup:early-exit
(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)))