Average Error: 37.4 → 5.4
Time: 17.0s
Precision: 64
Internal precision: 2176
\[\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.0713433718164824 \cdot 10^{+85}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{if}\;b \le 6.611638496230363 \cdot 10^{-143}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}\\ \mathbf{if}\;b \le 2.353344202188118 \cdot 10^{-100}:\\ \;\;\;\;\frac{c}{b} \cdot \frac{-2}{2}\\ \mathbf{if}\;b \le 4.3383085193935005 \cdot 10^{-09}:\\ \;\;\;\;\frac{\frac{a \cdot \left(4 \cdot c\right)}{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}{2 \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

Original37.4
Comparison25.4
Herbie5.4
\[ \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 < -2.0713433718164824e+85

    1. Initial program 44.5

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

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

      \[\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 -2.0713433718164824e+85 < b < 6.611638496230363e-143

    1. Initial program 11.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 11.7

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

    if 6.611638496230363e-143 < b < 2.353344202188118e-100 or 4.3383085193935005e-09 < b

    1. Initial program 58.4

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

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

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

    if 2.353344202188118e-100 < b < 4.3383085193935005e-09

    1. Initial program 37.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-+ 37.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.2

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

Runtime

Time bar (total: 17.0s) Debug logProfile

Please include this information when filing a bug report:

herbie shell --seed '#(1067773715 2765207660 218871639 3688798924 2755544087 2054563380)'
(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)))