Average Error: 32.8 → 9.1
Time: 1.6m
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}\;\frac{c \cdot \frac{4}{-2}}{\frac{\frac{c}{b}}{1}} \le -2.2392974626661273 \cdot 10^{+102}:\\
\;\;\;\;\frac{c}{b} \cdot \frac{-2}{2}\\
\mathbf{if}\;\frac{c \cdot \frac{4}{-2}}{\frac{\frac{c}{b}}{1}} \le -1.4337071185022381 \cdot 10^{-241}:\\
\;\;\;\;\frac{\frac{c \cdot a}{1} \cdot \frac{4}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\\
\mathbf{if}\;\frac{c \cdot \frac{4}{-2}}{\frac{\frac{c}{b}}{1}} \le 1.612877009196424 \cdot 10^{+65}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c}{b}}{1} - \frac{b}{a}\\
\end{array}\]
Target
| Original | 32.8 |
|---|
| Target | 20.4 |
|---|
| Herbie | 9.1 |
|---|
\[\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 (/ (* c (/ 4 -2)) (/ (/ c b) 1)) < -2.2392974626661273e+102
Initial program 56.5
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around inf 13.4
\[\leadsto \frac{\color{blue}{-2 \cdot \frac{c \cdot a}{b}}}{2 \cdot a}\]
Applied simplify2.3
\[\leadsto \color{blue}{\frac{c}{b} \cdot \frac{-2}{2}}\]
if -2.2392974626661273e+102 < (/ (* c (/ 4 -2)) (/ (/ c b) 1)) < -1.4337071185022381e-241
Initial program 36.3
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
- Using strategy
rm Applied flip-+36.3
\[\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.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}\]
- Using strategy
rm Applied *-un-lft-identity16.2
\[\leadsto \frac{\frac{\left(c \cdot a\right) \cdot 4}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}}}{2 \cdot a}\]
Applied times-frac16.3
\[\leadsto \frac{\color{blue}{\frac{c \cdot a}{1} \cdot \frac{4}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
if -1.4337071185022381e-241 < (/ (* c (/ 4 -2)) (/ (/ c b) 1)) < 1.612877009196424e+65
Initial program 11.3
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
if 1.612877009196424e+65 < (/ (* c (/ 4 -2)) (/ (/ c b) 1))
Initial program 38.1
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
Taylor expanded around -inf 9.2
\[\leadsto \frac{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}{2 \cdot a}\]
Applied simplify4.6
\[\leadsto \color{blue}{\frac{\frac{c}{b}}{1} - \frac{b}{a}}\]
- Recombined 4 regimes into one program.
Runtime
herbie shell --seed '#(1070227846 1561819246 480764335 4016816270 2602869839 2117310382)'
(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)))