Average Error: 38.6 → 4.3
Time: 2.8m
Precision: 64
Internal Precision: 3200
\[\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 -6.539512710864403 \cdot 10^{+66}:\\ \;\;\;\;\frac{\frac{4 \cdot c}{\left(\left(-b\right) - b\right) + \frac{a}{b} \cdot \left(c + c\right)}}{2}\\ \mathbf{if}\;b \le -3.4571144459829794 \cdot 10^{-131}:\\ \;\;\;\;\frac{\left(-b\right) + b}{a + a} - \frac{c}{b}\\ \mathbf{if}\;b \le 3.1746500024866854 \cdot 10^{+75}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original38.6
Target26.8
Herbie4.3
\[\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 < -6.539512710864403e+66

    1. Initial program 58.3

      \[\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--58.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 simplify31.7

      \[\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. Taylor expanded around -inf 14.6

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

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

    if -6.539512710864403e+66 < b < -3.4571144459829794e-131

    1. Initial program 59.8

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

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

      \[\leadsto \color{blue}{\frac{\left(-b\right) + b}{a + a} - \frac{\frac{c}{b}}{1}}\]
    4. Applied simplify0

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

    if -3.4571144459829794e-131 < b < 3.1746500024866854e+75

    1. Initial program 11.1

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

    if 3.1746500024866854e+75 < b

    1. Initial program 41.9

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

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

      \[\leadsto \color{blue}{\frac{\frac{c}{b}}{1} - \frac{b}{a}}\]
    4. Applied simplify0.0

      \[\leadsto \color{blue}{\frac{c}{b}} - \frac{b}{a}\]
  3. Recombined 4 regimes into one program.
  4. Removed slow pow expressions.

Runtime

Time bar (total: 2.8m)Debug logProfile

herbie shell --seed '#(1062930989 876886121 3990119081 3032829768 3060892583 1929069376)' 
(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)))