Average Error: 33.3 → 7.4
Time: 56.9s
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.3113335146564099 \cdot 10^{+63}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 1.1610232208714984 \cdot 10^{-305}:\\ \;\;\;\;\frac{\sqrt[3]{\frac{c}{\frac{1}{2}}}}{\sqrt{\sqrt{a \cdot \left(-4 \cdot c\right) + b \cdot b} - b}} \cdot \frac{\sqrt[3]{2 \cdot c} \cdot \sqrt[3]{2 \cdot c}}{\sqrt{\sqrt{\sqrt[3]{\left(-4 \cdot a\right) \cdot c + b \cdot b}} \cdot \left|\sqrt[3]{a \cdot \left(-4 \cdot c\right) + b \cdot b}\right| - b}}\\ \mathbf{elif}\;b \le 1.3071943870403567 \cdot 10^{+75}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - \left(c \cdot a\right) \cdot 4}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \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

Original33.3
Target20.9
Herbie7.4
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\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.3113335146564099e+63

    1. Initial program 57.2

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    3. Simplified3.7

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

    if -1.3113335146564099e+63 < b < 1.1610232208714984e-305

    1. Initial program 30.2

      \[\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--30.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 associate-/l/35.4

      \[\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. Simplified22.5

      \[\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*16.9

      \[\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. Simplified16.9

      \[\leadsto \frac{\frac{\left(c \cdot 4\right) \cdot a}{2 \cdot a}}{\color{blue}{\sqrt{-4 \cdot \left(a \cdot c\right) + b \cdot b} - b}}\]
    9. Using strategy rm
    10. Applied add-sqr-sqrt17.1

      \[\leadsto \frac{\frac{\left(c \cdot 4\right) \cdot a}{2 \cdot a}}{\color{blue}{\sqrt{\sqrt{-4 \cdot \left(a \cdot c\right) + b \cdot b} - b} \cdot \sqrt{\sqrt{-4 \cdot \left(a \cdot c\right) + b \cdot b} - b}}}\]
    11. Applied add-cube-cbrt17.7

      \[\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}}}}{\sqrt{\sqrt{-4 \cdot \left(a \cdot c\right) + b \cdot b} - b} \cdot \sqrt{\sqrt{-4 \cdot \left(a \cdot c\right) + b \cdot b} - b}}\]
    12. Applied times-frac17.7

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

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

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

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

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

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

    if 1.1610232208714984e-305 < b < 1.3071943870403567e+75

    1. Initial program 9.0

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

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

    if 1.3071943870403567e+75 < b

    1. Initial program 39.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.3113335146564099 \cdot 10^{+63}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 1.1610232208714984 \cdot 10^{-305}:\\ \;\;\;\;\frac{\sqrt[3]{\frac{c}{\frac{1}{2}}}}{\sqrt{\sqrt{a \cdot \left(-4 \cdot c\right) + b \cdot b} - b}} \cdot \frac{\sqrt[3]{2 \cdot c} \cdot \sqrt[3]{2 \cdot c}}{\sqrt{\sqrt{\sqrt[3]{\left(-4 \cdot a\right) \cdot c + b \cdot b}} \cdot \left|\sqrt[3]{a \cdot \left(-4 \cdot c\right) + b \cdot b}\right| - b}}\\ \mathbf{elif}\;b \le 1.3071943870403567 \cdot 10^{+75}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - \left(c \cdot a\right) \cdot 4}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Runtime

Time bar (total: 56.9s)Debug logProfile

BaselineHerbieOracleSpan%
Regimes30.37.45.724.593.4%
herbie shell --seed 2018263 
(FPCore (a b c)
  :name "The quadratic formula (r2)"

  :herbie-target
  (if (< b 0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))