Average Error: 35.5 → 7.9
Time: 32.3s
Precision: 64
Internal precision: 2944
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -2.8335922143007058 \cdot 10^{+135}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{if}\;b \le 2.4971715086460685 \cdot 10^{-08}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)} + \left(-b\right)}{a + a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot \frac{-2}{2}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original35.5
Comparison23.3
Herbie7.9
\[ \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 3 regimes.
  2. if b < -2.8335922143007058e+135

    1. Initial program 54.7

      \[\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 -2.8335922143007058e+135 < b < 2.4971715086460685e-08

    1. Initial program 15.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 15.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}}\]
    4. Applied taylor 15.3

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

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

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

    if 2.4971715086460685e-08 < b

    1. Initial program 58.3

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

      \[\leadsto \frac{-2 \cdot \frac{c \cdot a}{b}}{2 \cdot a}\]
    3. Taylor expanded around inf 15.4

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

      \[\leadsto \color{blue}{\frac{c}{b} \cdot \frac{-2}{2}}\]
  3. Recombined 3 regimes into one program.
  4. Removed slow pow expressions

Runtime

Time bar (total: 32.3s) Debug log

Please include this information when filing a bug report:

herbie shell --seed '#(644180380 3784176976 401987740 22459203 1940947670 3323606534)'
(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)))