Average Error: 33.5 → 8.8
Time: 2.1m
Precision: 64
Internal Precision: 3392
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -3.278194171645191 \cdot 10^{+90}:\\ \;\;\;\;\frac{\frac{2 \cdot c}{\frac{b}{a}} - \left(b + b\right)}{2 \cdot a}\\ \mathbf{if}\;b \le -1.6241581144933301 \cdot 10^{-288}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{if}\;b \le 3.8248083710801805 \cdot 10^{+20}:\\ \;\;\;\;\frac{\frac{c \cdot \left(4 \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}{2 \cdot a}\\ \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 - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -3.278194171645191e+90

    1. Initial program 44.1

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

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

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

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

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

    if -3.278194171645191e+90 < b < -1.6241581144933301e-288

    1. Initial program 8.6

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

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

    if -1.6241581144933301e-288 < b < 3.8248083710801805e+20

    1. Initial program 27.2

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

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

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

    if 3.8248083710801805e+20 < b

    1. Initial program 55.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{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 -3.278194171645191 \cdot 10^{+90}:\\ \;\;\;\;\frac{\frac{2 \cdot c}{\frac{b}{a}} - \left(b + b\right)}{2 \cdot a}\\ \mathbf{if}\;b \le -1.6241581144933301 \cdot 10^{-288}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{if}\;b \le 3.8248083710801805 \cdot 10^{+20}:\\ \;\;\;\;\frac{\frac{c \cdot \left(4 \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 2.1m)Debug logProfile

herbie shell --seed 2018167 
(FPCore (a b c)
  :name "The quadratic formula (r1)"

  :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)))