Average Error: 33.4 → 8.8
Time: 2.1m
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 -2.4116197049672324 \cdot 10^{+51}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;-b \le -2.14399979241458 \cdot 10^{-120}:\\ \;\;\;\;\sqrt[3]{\frac{1}{a \cdot 2}} \cdot \frac{\left(\left(-4\right) \cdot \left(a \cdot c\right)\right) \cdot \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right)}{\left(\sqrt[3]{a \cdot 2} \cdot \sqrt[3]{a \cdot 2}\right) \cdot \left(\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} + b\right)}\\ \mathbf{if}\;-b \le 2.3985390927549858 \cdot 10^{+87}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)} - b}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.4
Target20.5
Herbie8.8
\[\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) < -2.4116197049672324e+51

    1. Initial program 56.4

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

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

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

    if -2.4116197049672324e+51 < (- b) < -2.14399979241458e-120

    1. Initial program 39.6

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

      \[\leadsto \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}}\]
    4. Using strategy rm
    5. Applied add-cube-cbrt40.0

      \[\leadsto \left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \color{blue}{\left(\left(\sqrt[3]{\frac{1}{2 \cdot a}} \cdot \sqrt[3]{\frac{1}{2 \cdot a}}\right) \cdot \sqrt[3]{\frac{1}{2 \cdot a}}\right)}\]
    6. Applied associate-*r*40.0

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

      \[\leadsto \color{blue}{\left(\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \left(\sqrt[3]{\frac{1}{a \cdot 2}} \cdot \sqrt[3]{\frac{1}{a \cdot 2}}\right)\right)} \cdot \sqrt[3]{\frac{1}{2 \cdot a}}\]
    8. Using strategy rm
    9. Applied cbrt-div39.9

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

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

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

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

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

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

    if -2.14399979241458e-120 < (- b) < 2.3985390927549858e+87

    1. Initial program 11.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 clear-num11.4

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

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

    if 2.3985390927549858e+87 < (- b)

    1. Initial program 42.0

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    3. Applied simplify4.2

      \[\leadsto \color{blue}{\frac{-b}{a}}\]
  3. Recombined 4 regimes into one program.
  4. Applied simplify8.8

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;-b \le -2.4116197049672324 \cdot 10^{+51}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;-b \le -2.14399979241458 \cdot 10^{-120}:\\ \;\;\;\;\sqrt[3]{\frac{1}{a \cdot 2}} \cdot \frac{\left(\left(-4\right) \cdot \left(a \cdot c\right)\right) \cdot \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right)}{\left(\sqrt[3]{a \cdot 2} \cdot \sqrt[3]{a \cdot 2}\right) \cdot \left(\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} + b\right)}\\ \mathbf{if}\;-b \le 2.3985390927549858 \cdot 10^{+87}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)} - b}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}}\]

Runtime

Time bar (total: 2.1m)Debug logProfile

herbie shell --seed '#(1071948828 1180510430 2986424009 997076509 406109801 420189285)' 
(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)))