Average Error: 34.0 → 6.4
Time: 1.9m
Precision: 64
Internal Precision: 3392
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -7.060089202421629 \cdot 10^{+125}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{if}\;b \le 5.94703430650783 \cdot 10^{-258}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{2 \cdot a}\\ \mathbf{if}\;b \le 9.143378368875635 \cdot 10^{+135}:\\ \;\;\;\;\left(-\frac{4}{2}\right) \cdot \frac{c}{b + \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-c}{2} \cdot \frac{4}{2}}{b - \frac{c}{\frac{b}{a}}}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.0
Target20.6
Herbie6.4
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -7.060089202421629e+125

    1. Initial program 52.3

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{2 \cdot a}}\]
    3. Taylor expanded around -inf 3.9

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    4. Applied simplify3.9

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

    if -7.060089202421629e+125 < b < 5.94703430650783e-258

    1. Initial program 9.4

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

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

    if 5.94703430650783e-258 < b < 9.143378368875635e+135

    1. Initial program 35.8

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

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

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

      \[\leadsto \frac{\frac{\color{blue}{\left(-4\right) \cdot \left(c \cdot a\right)}}{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} + b}}{2 \cdot a}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity15.1

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

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

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

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

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

    if 9.143378368875635e+135 < b

    1. Initial program 61.2

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

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

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

      \[\leadsto \frac{\frac{\color{blue}{\left(-4\right) \cdot \left(c \cdot a\right)}}{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} + b}}{2 \cdot a}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity35.1

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

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

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

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

      \[\leadsto \left(-\frac{4}{2}\right) \cdot \color{blue}{\frac{c}{b + \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}}\]
    12. Taylor expanded around inf 5.9

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

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

Runtime

Time bar (total: 1.9m)Debug logProfile

herbie shell --seed '#(1071979731 1496239409 439705970 2863295848 982327776 189749553)' 
(FPCore (a b c)
  :name "quadp (p42, positive)"

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

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