Average Error: 33.0 → 9.3
Time: 34.0s
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 -5.798380311898068 \cdot 10^{+56}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -1.8457662875705005 \cdot 10^{-81}:\\ \;\;\;\;\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 -3.566930431549089 \cdot 10^{-112}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 4.353512703078241 \cdot 10^{+76}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \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

Original33.0
Target20.4
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 < -5.798380311898068e+56 or -1.8457662875705005e-81 < b < -3.566930431549089e-112

    1. Initial program 54.7

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    4. Simplified6.3

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

    if -5.798380311898068e+56 < b < -1.8457662875705005e-81

    1. Initial program 40.1

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Initial simplification40.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 flip--40.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/43.2

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

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

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

      \[\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 -3.566930431549089e-112 < b < 4.353512703078241e+76

    1. Initial program 12.0

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

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

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

    if 4.353512703078241e+76 < b

    1. Initial program 38.9

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

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

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

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

      \[\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. Taylor expanded around 0 4.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -5.798380311898068 \cdot 10^{+56}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -1.8457662875705005 \cdot 10^{-81}:\\ \;\;\;\;\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 -3.566930431549089 \cdot 10^{-112}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 4.353512703078241 \cdot 10^{+76}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}\]

Runtime

Time bar (total: 34.0s)Debug logProfile

BaselineHerbieOracleSpan%
Regimes32.09.35.526.585.7%
herbie shell --seed 2018355 
(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)))