Average Error: 33.5 → 10.0
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 -3.1121915926751862 \cdot 10^{+81}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{if}\;b \le -6.495235596303068 \cdot 10^{-31}:\\ \;\;\;\;\frac{\left(a \cdot c\right) \cdot 4}{\sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)} - b} \cdot \frac{1}{2 \cdot a}\\ \mathbf{if}\;b \le -5.2599359043084235 \cdot 10^{-101}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{if}\;b \le 6.045122565443192 \cdot 10^{+91}:\\ \;\;\;\;\frac{1}{2 \cdot a} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}\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

Original33.5
Target20.2
Herbie10.0
\[\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 < -3.1121915926751862e+81 or -6.495235596303068e-31 < b < -5.2599359043084235e-101

    1. Initial program 53.6

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

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

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

    if -3.1121915926751862e+81 < b < -6.495235596303068e-31

    1. Initial program 45.7

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

      \[\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. Using strategy rm
    5. Applied flip--45.8

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

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

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

    if -5.2599359043084235e-101 < b < 6.045122565443192e+91

    1. Initial program 11.8

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

      \[\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}}\]

    if 6.045122565443192e+91 < b

    1. Initial program 42.4

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

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -3.1121915926751862 \cdot 10^{+81}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{if}\;b \le -6.495235596303068 \cdot 10^{-31}:\\ \;\;\;\;\frac{\left(a \cdot c\right) \cdot 4}{\sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)} - b} \cdot \frac{1}{2 \cdot a}\\ \mathbf{if}\;b \le -5.2599359043084235 \cdot 10^{-101}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{if}\;b \le 6.045122565443192 \cdot 10^{+91}:\\ \;\;\;\;\frac{1}{2 \cdot a} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}}\]

Runtime

Time bar (total: 2.6m)Debug logProfile

herbie shell --seed 2018166 
(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)))