Average Error: 32.8 → 9.4
Time: 2.5m
Precision: 64
Internal Precision: 3456
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
↓
\[\begin{array}{l}
\mathbf{if}\;b \le -1.1901431689654337 \cdot 10^{+154}:\\
\;\;\;\;\frac{\frac{c}{b}}{1} - \frac{b + b}{2 \cdot a}\\
\mathbf{if}\;b \le 2.6801633678126084 \cdot 10^{-89}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\frac{a}{a} \cdot \frac{c}{2}\right) \cdot 4}{\left(-\left(b + b\right)\right) + \frac{2 \cdot c}{\frac{b}{a}}}\\
\end{array}\]
Target
| Original | 32.8 |
|---|
| Target | 20.5 |
|---|
| Herbie | 9.4 |
|---|
\[\begin{array}{l}
\mathbf{if}\;b \lt 0:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\
\end{array}\]
Derivation
- Split input into 3 regimes
if b < -1.1901431689654337e+154
Initial program 60.8
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around -inf 9.6
\[\leadsto \frac{\left(-b\right) + \color{blue}{\left(2 \cdot \frac{c \cdot a}{b} - b\right)}}{2 \cdot a}\]
Applied simplify1.6
\[\leadsto \color{blue}{\frac{\frac{c}{b}}{1} - \frac{b + b}{2 \cdot a}}\]
if -1.1901431689654337e+154 < b < 2.6801633678126084e-89
Initial program 11.0
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
if 2.6801633678126084e-89 < b
Initial program 51.9
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied div-inv51.9
\[\leadsto \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}}\]
- Using strategy
rm Applied flip-+52.0
\[\leadsto \color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}} \cdot \frac{1}{2 \cdot a}\]
Applied simplify26.0
\[\leadsto \frac{\color{blue}{\left(c \cdot a\right) \cdot 4}}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}} \cdot \frac{1}{2 \cdot a}\]
Taylor expanded around inf 20.6
\[\leadsto \frac{\left(c \cdot a\right) \cdot 4}{\left(-b\right) - \color{blue}{\left(b - 2 \cdot \frac{c \cdot a}{b}\right)}} \cdot \frac{1}{2 \cdot a}\]
Applied simplify9.5
\[\leadsto \color{blue}{\frac{\left(\frac{a}{a} \cdot \frac{c}{2}\right) \cdot 4}{\left(-\left(b + b\right)\right) + \frac{2 \cdot c}{\frac{b}{a}}}}\]
- Recombined 3 regimes into one program.
Runtime
herbie shell --seed '#(1070386091 2509006183 1430610344 1025408621 36622005 1425925650)'
(FPCore (a b c)
:name "quadp (p42, positive)"
:herbie-target
(if (< b 0) (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))