Average Error: 34.3 → 4.9
Time: 26.4s
Precision: 64
Internal Precision: 384
\[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
↓
\[\begin{array}{l}
\mathbf{if}\;y \le -7.833327672762858 \cdot 10^{+152}:\\
\;\;\;\;-1.0\\
\mathbf{if}\;y \le -4.242771342822211 \cdot 10^{-79}:\\
\;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\\
\mathbf{if}\;y \le 1.0512428670373637 \cdot 10^{-135}:\\
\;\;\;\;1\\
\mathbf{if}\;y \le 2.586528948499352 \cdot 10^{+28}:\\
\;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\\
\mathbf{if}\;y \le 6.89776155181784 \cdot 10^{+58}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1.0\\
\end{array}\]
Target
| Original | 34.3 |
|---|
| Target | 34.3 |
|---|
| Herbie | 4.9 |
|---|
\[\begin{array}{l}
\mathbf{if}\;\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} \lt 0.9743233849626781:\\
\;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot y\right) \cdot 4.0} - \frac{\left(y \cdot y\right) \cdot 4.0}{x \cdot x + \left(y \cdot y\right) \cdot 4.0}\\
\mathbf{else}:\\
\;\;\;\;{\left(\frac{x}{\sqrt{x \cdot x + \left(y \cdot y\right) \cdot 4.0}}\right)}^{2} - \frac{\left(y \cdot y\right) \cdot 4.0}{x \cdot x + \left(y \cdot y\right) \cdot 4.0}\\
\end{array}\]
Derivation
- Split input into 3 regimes
if y < -7.833327672762858e+152 or 6.89776155181784e+58 < y
Initial program 53.8
\[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
Taylor expanded around 0 0
\[\leadsto \color{blue}{-1.0}\]
if -7.833327672762858e+152 < y < -4.242771342822211e-79 or 1.0512428670373637e-135 < y < 2.586528948499352e+28
Initial program 15.6
\[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
- Using strategy
rm Applied div-sub15.6
\[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}}\]
if -4.242771342822211e-79 < y < 1.0512428670373637e-135 or 2.586528948499352e+28 < y < 6.89776155181784e+58
Initial program 32.5
\[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
Taylor expanded around inf 0
\[\leadsto \color{blue}{1}\]
- 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 "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
:herbie-target
(if (< (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4.0))) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4.0)))) 2) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))))
(/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))