Average Error: 33.6 → 6.5
Time: 2.3m
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 -5.955045875733722 \cdot 10^{+135}:\\ \;\;\;\;\frac{\frac{c}{2} \cdot \frac{4}{2}}{(a \cdot \left(\frac{c}{b}\right) + \left(-b\right))_*}\\ \mathbf{if}\;-b \le -2.8432650981668703 \cdot 10^{-263}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{c \cdot 4}{\left(-b\right) - \sqrt{(\left(c \cdot 4\right) \cdot \left(-a\right) + \left(b \cdot b\right))_*}}\\ \mathbf{if}\;-b \le 1.0453900460671028 \cdot 10^{+79}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot 4\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b + b}{a \cdot 2}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.6
Target20.9
Herbie6.5
\[\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) < -5.955045875733722e+135

    1. Initial program 61.5

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

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

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

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

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

      \[\leadsto \frac{1}{2} \cdot \color{blue}{\frac{c \cdot 4}{\left(-b\right) - \sqrt{(\left(c \cdot 4\right) \cdot \left(-a\right) + \left(b \cdot b\right))_*}}}\]
    9. Taylor expanded around inf 6.7

      \[\leadsto \frac{1}{2} \cdot \frac{c \cdot 4}{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}\]
    10. Applied simplify1.9

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

    if -5.955045875733722e+135 < (- b) < -2.8432650981668703e-263

    1. Initial program 35.3

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

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

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

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

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

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

    if -2.8432650981668703e-263 < (- b) < 1.0453900460671028e+79

    1. Initial program 9.7

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

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

    if 1.0453900460671028e+79 < (- b)

    1. Initial program 41.5

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

      \[\leadsto \frac{\left(-b\right) + \color{blue}{\left(2 \cdot \frac{c \cdot a}{b} - b\right)}}{2 \cdot a}\]
    3. Applied simplify4.5

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;-b \le -5.955045875733722 \cdot 10^{+135}:\\ \;\;\;\;\frac{\frac{c}{2} \cdot \frac{4}{2}}{(a \cdot \left(\frac{c}{b}\right) + \left(-b\right))_*}\\ \mathbf{if}\;-b \le -2.8432650981668703 \cdot 10^{-263}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{c \cdot 4}{\left(-b\right) - \sqrt{(\left(c \cdot 4\right) \cdot \left(-a\right) + \left(b \cdot b\right))_*}}\\ \mathbf{if}\;-b \le 1.0453900460671028 \cdot 10^{+79}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot 4\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b + b}{a \cdot 2}\\ \end{array}}\]

Runtime

Time bar (total: 2.3m)Debug logProfile

herbie shell --seed '#(1071119240 1686926585 3481876196 78132896 2080707795 3185793749)' +o rules:numerics
(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)))