Average Error: 34.0 → 9.6
Time: 59.2s
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 -5.874592666189354 \cdot 10^{+51}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -4.716248046325564 \cdot 10^{-77}:\\ \;\;\;\;\frac{\frac{\left(a \cdot 4\right) \cdot c}{a \cdot 2}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{elif}\;b \le -2.068510444224263 \cdot 10^{-85}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 1.04628164907388 \cdot 10^{+86}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \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

Original34.0
Target21.0
Herbie9.6
\[\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 < -5.874592666189354e+51 or -4.716248046325564e-77 < b < -2.068510444224263e-85

    1. Initial program 56.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-inv56.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 4.3

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    5. Simplified4.3

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

    if -5.874592666189354e+51 < b < -4.716248046325564e-77

    1. Initial program 43.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 div-inv43.1

      \[\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. Using strategy rm
    5. Applied flip--43.2

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

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

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

    if -2.068510444224263e-85 < b < 1.04628164907388e+86

    1. Initial program 13.5

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

    if 1.04628164907388e+86 < b

    1. Initial program 42.8

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    3. Simplified4.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -5.874592666189354 \cdot 10^{+51}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -4.716248046325564 \cdot 10^{-77}:\\ \;\;\;\;\frac{\frac{\left(a \cdot 4\right) \cdot c}{a \cdot 2}}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{elif}\;b \le -2.068510444224263 \cdot 10^{-85}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 1.04628164907388 \cdot 10^{+86}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}\]

Runtime

Time bar (total: 59.2s)Debug logProfile

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