Average Error: 33.4 → 9.3
Time: 41.8s
Precision: 64
Internal Precision: 128
\[\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 -0.9292673416568248:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -8.910960457072908 \cdot 10^{-112}:\\ \;\;\;\;\frac{\frac{4 \cdot \left(c \cdot a\right)}{a \cdot 2}}{\sqrt{a \cdot \left(-4 \cdot c\right) + b \cdot b} - b}\\ \mathbf{elif}\;b \le -4.5114751320494853 \cdot 10^{-150}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 2.8245841850260827 \cdot 10^{+142}:\\ \;\;\;\;\frac{-b}{a \cdot 2} - \frac{\sqrt{b \cdot b + \left(c \cdot a\right) \cdot -4}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a \cdot 2} - \left(\frac{b}{a} \cdot \frac{1}{2} - \frac{c}{b}\right)\\ \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.6
Herbie9.3
\[\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 < -0.9292673416568248 or -8.910960457072908e-112 < b < -4.5114751320494853e-150

    1. Initial program 53.2

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

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

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

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

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

    if -0.9292673416568248 < b < -8.910960457072908e-112

    1. Initial program 34.8

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

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

      \[\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}\]
    5. Applied associate-/l/38.4

      \[\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(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}\right)}}\]
    6. Simplified19.8

      \[\leadsto \frac{\color{blue}{4 \cdot \left(a \cdot c\right)}}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}\right)}\]
    7. Using strategy rm
    8. Applied associate-/r*14.9

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

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

    if -4.5114751320494853e-150 < b < 2.8245841850260827e+142

    1. Initial program 10.5

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

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

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

    if 2.8245841850260827e+142 < b

    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 + -4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    3. Using strategy rm
    4. Applied div-sub56.4

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

      \[\leadsto \frac{-b}{2 \cdot a} - \color{blue}{\left(\frac{1}{2} \cdot \frac{b}{a} - \frac{c}{b}\right)}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification9.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -0.9292673416568248:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -8.910960457072908 \cdot 10^{-112}:\\ \;\;\;\;\frac{\frac{4 \cdot \left(c \cdot a\right)}{a \cdot 2}}{\sqrt{a \cdot \left(-4 \cdot c\right) + b \cdot b} - b}\\ \mathbf{elif}\;b \le -4.5114751320494853 \cdot 10^{-150}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 2.8245841850260827 \cdot 10^{+142}:\\ \;\;\;\;\frac{-b}{a \cdot 2} - \frac{\sqrt{b \cdot b + \left(c \cdot a\right) \cdot -4}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a \cdot 2} - \left(\frac{b}{a} \cdot \frac{1}{2} - \frac{c}{b}\right)\\ \end{array}\]

Runtime

Time bar (total: 41.8s)Debug logProfile

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