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}\]
Target
| Original | 20.0 |
|---|
| 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 < -1.3432170256437628e+154
Initial program 59.5
\[\sqrt{x \cdot x + y}\]
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
Initial program 0.0
\[\sqrt{x \cdot x + y}\]
if 1.902380624814309e+130 < x
Initial program 52.3
\[\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 +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)))