Average Error: 33.4 → 6.6
Time: 2.9m
Precision: 64
Internal Precision: 3456
\[\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.7635612098687 \cdot 10^{+72}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;-b \le -1.206225567686126 \cdot 10^{-254}:\\ \;\;\;\;\frac{1}{\left(\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} + b\right) \cdot \frac{\frac{-1}{2}}{c}}\\ \mathbf{if}\;-b \le 1.80809249792908 \cdot 10^{+139}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + \left(-b\right)}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b + b}{2 \cdot a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.4
Target20.5
Herbie6.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.7635612098687e+72

    1. Initial program 57.5

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

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

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

    if -7.7635612098687e+72 < (- b) < -1.206225567686126e-254

    1. Initial program 33.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-+33.3

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

      \[\leadsto \frac{\frac{\color{blue}{\left(c \cdot a\right) \cdot 4}}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied clear-num17.1

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

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

    if -1.206225567686126e-254 < (- b) < 1.80809249792908e+139

    1. Initial program 9.2

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

    if 1.80809249792908e+139 < (- b)

    1. Initial program 55.1

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

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

      \[\leadsto \color{blue}{\frac{\frac{c}{b}}{1} - \frac{b + b}{2 \cdot a}}\]
  3. Recombined 4 regimes into one program.
  4. Applied simplify6.6

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;-b \le -7.7635612098687 \cdot 10^{+72}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;-b \le -1.206225567686126 \cdot 10^{-254}:\\ \;\;\;\;\frac{1}{\left(\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} + b\right) \cdot \frac{\frac{-1}{2}}{c}}\\ \mathbf{if}\;-b \le 1.80809249792908 \cdot 10^{+139}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + \left(-b\right)}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b + b}{2 \cdot a}\\ \end{array}}\]

Runtime

Time bar (total: 2.9m)Debug logProfile

herbie shell --seed '#(1070991898 1055468627 4280279443 640792587 928206309 3646738750)' 
(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)))