Average Error: 33.9 → 6.6
Time: 2.0m
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 -8.013722784565075 \cdot 10^{+72}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{if}\;-b \le 6.6023739187105 \cdot 10^{-235}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}\right) \cdot \frac{\frac{1}{2}}{a}\\ \mathbf{if}\;-b \le 4.416258706655503 \cdot 10^{+147}:\\ \;\;\;\;\frac{1}{\left(\sqrt{\left(c \cdot a\right) \cdot -4 + b \cdot b} - b\right) \cdot \frac{\frac{1}{2}}{c}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.9
Target20.7
Herbie6.6
\[\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) < -8.013722784565075e+72

    1. Initial program 40.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.8

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

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

    if -8.013722784565075e+72 < (- b) < 6.6023739187105e-235

    1. Initial program 10.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 div-inv10.3

      \[\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. Applied simplify10.2

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

    if 6.6023739187105e-235 < (- b) < 4.416258706655503e+147

    1. Initial program 37.1

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

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

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

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

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

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

    if 4.416258706655503e+147 < (- b)

    1. Initial program 62.1

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

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;-b \le -8.013722784565075 \cdot 10^{+72}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{if}\;-b \le 6.6023739187105 \cdot 10^{-235}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}\right) \cdot \frac{\frac{1}{2}}{a}\\ \mathbf{if}\;-b \le 4.416258706655503 \cdot 10^{+147}:\\ \;\;\;\;\frac{1}{\left(\sqrt{\left(c \cdot a\right) \cdot -4 + b \cdot b} - b\right) \cdot \frac{\frac{1}{2}}{c}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 2.0m)Debug logProfile

herbie shell --seed '#(1070991898 1055468627 4280279443 640792587 928206309 3646738750)' 
(FPCore (a b c)
  :name "quadm (p42, negative)"

  :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)))