Average Error: 34.8 → 6.7
Time: 56.5s
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 -5.365468925333354 \cdot 10^{+120}:\\ \;\;\;\;\frac{\frac{c + c}{\frac{b}{a}} - \left(b - \left(-b\right)\right)}{a + a}\\ \mathbf{if}\;b \le -3.283746017650344 \cdot 10^{-287}:\\ \;\;\;\;\frac{1}{\left(2 \cdot a\right) \cdot \frac{1}{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}\\ \mathbf{if}\;b \le 2.9567149947595096 \cdot 10^{+19}:\\ \;\;\;\;\frac{\frac{4 \cdot \left(a \cdot c\right)}{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\\ \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.8
Comparison22.9
Herbie6.7
\[ \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 < -5.365468925333354e+120

    1. Initial program 51.2

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

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

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

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

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

    if -5.365468925333354e+120 < b < -3.283746017650344e-287

    1. Initial program 8.6

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}}\]
    4. Using strategy rm
    5. Applied div-inv 8.8

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

    if -3.283746017650344e-287 < b < 2.9567149947595096e+19

    1. Initial program 25.5

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

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

      \[\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}\]

    if 2.9567149947595096e+19 < b

    1. Initial program 57.9

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

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

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

      \[\leadsto \color{blue}{\frac{b + \left(-b\right)}{a + a} - 1 \cdot \frac{c}{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: 56.5s) Debug log

Please include this information when filing a bug report:

herbie shell --seed '#(2277612311 2645429965 1090895633 2857793080 2144184008 3989768357)'
(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)))