Average Error: 33.7 → 6.7
Time: 47.0s
Precision: 64
Internal Precision: 3392
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -6.269787584020147 \cdot 10^{+84}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -6.950165815222384 \cdot 10^{-304}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.0156208709971131 \cdot 10^{+92}:\\ \;\;\;\;\frac{-2 \cdot c}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}\\ \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.7
Target20.6
Herbie6.7
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -6.269787584020147e+84

    1. Initial program 40.7

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

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

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

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

    if -6.269787584020147e+84 < b < -6.950165815222384e-304

    1. Initial program 8.7

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

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

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

    if -6.950165815222384e-304 < b < 1.0156208709971131e+92

    1. Initial program 32.2

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

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

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} \cdot \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b \cdot b}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}} \cdot \frac{1}{2 \cdot a}\]
    7. Applied associate-*l/32.4

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

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

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

    if 1.0156208709971131e+92 < b

    1. Initial program 58.6

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    6. Simplified2.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -6.269787584020147 \cdot 10^{+84}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -6.950165815222384 \cdot 10^{-304}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.0156208709971131 \cdot 10^{+92}:\\ \;\;\;\;\frac{-2 \cdot c}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Runtime

Time bar (total: 47.0s)Debug logProfile

BaselineHerbieOracleSpan%
Regimes29.46.75.723.795.7%
herbie shell --seed 2018274 
(FPCore (a b c)
  :name "The quadratic formula (r1)"

  :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)))