Average Error: 32.9 → 9.6
Time: 1.8m
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.634208798105995 \cdot 10^{+111}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{if}\;b \le 1.830255897208847 \cdot 10^{-62}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} - b\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{if}\;b \le 7.254129679093779 \cdot 10^{+96}:\\ \;\;\;\;\frac{\frac{\left(-4\right) \cdot \left(c \cdot a\right)}{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} + b}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original32.9
Target19.7
Herbie9.6
\[\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.634208798105995e+111

    1. Initial program 46.4

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

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

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

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

    if -7.634208798105995e+111 < b < 1.830255897208847e-62

    1. Initial program 12.8

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Applied simplify12.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 div-inv12.9

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

    if 1.830255897208847e-62 < b < 7.254129679093779e+96

    1. Initial program 43.2

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Applied simplify43.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--43.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 simplify15.6

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

    if 7.254129679093779e+96 < b

    1. Initial program 58.5

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

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

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

      \[\leadsto \color{blue}{\frac{-c}{\frac{b}{1}}}\]
  3. Recombined 4 regimes into one program.
  4. Applied simplify9.6

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -7.634208798105995 \cdot 10^{+111}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{if}\;b \le 1.830255897208847 \cdot 10^{-62}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} - b\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{if}\;b \le 7.254129679093779 \cdot 10^{+96}:\\ \;\;\;\;\frac{\frac{\left(-4\right) \cdot \left(c \cdot a\right)}{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} + b}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 1.8m)Debug logProfile

herbie shell --seed '#(1071246582 2318319007 2683472949 3810440501 3233274817 2724848749)' 
(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)))