Average Error: 33.2 → 10.0
Time: 2.3m
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 -7.094821279311991 \cdot 10^{+50}:\\
\;\;\;\;\frac{\left(-b\right) + b}{a + a} - \frac{c}{b}\\
\mathbf{if}\;b \le -8935664797341.434:\\
\;\;\;\;\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{if}\;b \le -1.660099227068191 \cdot 10^{-124}:\\
\;\;\;\;\frac{\left(-b\right) + b}{a + a} - \frac{c}{b}\\
\mathbf{if}\;b \le 4.521805228743851 \cdot 10^{+91}:\\
\;\;\;\;\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}\]
Target
| Original | 33.2 |
|---|
| Target | 20.5 |
|---|
| Herbie | 10.0 |
|---|
\[\begin{array}{l}
\mathbf{if}\;b \lt 0:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\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 < -7.094821279311991e+50 or -8935664797341.434 < b < -1.660099227068191e-124
Initial program 51.3
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around -inf 47.3
\[\leadsto \frac{\left(-b\right) - \color{blue}{\left(2 \cdot \frac{c \cdot a}{b} - b\right)}}{2 \cdot a}\]
Applied simplify10.8
\[\leadsto \color{blue}{\frac{\left(-b\right) + b}{a + a} - \frac{\frac{c}{b}}{1}}\]
Applied simplify10.8
\[\leadsto \frac{\left(-b\right) + b}{a + a} - \color{blue}{\frac{c}{b}}\]
if -7.094821279311991e+50 < b < -8935664797341.434
Initial program 44.9
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied flip--45.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 simplify12.3
\[\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 -1.660099227068191e-124 < b < 4.521805228743851e+91
Initial program 11.4
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied div-inv11.5
\[\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}}\]
if 4.521805228743851e+91 < b
Initial program 42.3
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around inf 9.9
\[\leadsto \frac{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}{2 \cdot a}\]
Applied simplify3.7
\[\leadsto \color{blue}{\frac{\frac{c}{b}}{1} - \frac{b}{a}}\]
Applied simplify3.7
\[\leadsto \color{blue}{\frac{c}{b}} - \frac{b}{a}\]
- Recombined 4 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1063154770 1824007522 645063331 41291047 494775821 1237684644)'
(FPCore (a b c)
:name "quadm (p42, negative)"
:herbie-target
(if (< b 0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))