Average Error: 32.8 → 9.0
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}\;\left(-b\right) - b \le -1.4716501915070803 \cdot 10^{+80}:\\ \;\;\;\;\left(\sqrt[3]{\frac{4}{\frac{2}{c}}} \cdot \sqrt[3]{\frac{4}{\frac{2}{c}}}\right) \cdot \frac{\sqrt[3]{\frac{c}{\frac{2}{4}}}}{\left(-b\right) - b}\\ \mathbf{elif}\;\left(-b\right) - b \le -3.938044676036957 \cdot 10^{-164}:\\ \;\;\;\;\frac{\frac{\left(c \cdot 4\right) \cdot a}{2 \cdot a}}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\ \mathbf{elif}\;\left(-b\right) - b \le 1.1567840076216113 \cdot 10^{+56}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \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

Original32.8
Target20.3
Herbie9.0
\[\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) b) < -1.4716501915070803e+80

    1. Initial program 57.4

      \[\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-+57.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 associate-/l/58.0

      \[\leadsto \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(2 \cdot a\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}}\]
    5. Simplified30.9

      \[\leadsto \frac{\color{blue}{\left(c \cdot 4\right) \cdot a}}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}\]
    6. Using strategy rm
    7. Applied associate-/r*29.2

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

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

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

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

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

      \[\leadsto \left(\sqrt[3]{\frac{4}{\frac{2}{c}}} \cdot \sqrt[3]{\frac{4}{\frac{2}{c}}}\right) \cdot \color{blue}{\frac{\sqrt[3]{\frac{c}{\frac{2}{4}}}}{\left(-b\right) - \sqrt{(\left(-4\right) \cdot \left(a \cdot c\right) + \left(b \cdot b\right))_*}}}\]
    14. Taylor expanded around 0 4.1

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

    if -1.4716501915070803e+80 < (- (- b) b) < -3.938044676036957e-164

    1. Initial program 35.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 flip-+35.7

      \[\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 associate-/l/39.5

      \[\leadsto \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(2 \cdot a\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}}\]
    5. Simplified19.3

      \[\leadsto \frac{\color{blue}{\left(c \cdot 4\right) \cdot a}}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}\]
    6. Using strategy rm
    7. Applied associate-/r*14.0

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

    if -3.938044676036957e-164 < (- (- b) b) < 1.1567840076216113e+56

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

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

    if 1.1567840076216113e+56 < (- (- b) b)

    1. Initial program 36.2

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    3. Simplified5.6

      \[\leadsto \color{blue}{\frac{-b}{a}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification9.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(-b\right) - b \le -1.4716501915070803 \cdot 10^{+80}:\\ \;\;\;\;\left(\sqrt[3]{\frac{4}{\frac{2}{c}}} \cdot \sqrt[3]{\frac{4}{\frac{2}{c}}}\right) \cdot \frac{\sqrt[3]{\frac{c}{\frac{2}{4}}}}{\left(-b\right) - b}\\ \mathbf{elif}\;\left(-b\right) - b \le -3.938044676036957 \cdot 10^{-164}:\\ \;\;\;\;\frac{\frac{\left(c \cdot 4\right) \cdot a}{2 \cdot a}}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\ \mathbf{elif}\;\left(-b\right) - b \le 1.1567840076216113 \cdot 10^{+56}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}\]

Runtime

Time bar (total: 2.3m)Debug logProfile

herbie shell --seed 2018217 +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)))