Average Error: 31.2 → 16.3
Time: 22.3s
Precision: 64
Internal precision: 128
\[\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}\;\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} \le 0.99995974222954:\\
\;\;\;\;\frac{x \cdot x}{x \cdot x + {y}^2 \cdot 4.0} - \frac{{y}^2 \cdot 4.0}{x \cdot x + {y}^2 \cdot 4.0}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}\]
Target
| Original | 31.2 |
| Comparison | 31.3 |
| Herbie | 16.3 |
\[ \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}^2}{{x}^2 + {y}^2 \cdot 4.0} - \frac{{y}^2 \cdot 4.0}{{x}^2 + {y}^2 \cdot 4.0}\\
\mathbf{else}:\\
\;\;\;\;{\left(\frac{x}{\sqrt{{x}^2 + {y}^2 \cdot 4.0}}\right)}^2 - \frac{{y}^2 \cdot 4.0}{{x}^2 + {y}^2 \cdot 4.0}\\
\end{array} \]
Derivation
- Split input into 2 regimes.
-
if (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))) < 0.99995974222954
Initial program 0.0
\[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
Applied simplify 0.0
\[\leadsto \color{blue}{\frac{x \cdot x - {y}^2 \cdot 4.0}{x \cdot x + {y}^2 \cdot 4.0}}\]
- Using strategy
rm
Applied div-sub 0.0
\[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + {y}^2 \cdot 4.0} - \frac{{y}^2 \cdot 4.0}{x \cdot x + {y}^2 \cdot 4.0}}\]
if 0.99995974222954 < (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y)))
Initial program 41.8
\[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
Applied simplify 41.8
\[\leadsto \color{blue}{\frac{x \cdot x - {y}^2 \cdot 4.0}{x \cdot x + {y}^2 \cdot 4.0}}\]
Applied taylor 21.7
\[\leadsto 1\]
Taylor expanded around inf 21.7
\[\leadsto \color{blue}{1}\]
- Recombined 2 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie --seed '#(1124604979 3004756373 289015944 3802788677 3056753239 1938455670)'
(FPCore (x y)
:name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
:target
(if (< (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))) 0.9743233849626781) (- (/ (sqr x) (+ (sqr x) (* (sqr y) 4.0))) (/ (* (sqr y) 4.0) (+ (sqr x) (* (sqr y) 4.0)))) (- (sqr (/ x (sqrt (+ (sqr x) (* (sqr y) 4.0))))) (/ (* (sqr y) 4.0) (+ (sqr x) (* (sqr y) 4.0)))))
(/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))