Average Error: 33.5 → 8.8
Time: 2.7m
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 -4.6073003559298436 \cdot 10^{+89}:\\ \;\;\;\;\frac{\frac{c}{\frac{b}{a}}}{a} - \frac{b}{a}\\ \mathbf{if}\;b \le -1.7783861994221244 \cdot 10^{-287}:\\ \;\;\;\;\frac{1}{a \cdot 2} \cdot \left(\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)\right)\\ \mathbf{if}\;b \le 4.7334951176876386 \cdot 10^{+20}:\\ \;\;\;\;\frac{\frac{4 \cdot \left(c \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}{a \cdot 2}\\ \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.5
Target20.2
Herbie8.8
\[\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 < -4.6073003559298436e+89

    1. Initial program 43.8

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

      \[\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}}\]
    4. Taylor expanded around -inf 9.8

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

      \[\leadsto \color{blue}{\frac{\frac{c}{\frac{b}{a}}}{a} - \frac{b}{a}}\]

    if -4.6073003559298436e+89 < b < -1.7783861994221244e-287

    1. Initial program 8.7

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

      \[\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 -1.7783861994221244e-287 < b < 4.7334951176876386e+20

    1. Initial program 27.1

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

      \[\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}\]
    4. Applied simplify16.7

      \[\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 4.7334951176876386e+20 < b

    1. Initial program 55.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around inf 44.3

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

      \[\leadsto \color{blue}{\left(-1\right) \cdot \frac{c}{b}}\]
  3. Recombined 4 regimes into one program.
  4. Applied simplify8.8

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -4.6073003559298436 \cdot 10^{+89}:\\ \;\;\;\;\frac{\frac{c}{\frac{b}{a}}}{a} - \frac{b}{a}\\ \mathbf{if}\;b \le -1.7783861994221244 \cdot 10^{-287}:\\ \;\;\;\;\frac{1}{a \cdot 2} \cdot \left(\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)\right)\\ \mathbf{if}\;b \le 4.7334951176876386 \cdot 10^{+20}:\\ \;\;\;\;\frac{\frac{4 \cdot \left(c \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 2.7m)Debug logProfile

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