Average Error: 33.9 → 10.7
Time: 3.8m
Precision: 64
Internal Precision: 3392
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -7.623780782047697 \cdot 10^{+153}:\\ \;\;\;\;\frac{\frac{a}{\frac{b}{c}} - b}{a}\\ \mathbf{if}\;b \le 5.4809203653664925 \cdot 10^{-108}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}\\ \mathbf{if}\;b \le 6.844885804288013 \cdot 10^{-56}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{if}\;b \le 2.345202142130803 \cdot 10^{-14}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.9
Target21.0
Herbie10.7
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -7.623780782047697e+153

    1. Initial program 61.0

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied clear-num61.0

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} - b}}}\]
    5. Taylor expanded around -inf 10.3

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}}\]
    6. Applied simplify1.9

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

    if -7.623780782047697e+153 < b < 5.4809203653664925e-108

    1. Initial program 12.0

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied clear-num12.1

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

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

    if 5.4809203653664925e-108 < b < 6.844885804288013e-56 or 2.345202142130803e-14 < b

    1. Initial program 52.8

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

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

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

    if 6.844885804288013e-56 < b < 2.345202142130803e-14

    1. Initial program 38.1

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
  3. Recombined 4 regimes into one program.
  4. Applied simplify10.7

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -7.623780782047697 \cdot 10^{+153}:\\ \;\;\;\;\frac{\frac{a}{\frac{b}{c}} - b}{a}\\ \mathbf{if}\;b \le 5.4809203653664925 \cdot 10^{-108}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}\\ \mathbf{if}\;b \le 6.844885804288013 \cdot 10^{-56}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{if}\;b \le 2.345202142130803 \cdot 10^{-14}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 3.8m)Debug logProfile

herbie shell --seed '#(1939690843 327321720 555351923 2438475338 4053368242 4228276045)' 
(FPCore (a b c)
  :name "The quadratic formula (r1)"

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