Average Error: 33.7 → 5.8
Time: 19.5s
Precision: 64
Internal precision: 2688
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -3.075239283784152 \cdot 10^{+132}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{if}\;b \le -4.983822085296594 \cdot 10^{-276}:\\ \;\;\;\;\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 7.666985785588564 \cdot 10^{+91}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{c \cdot 4}{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot 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

Original33.7
Comparison21.2
Herbie5.8
\[ \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 < -3.075239283784152e+132

    1. Initial program 53.4

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{c}{b}}{1} - \frac{b}{a}}\]
    5. Applied simplify 0.0

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

    if -3.075239283784152e+132 < b < -4.983822085296594e-276

    1. Initial program 8.4

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

      \[\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 -4.983822085296594e-276 < b < 7.666985785588564e+91

    1. Initial program 31.0

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

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

      \[\leadsto \frac{\frac{\color{blue}{a \cdot \left(4 \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 16.9

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

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

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

    if 7.666985785588564e+91 < b

    1. Initial program 59.0

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

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

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

Runtime

Time bar (total: 19.5s) Debug logProfile

Please include this information when filing a bug report:

herbie shell --seed '#(1066372953 114334025 411438303 1288252006 2962405338 2829794477)'
(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)))