Average Error: 34.0 → 13.4
Time: 31.0s
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.7412060648765384 \cdot 10^{+90}:\\ \;\;\;\;\frac{-2 \cdot \frac{a \cdot c}{b}}{a \cdot 2}\\ \mathbf{elif}\;b \le -2.9108748169166987 \cdot 10^{-67}:\\ \;\;\;\;\frac{4 \cdot \left(a \cdot c\right)}{\left(a \cdot 2\right) \cdot \left(\sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)} + \left(-b\right)\right)}\\ \mathbf{elif}\;b \le -2.600632313007493 \cdot 10^{-91}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{-2 \cdot \frac{a \cdot c}{b}}}\\ \mathbf{elif}\;b \le 2.1153853257639953 \cdot 10^{+45}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\left(-b\right) - \sqrt{\left(a \cdot -4\right) \cdot c + b \cdot b}}{a}\\ \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.3
Herbie13.4
\[\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 5 regimes
  2. if b < -1.7412060648765384e+90

    1. Initial program 58.2

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

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

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

    if -1.7412060648765384e+90 < b < -2.9108748169166987e-67

    1. Initial program 44.0

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

      \[\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--44.1

      \[\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/47.1

      \[\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. Simplified17.2

      \[\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)}\]

    if -2.9108748169166987e-67 < b < -2.600632313007493e-91

    1. Initial program 31.3

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

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

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

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

    if -2.600632313007493e-91 < b < 2.1153853257639953e+45

    1. Initial program 14.1

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

      \[\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 add-sqr-sqrt14.1

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

      \[\leadsto \frac{\left(-b\right) - \color{blue}{\sqrt{\sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}} \cdot \sqrt{\sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity14.3

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

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

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

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

    if 2.1153853257639953e+45 < b

    1. Initial program 36.0

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    4. Simplified5.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.7412060648765384 \cdot 10^{+90}:\\ \;\;\;\;\frac{-2 \cdot \frac{a \cdot c}{b}}{a \cdot 2}\\ \mathbf{elif}\;b \le -2.9108748169166987 \cdot 10^{-67}:\\ \;\;\;\;\frac{4 \cdot \left(a \cdot c\right)}{\left(a \cdot 2\right) \cdot \left(\sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)} + \left(-b\right)\right)}\\ \mathbf{elif}\;b \le -2.600632313007493 \cdot 10^{-91}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{-2 \cdot \frac{a \cdot c}{b}}}\\ \mathbf{elif}\;b \le 2.1153853257639953 \cdot 10^{+45}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\left(-b\right) - \sqrt{\left(a \cdot -4\right) \cdot c + b \cdot b}}{a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}\]

Runtime

Time bar (total: 31.0s)Debug logProfile

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