Average Error: 33.5 → 8.0
Time: 2.8m
Precision: 64
Internal Precision: 2688
\[\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 -3.3955093218469717 \cdot 10^{+145}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{if}\;b \le 2.2909014290158868 \cdot 10^{-107}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\mathbf{if}\;b \le 3.1746500024866854 \cdot 10^{+75}:\\
\;\;\;\;\frac{\frac{\left(c \cdot a\right) \cdot 4}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\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.5 |
|---|
| Target | 21.2 |
|---|
| Herbie | 8.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 4 regimes
if b < -3.3955093218469717e+145
Initial program 57.8
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around -inf 11.5
\[\leadsto \frac{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}{2 \cdot a}\]
Applied simplify0.0
\[\leadsto \color{blue}{\frac{\frac{c}{b}}{1} - \frac{b}{a}}\]
Applied simplify0.0
\[\leadsto \color{blue}{\frac{c}{b}} - \frac{b}{a}\]
if -3.3955093218469717e+145 < b < 2.2909014290158868e-107
Initial program 11.0
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
if 2.2909014290158868e-107 < b < 3.1746500024866854e+75
Initial program 39.9
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied flip-+40.0
\[\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 simplify16.0
\[\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}\]
if 3.1746500024866854e+75 < b
Initial program 58.4
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied flip-+58.4
\[\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 simplify31.9
\[\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 15.7
\[\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 simplify1.6
\[\leadsto \color{blue}{\frac{\left(1 \cdot \frac{c}{2}\right) \cdot 4}{\frac{c + c}{\frac{b}{a}} - \left(b + b\right)}}\]
Applied simplify1.7
\[\leadsto \frac{\color{blue}{\frac{4}{\frac{2}{c}}}}{\frac{c + c}{\frac{b}{a}} - \left(b + b\right)}\]
- Recombined 4 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1062930989 876886121 3990119081 3032829768 3060892583 1929069376)'
(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)))