Average Error: 33.4 → 8.8
Time: 42.1s
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 -8.687420785654022 \cdot 10^{+64}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -2.4136707020362904 \cdot 10^{-185}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot a\right) \cdot c}{2 \cdot a}}{\left(-b\right) + \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}}\\ \mathbf{elif}\;b \le 1.5687409701741605 \cdot 10^{+116}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\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.4
Target20.8
Herbie8.8
\[\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 < -8.687420785654022e+64

    1. Initial program 56.4

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Initial simplification56.4

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    6. Simplified3.7

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

    if -8.687420785654022e+64 < b < -2.4136707020362904e-185

    1. Initial program 36.2

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Initial simplification36.2

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

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

      \[\leadsto \color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)} \cdot \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}{\left(-b\right) + \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}} \cdot \frac{1}{2 \cdot a}\]
    7. Applied associate-*l/36.4

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

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

    if -2.4136707020362904e-185 < b < 1.5687409701741605e+116

    1. Initial program 10.6

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

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

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

    if 1.5687409701741605e+116 < b

    1. Initial program 49.5

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    4. Simplified3.0

      \[\leadsto \color{blue}{\frac{-b}{a}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification8.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -8.687420785654022 \cdot 10^{+64}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -2.4136707020362904 \cdot 10^{-185}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot a\right) \cdot c}{2 \cdot a}}{\left(-b\right) + \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}}\\ \mathbf{elif}\;b \le 1.5687409701741605 \cdot 10^{+116}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Runtime

Time bar (total: 42.1s)Debug logProfile

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