Average Error: 33.3 → 7.2
Time: 2.6m
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 -1.3026234282048264 \cdot 10^{+154}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{if}\;b \le 2.9009672808283745 \cdot 10^{-123}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{2 \cdot a}\\ \mathbf{if}\;b \le 7.182266640601894 \cdot 10^{+134}:\\ \;\;\;\;\frac{-c}{\sqrt[3]{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + b}} \cdot \frac{\frac{4}{\sqrt[3]{\sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)} + b} \cdot \sqrt[3]{\sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)} + b}}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original33.3
Target21.0
Herbie7.2
\[\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 < -1.3026234282048264e+154

    1. Initial program 60.8

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

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

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

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

    if -1.3026234282048264e+154 < b < 2.9009672808283745e-123

    1. Initial program 11.4

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

    if 2.9009672808283745e-123 < b < 7.182266640601894e+134

    1. Initial program 40.9

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

      \[\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--41.1

      \[\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 simplify14.8

      \[\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 add-cube-cbrt15.4

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

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

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

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

    if 7.182266640601894e+134 < b

    1. Initial program 61.0

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

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

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -1.3026234282048264 \cdot 10^{+154}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{if}\;b \le 2.9009672808283745 \cdot 10^{-123}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{2 \cdot a}\\ \mathbf{if}\;b \le 7.182266640601894 \cdot 10^{+134}:\\ \;\;\;\;\frac{-c}{\sqrt[3]{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + b}} \cdot \frac{\frac{4}{\sqrt[3]{\sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)} + b} \cdot \sqrt[3]{\sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)} + b}}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 2.6m)Debug logProfile

herbie shell --seed '#(1072936661 1621281212 3440817831 3219514234 460296804 1258167384)' 
(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)))