Average Error: 33.8 → 8.8
Time: 2.8m
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.9979183584340477 \cdot 10^{+120}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{if}\;b \le 1.021266047469986 \cdot 10^{-281}:\\ \;\;\;\;\frac{1}{2 \cdot a} \cdot \left(\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b\right)\\ \mathbf{if}\;b \le 3.7208207919097225 \cdot 10^{+36}:\\ \;\;\;\;\frac{\frac{\left(-c\right) \cdot \left(4 \cdot a\right)}{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} + b}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \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
Herbie8.8
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \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.9979183584340477e+120

    1. Initial program 50.2

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    4. Applied simplify2.7

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

    if -1.9979183584340477e+120 < b < 1.021266047469986e-281

    1. Initial program 9.4

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

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

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

    if 1.021266047469986e-281 < b < 3.7208207919097225e+36

    1. Initial program 29.9

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

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

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

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

    if 3.7208207919097225e+36 < b

    1. Initial program 56.3

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Applied simplify56.3

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

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -1.9979183584340477 \cdot 10^{+120}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{if}\;b \le 1.021266047469986 \cdot 10^{-281}:\\ \;\;\;\;\frac{1}{2 \cdot a} \cdot \left(\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b\right)\\ \mathbf{if}\;b \le 3.7208207919097225 \cdot 10^{+36}:\\ \;\;\;\;\frac{\frac{\left(-c\right) \cdot \left(4 \cdot a\right)}{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} + b}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 2.8m)Debug logProfile

herbie shell --seed 2020178 
(FPCore (a b c)
  :name "quadp (p42, positive)"

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

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