Average Error: 34.2 → 5.4
Time: 28.9s
Precision: 64
Internal precision: 2944
\[\frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.718982199476945 \cdot 10^{+89}:\\ \;\;\;\;\frac{\left(-b\right) + b}{a + a} - \frac{c}{b}\\ \mathbf{if}\;b \le -2.321564696919607 \cdot 10^{-245}:\\ \;\;\;\;{\left(\sqrt[3]{\frac{\frac{1}{2} \cdot \left(c \cdot 4\right)}{{\left(\sqrt[3]{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}\right)}^3 + \left(-b\right)}}\right)}^3\\ \mathbf{if}\;b \le 9.141549925217606 \cdot 10^{+73}:\\ \;\;\;\;\frac{-b}{2 \cdot a} - \frac{\sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.2
Comparison22.3
Herbie5.4
\[ \begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \end{array} \]

Derivation

  1. Split input into 4 regimes.
  2. if b < -1.718982199476945e+89

    1. Initial program 59.4

      \[\frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Applied taylor 41.9

      \[\leadsto \frac{\left(-b\right) - \left(2 \cdot \frac{c \cdot a}{b} - b\right)}{2 \cdot a}\]
    3. Taylor expanded around -inf 41.9

      \[\leadsto \frac{\left(-b\right) - \color{blue}{\left(2 \cdot \frac{c \cdot a}{b} - b\right)}}{2 \cdot a}\]
    4. Applied simplify 0

      \[\leadsto \color{blue}{\frac{\left(-b\right) + b}{a + a} - \frac{\frac{c}{b}}{1}}\]
    5. Applied simplify 0

      \[\leadsto \frac{\left(-b\right) + b}{a + a} - \color{blue}{\frac{c}{b}}\]

    if -1.718982199476945e+89 < b < -2.321564696919607e-245

    1. Initial program 33.7

      \[\frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied flip-- 33.8

      \[\leadsto \frac{\color{blue}{\frac{{\left(-b\right)}^2 - {\left(\sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}\right)}^2}{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
    4. Applied simplify 17.2

      \[\leadsto \frac{\frac{\color{blue}{a \cdot \left(4 \cdot c\right)}}{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt 17.9

      \[\leadsto \color{blue}{{\left(\sqrt[3]{\frac{\frac{a \cdot \left(4 \cdot c\right)}{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}}\right)}^3}\]
    7. Applied simplify 9.4

      \[\leadsto {\color{blue}{\left(\sqrt[3]{\frac{\frac{1}{2} \cdot \left(c \cdot 4\right)}{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} + \left(-b\right)}}\right)}}^3\]
    8. Using strategy rm
    9. Applied add-cube-cbrt 9.5

      \[\leadsto {\left(\sqrt[3]{\frac{\frac{1}{2} \cdot \left(c \cdot 4\right)}{\color{blue}{{\left(\sqrt[3]{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}\right)}^3} + \left(-b\right)}}\right)}^3\]

    if -2.321564696919607e-245 < b < 9.141549925217606e+73

    1. Initial program 9.7

      \[\frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied div-sub 9.7

      \[\leadsto \color{blue}{\frac{-b}{2 \cdot a} - \frac{\sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\]

    if 9.141549925217606e+73 < b

    1. Initial program 42.2

      \[\frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Applied taylor 10.8

      \[\leadsto \frac{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}{2 \cdot a}\]
    3. Taylor expanded around inf 10.8

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}{2 \cdot a}\]
    4. Applied simplify 0.0

      \[\leadsto \color{blue}{\frac{\frac{c}{b}}{1} - \frac{b}{a}}\]
    5. Applied simplify 0.0

      \[\leadsto \color{blue}{\frac{c}{b}} - \frac{b}{a}\]
  3. Recombined 4 regimes into one program.
  4. Removed slow pow expressions

Runtime

Time bar (total: 28.9s) Debug logProfile

Please include this information when filing a bug report:

herbie shell --seed '#(1064524629 4159152179 2999149171 575749698 4006532819 692958815)'
(FPCore (a b c)
  :name "The quadratic formula (r2)"

  :target
  (if (< b 0) (/ c (* a (/ (+ (- b) (sqrt (- (sqr b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (sqr b) (* 4 (* a c))))) (* 2 a)))

  (/ (- (- b) (sqrt (- (sqr b) (* 4 (* a c))))) (* 2 a)))