Average Error: 33.8 → 9.4
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 -7.791543498596527 \cdot 10^{+36}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -4.37052678659646 \cdot 10^{-60}:\\ \;\;\;\;\frac{\frac{4 \cdot \left(a \cdot c\right)}{\sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)} - b}}{2 \cdot a}\\ \mathbf{elif}\;b \le -9.278703398573534 \cdot 10^{-80}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 3.808029533446154 \cdot 10^{+118}:\\ \;\;\;\;\frac{1}{2 \cdot a} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{\frac{b}{a}}}{a} - \frac{b}{a}\\ \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.8
Target20.8
Herbie9.4
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\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.791543498596527e+36 or -4.37052678659646e-60 < b < -9.278703398573534e-80

    1. Initial program 55.2

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

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

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

    if -7.791543498596527e+36 < b < -4.37052678659646e-60

    1. Initial program 44.0

      \[\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--44.1

      \[\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 simplify15.5

      \[\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}\]
    5. Applied simplify15.5

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

    if -9.278703398573534e-80 < b < 3.808029533446154e+118

    1. Initial program 12.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-inv12.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}}\]

    if 3.808029533446154e+118 < b

    1. Initial program 50.2

      \[\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-inv50.2

      \[\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 10.0

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -7.791543498596527 \cdot 10^{+36}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -4.37052678659646 \cdot 10^{-60}:\\ \;\;\;\;\frac{\frac{4 \cdot \left(a \cdot c\right)}{\sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)} - b}}{2 \cdot a}\\ \mathbf{elif}\;b \le -9.278703398573534 \cdot 10^{-80}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 3.808029533446154 \cdot 10^{+118}:\\ \;\;\;\;\frac{1}{2 \cdot a} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{\frac{b}{a}}}{a} - \frac{b}{a}\\ \end{array}}\]

Runtime

Time bar (total: 2.7m)Debug logProfile

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

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

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