Average Error: 29.9 → 14.0
Time: 18.1s
Precision: 64
Internal Precision: 384
\[\sqrt{x \cdot x + y \cdot y}\]
↓
\[\begin{array}{l}
\mathbf{if}\;x \le -3.993615069801488 \cdot 10^{+125}:\\
\;\;\;\;-x\\
\mathbf{if}\;x \le 2.447855958190132 \cdot 10^{-195}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\
\mathbf{if}\;x \le 2.240485188259365 \cdot 10^{-180}:\\
\;\;\;\;x\\
\mathbf{if}\;x \le 5.62501088847094 \cdot 10^{+147}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}\]
Target
| Original | 29.9 |
|---|
| Target | 14.9 |
|---|
| Herbie | 14.0 |
|---|
\[\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
- Split input into 3 regimes
if x < -3.993615069801488e+125
Initial program 52.8
\[\sqrt{x \cdot x + y \cdot y}\]
Taylor expanded around -inf 0
\[\leadsto \color{blue}{-1 \cdot x}\]
Applied simplify0
\[\leadsto \color{blue}{-x}\]
if -3.993615069801488e+125 < x < 2.447855958190132e-195 or 2.240485188259365e-180 < x < 5.62501088847094e+147
Initial program 19.6
\[\sqrt{x \cdot x + y \cdot y}\]
if 2.447855958190132e-195 < x < 2.240485188259365e-180 or 5.62501088847094e+147 < x
Initial program 58.1
\[\sqrt{x \cdot x + y \cdot y}\]
Taylor expanded around inf 0
\[\leadsto \color{blue}{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 +o reduce:binary-search
(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))))