Average Error: 29.9 → 14.3
Time: 8.1s
Precision: 64
Internal precision: 128
\[\sqrt{x \cdot x + y \cdot y}\]
⬇
\[\begin{array}{l}
\mathbf{if}\;y \le -1.1496000680102836 \cdot 10^{+163}:\\
\;\;\;\;-y\\
\mathbf{if}\;y \le 4.692828868299432 \cdot 10^{+91}:\\
\;\;\;\;\sqrt{{y}^2 + x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}\]
Target
| Original | 29.9 |
| Comparison | 20.0 |
| Herbie | 14.3 |
\[ \begin{array}{l}
\mathbf{if}\;x \lt -1.1236950826599826 \cdot 10^{+145}:\\
\;\;\;\;-x\\
\mathbf{if}\;x \lt 1.116557621183362 \cdot 10^{+93}:\\
\;\;\;\;\sqrt{{x}^2 + {y}^2}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array} \]
Derivation
- Split input into 3 regimes.
-
if y < -1.1496000680102836e+163
Initial program 59.5
\[\sqrt{x \cdot x + y \cdot y}\]
Applied simplify 59.5
\[\leadsto \color{blue}{\sqrt{{y}^2 + x \cdot x}}\]
Applied taylor 0
\[\leadsto -1 \cdot y\]
Taylor expanded around -inf 0
\[\leadsto \color{blue}{-1 \cdot y}\]
Applied simplify 0
\[\leadsto \color{blue}{-y}\]
if -1.1496000680102836e+163 < y < 4.692828868299432e+91
Initial program 20.4
\[\sqrt{x \cdot x + y \cdot y}\]
Applied simplify 20.4
\[\leadsto \color{blue}{\sqrt{{y}^2 + x \cdot x}}\]
if 4.692828868299432e+91 < y
Initial program 47.2
\[\sqrt{x \cdot x + y \cdot y}\]
Applied simplify 47.2
\[\leadsto \color{blue}{\sqrt{{y}^2 + x \cdot x}}\]
Applied taylor 0
\[\leadsto y\]
Taylor expanded around inf 0
\[\leadsto \color{blue}{y}\]
- Recombined 3 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie --seed '#(2720615825 1004056919 4120259589 2051053137 2275611525 1862790197)'
(FPCore (x y)
:name "Data.Octree.Internal:octantDistance from Octree-0.5.4.2"
:target
(if (< x -1.1236950826599826e+145) (- x) (if (< x 1.116557621183362e+93) (sqrt (+ (sqr x) (sqr y))) x))
(sqrt (+ (* x x) (* y y))))