Average Error: 33.2 → 6.4
Time: 3.1m
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.4774007183366623 \cdot 10^{+126}:\\ \;\;\;\;\frac{c}{b} - \frac{b + b}{2 \cdot a}\\ \mathbf{if}\;b \le 1.63884623983986 \cdot 10^{-310}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} - b}{2 \cdot a}\\ \mathbf{if}\;b \le 1.8818205913123887 \cdot 10^{+75}:\\ \;\;\;\;\frac{1}{\left(\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} + b\right) \cdot \frac{\frac{2}{c}}{-4}}\\ \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.2
Target20.4
Herbie6.4
\[\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.4774007183366623e+126

    1. Initial program 50.6

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

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

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

      \[\leadsto \color{blue}{\frac{c}{b} \cdot 1 - \frac{b + b}{2 \cdot a}}\]

    if -1.4774007183366623e+126 < b < 1.63884623983986e-310

    1. Initial program 8.9

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

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

    if 1.63884623983986e-310 < b < 1.8818205913123887e+75

    1. Initial program 29.1

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

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

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

      \[\leadsto \frac{\frac{\color{blue}{\left(-4\right) \cdot \left(c \cdot a\right)}}{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} + b}}{2 \cdot a}\]
    6. Using strategy rm
    7. Applied clear-num15.8

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

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

    if 1.8818205913123887e+75 < b

    1. Initial program 57.9

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

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

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -1.4774007183366623 \cdot 10^{+126}:\\ \;\;\;\;\frac{c}{b} - \frac{b + b}{2 \cdot a}\\ \mathbf{if}\;b \le 1.63884623983986 \cdot 10^{-310}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} - b}{2 \cdot a}\\ \mathbf{if}\;b \le 1.8818205913123887 \cdot 10^{+75}:\\ \;\;\;\;\frac{1}{\left(\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} + b\right) \cdot \frac{\frac{2}{c}}{-4}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 3.1m)Debug logProfile

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