Average Error: 19.6 → 0.0
Time: 9.0s
Precision: 64
Internal precision: 128
\[\sqrt{x \cdot x + y}\]
⬇
\[\begin{array}{l}
\mathbf{if}\;x \le -1.798458072626415 \cdot 10^{+148}:\\
\;\;\;\;-\left(x + \frac{1}{2} \cdot \frac{y}{x}\right)\\
\mathbf{if}\;x \le 3.3156380580081446 \cdot 10^{+107}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{1}{2} \cdot \frac{y}{x}\\
\end{array}\]
Target
| Original | 19.6 |
| Comparison | 0.3 |
| 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}^2 + y}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2} \cdot \frac{y}{x} + x\\
\end{array} \]
Derivation
- Split input into 3 regimes.
-
if x < -1.798458072626415e+148
Initial program 57.9
\[\sqrt{x \cdot x + y}\]
Applied taylor 0
\[\leadsto -\left(x + \frac{1}{2} \cdot \frac{y}{x}\right)\]
Taylor expanded around -inf 0
\[\leadsto \color{blue}{-\left(x + \frac{1}{2} \cdot \frac{y}{x}\right)}\]
if -1.798458072626415e+148 < x < 3.3156380580081446e+107
Initial program 0.0
\[\sqrt{x \cdot x + y}\]
if 3.3156380580081446e+107 < x
Initial program 46.2
\[\sqrt{x \cdot x + y}\]
Applied taylor 0.0
\[\leadsto x + \frac{1}{2} \cdot \frac{y}{x}\]
Taylor expanded around inf 0.0
\[\leadsto \color{blue}{x + \frac{1}{2} \cdot \frac{y}{x}}\]
- Recombined 3 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie --seed '#(1213585941 1107528756 3166255956 227454801 1182528254 2608549406)'
(FPCore (x y)
:name "Linear.Quaternion:$clog from linear-1.19.1.3"
:target
(if (< x -1.5097698010472593e+153) (- (+ (* 1/2 (/ y x)) x)) (if (< x 5.582399551122541e+57) (sqrt (+ (sqr x) y)) (+ (* 1/2 (/ y x)) x)))
(sqrt (+ (* x x) y)))