Average Error: 34.5 → 5.6
Time: 1.1m
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 + \left(-b\right)}{a + a} - \frac{c}{b}\\ \mathbf{if}\;b \le 7.285691125792036 \cdot 10^{-223}:\\ \;\;\;\;\frac{4}{2} \cdot \frac{c}{\left(-b\right) + {\left(\sqrt{\sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}}\right)}^2}\\ \mathbf{if}\;b \le 1.0905893076356243 \cdot 10^{+100}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.5
Comparison21.9
Herbie5.6
\[ \begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\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 58.8

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

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

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

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

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

    if -4.319226994044875e+67 < b < 7.285691125792036e-223

    1. Initial program 28.1

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

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

      \[\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 *-un-lft-identity 17.3

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

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

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

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

      \[\leadsto \frac{4}{2} \cdot \color{blue}{\frac{c}{\left(-b\right) + \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}}}\]
    11. Using strategy rm
    12. Applied add-sqr-sqrt 11.0

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

    if 7.285691125792036e-223 < b < 1.0905893076356243e+100

    1. Initial program 8.0

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

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

    if 1.0905893076356243e+100 < b

    1. Initial program 45.1

      \[\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}}\]
  3. Recombined 4 regimes into one program.
  4. Removed slow pow expressions

Runtime

Time bar (total: 1.1m) Debug log

Please include this information when filing a bug report:

herbie --seed '#(1999171097 831851190 1290423800 1216071174 2948071701 1563903785)'
(FPCore (a b c)
  :name "quadm (p42, negative)"

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

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