Average Error: 33.4 → 9.6
Time: 2.4m
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 -5.526507823399679 \cdot 10^{+75}:\\
\;\;\;\;\frac{-c}{\frac{b}{1}}\\
\mathbf{if}\;-b \le -1.706688010605929 \cdot 10^{-79}:\\
\;\;\;\;\frac{\frac{\left(-4\right) \cdot \left(c \cdot a\right)}{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} + b}}{2 \cdot a}\\
\mathbf{if}\;-b \le -8.395702196690546 \cdot 10^{-126}:\\
\;\;\;\;\frac{-c}{\frac{b}{1}}\\
\mathbf{if}\;-b \le 1.7724463622243848 \cdot 10^{+74}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}\]
Target
| Original | 33.4 |
|---|
| Target | 20.0 |
|---|
| Herbie | 9.6 |
|---|
\[\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 4 regimes
if (- b) < -5.526507823399679e+75 or -1.706688010605929e-79 < (- b) < -8.395702196690546e-126
Initial program 53.9
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied simplify53.9
\[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{2 \cdot a}}\]
Taylor expanded around inf 43.4
\[\leadsto \frac{\color{blue}{\left(b - 2 \cdot \frac{c \cdot a}{b}\right)} - b}{2 \cdot a}\]
Applied simplify7.4
\[\leadsto \color{blue}{\frac{-c}{\frac{b}{1}}}\]
if -5.526507823399679e+75 < (- b) < -1.706688010605929e-79
Initial program 43.7
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied simplify43.7
\[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{2 \cdot a}}\]
- Using strategy
rm Applied flip--43.8
\[\leadsto \frac{\color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} \cdot \sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b \cdot b}{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} + b}}}{2 \cdot a}\]
Applied simplify15.0
\[\leadsto \frac{\frac{\color{blue}{\left(-4\right) \cdot \left(c \cdot a\right)}}{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} + b}}{2 \cdot a}\]
if -8.395702196690546e-126 < (- b) < 1.7724463622243848e+74
Initial program 11.5
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied simplify11.5
\[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{2 \cdot a}}\]
if 1.7724463622243848e+74 < (- b)
Initial program 38.9
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Applied simplify39.0
\[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{2 \cdot a}}\]
Taylor expanded around -inf 4.8
\[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
Applied simplify4.8
\[\leadsto \color{blue}{\frac{-b}{a}}\]
- Recombined 4 regimes into one program.
Runtime
herbie shell --seed '#(1070833653 108281690 3330367898 3632331308 3494323072 43156186)'
(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)))