Average Error: 33.1 → 8.6
Time: 2.6m
Precision: 64
Internal Precision: 3392
\[\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.739999686026577 \cdot 10^{+110}:\\ \;\;\;\;\frac{c}{b} - \frac{b + b}{2 \cdot a}\\ \mathbf{if}\;b \le 4.308150604481148 \cdot 10^{-158}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} - b}}\\ \mathbf{if}\;b \le 1.643123946810858 \cdot 10^{+22}:\\ \;\;\;\;\frac{\frac{\left(-a\right) \cdot \left(c \cdot 4\right)}{2 \cdot a}}{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} + b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original33.1
Target20.3
Herbie8.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

  1. Split input into 4 regimes
  2. if b < -7.739999686026577e+110

    1. Initial program 46.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Applied simplify46.6

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{2 \cdot a}}\]
    3. Taylor expanded around -inf 9.6

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

      \[\leadsto \color{blue}{\frac{c}{b} \cdot 1 - \frac{b + b}{2 \cdot a}}\]

    if -7.739999686026577e+110 < b < 4.308150604481148e-158

    1. Initial program 10.4

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied clear-num10.6

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

    if 4.308150604481148e-158 < b < 1.643123946810858e+22

    1. Initial program 34.1

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Applied simplify34.1

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied div-inv34.1

      \[\leadsto \color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b\right) \cdot \frac{1}{2 \cdot a}}\]
    5. Using strategy rm
    6. Applied flip--34.2

      \[\leadsto \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}} \cdot \frac{1}{2 \cdot a}\]
    7. Applied associate-*l/34.3

      \[\leadsto \color{blue}{\frac{\left(\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\right) \cdot \frac{1}{2 \cdot a}}{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} + b}}\]
    8. Applied simplify16.4

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

    if 1.643123946810858e+22 < b

    1. Initial program 55.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Applied simplify55.5

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{2 \cdot a}}\]
    3. Taylor expanded around inf 44.0

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

      \[\leadsto \color{blue}{\frac{-c}{\frac{b}{1}}}\]
  3. Recombined 4 regimes into one program.
  4. Applied simplify8.6

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -7.739999686026577 \cdot 10^{+110}:\\ \;\;\;\;\frac{c}{b} - \frac{b + b}{2 \cdot a}\\ \mathbf{if}\;b \le 4.308150604481148 \cdot 10^{-158}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} - b}}\\ \mathbf{if}\;b \le 1.643123946810858 \cdot 10^{+22}:\\ \;\;\;\;\frac{\frac{\left(-a\right) \cdot \left(c \cdot 4\right)}{2 \cdot a}}{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} + b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 2.6m)Debug logProfile

herbie shell --seed 2018166 
(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)))