Average Error: 32.9 → 9.3
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 -1.1058513712164536 \cdot 10^{+149}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{if}\;b \le -5.496700305081621 \cdot 10^{-102}:\\ \;\;\;\;\frac{\frac{\left(c \cdot a\right) \cdot 4}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{a \cdot 2}\\ \mathbf{if}\;b \le 6.008237338849469 \cdot 10^{+153}:\\ \;\;\;\;\frac{-b}{a \cdot 2} - \frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \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

Original32.9
Target19.9
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 < -1.1058513712164536e+149

    1. Initial program 62.5

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

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

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

    if -1.1058513712164536e+149 < b < -5.496700305081621e-102

    1. Initial program 42.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--42.0

      \[\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 simplify13.7

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

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

    if -5.496700305081621e-102 < b < 6.008237338849469e+153

    1. Initial program 11.4

      \[\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-sub11.4

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

    if 6.008237338849469e+153 < b

    1. Initial program 60.8

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

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}{2 \cdot a}\]
    3. Applied simplify2.2

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -1.1058513712164536 \cdot 10^{+149}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{if}\;b \le -5.496700305081621 \cdot 10^{-102}:\\ \;\;\;\;\frac{\frac{\left(c \cdot a\right) \cdot 4}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{a \cdot 2}\\ \mathbf{if}\;b \le 6.008237338849469 \cdot 10^{+153}:\\ \;\;\;\;\frac{-b}{a \cdot 2} - \frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}}\]

Runtime

Time bar (total: 2.7m)Debug logProfile

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