Average Error: 33.2 → 10.0
Time: 2.2m
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.4259686058446102 \cdot 10^{+154}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{if}\;b \le 1.056111401872344 \cdot 10^{-129}:\\
\;\;\;\;\frac{b + \left(-\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a}\right)}{-2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{4}{\frac{2}{c}}}{\frac{c + c}{\frac{b}{a}} - \left(b + b\right)}\\
\end{array}\]
Target
| Original | 33.2 |
|---|
| Target | 20.2 |
|---|
| Herbie | 10.0 |
|---|
\[\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.4259686058446102e+154
Initial program 60.9
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around -inf 2.2
\[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
Applied simplify2.2
\[\leadsto \color{blue}{\frac{-b}{a}}\]
if -1.4259686058446102e+154 < b < 1.056111401872344e-129
Initial program 10.4
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied frac-2neg10.4
\[\leadsto \color{blue}{\frac{-\left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}{-2 \cdot a}}\]
Applied simplify10.4
\[\leadsto \frac{\color{blue}{b + \left(-\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a}\right)}}{-2 \cdot a}\]
if 1.056111401872344e-129 < b
Initial program 50.6
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied flip-+50.6
\[\leadsto \frac{\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)}}}}{2 \cdot a}\]
Applied simplify24.2
\[\leadsto \frac{\frac{\color{blue}{\left(c \cdot a\right) \cdot 4}}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
Taylor expanded around inf 22.0
\[\leadsto \frac{\frac{\left(c \cdot a\right) \cdot 4}{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}}{2 \cdot a}\]
Applied simplify11.4
\[\leadsto \color{blue}{\frac{\left(1 \cdot \frac{c}{2}\right) \cdot 4}{\frac{c + c}{\frac{b}{a}} - \left(b + b\right)}}\]
Applied simplify11.5
\[\leadsto \frac{\color{blue}{\frac{4}{\frac{2}{c}}}}{\frac{c + c}{\frac{b}{a}} - \left(b + b\right)}\]
- Recombined 3 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1063185673 2139736501 2393378123 1907444849 1070993796 1007244912)'
(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)))