Average Error: 34.4 → 5.6
Time: 1.2m
Precision: 64
Internal precision: 128
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -4.319226994044875 \cdot 10^{+67}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{if}\;b \le 3.4158607390551766 \cdot 10^{-208}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{if}\;b \le 1.0905893076356243 \cdot 10^{+100}:\\ \;\;\;\;\frac{1}{\left(\left(-b\right) - {\left(\sqrt{\sqrt{{b}^2 - \left(4 \cdot a\right) \cdot c}}\right)}^2\right) \cdot \frac{\frac{2}{4}}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \left(-b\right)}{a + a} - \frac{c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.4
Comparison22.2
Herbie5.6
\[ \begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \end{array} \]

Derivation

  1. Split input into 4 regimes.
  2. if b < -4.319226994044875e+67

    1. Initial program 43.2

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

      \[\leadsto -1 \cdot \frac{b}{a}\]
    3. Taylor expanded around -inf 0

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

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

    if -4.319226994044875e+67 < b < 3.4158607390551766e-208

    1. Initial program 11.1

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

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

    if 3.4158607390551766e-208 < b < 1.0905893076356243e+100

    1. Initial program 35.3

      \[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied flip-+ 35.4

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(\left(-b\right) - \sqrt{{b}^2 - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{\frac{2}{4}}{c}}}\]
    8. Using strategy rm
    9. Applied add-sqr-sqrt 7.9

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

    if 1.0905893076356243e+100 < b

    1. Initial program 58.9

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

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

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

      \[\leadsto \color{blue}{\frac{b + \left(-b\right)}{a + a} - \frac{c}{1 \cdot b}}\]
    5. Applied simplify 0

      \[\leadsto \frac{b + \left(-b\right)}{a + a} - \color{blue}{\frac{c}{b}}\]
  3. Recombined 4 regimes into one program.
  4. Removed slow pow expressions

Runtime

Time bar (total: 1.2m) Debug log

Please include this information when filing a bug report:

herbie --seed '#(1459318687 3783235169 3882486712 3306245629 1782328778 3817826396)'
(FPCore (a b c)
  :name "quadp (p42, positive)"

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

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