Average Error: 33.1 → 9.9
Time: 2.0m
Precision: 64
Internal Precision: 3456
\[\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 -2.9518183431889837 \cdot 10^{-19}:\\ \;\;\;\;\frac{c}{b} \cdot \frac{-2}{2}\\ \mathbf{if}\;-b \le -1.03811770724071 \cdot 10^{-112}:\\ \;\;\;\;\frac{\frac{c \cdot \left(a \cdot 4\right)}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}{a \cdot 2}\\ \mathbf{if}\;-b \le -7.684966148341504 \cdot 10^{-133}:\\ \;\;\;\;\frac{c}{b} \cdot \frac{-2}{2}\\ \mathbf{if}\;-b \le 52.989744707118035:\\ \;\;\;\;\frac{1}{a \cdot 2} \cdot \left(\sqrt{(\left(a \cdot 4\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.1
Target20.3
Herbie9.9
\[\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) < -2.9518183431889837e-19 or -1.03811770724071e-112 < (- b) < -7.684966148341504e-133

    1. Initial program 53.8

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

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

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

    if -2.9518183431889837e-19 < (- b) < -1.03811770724071e-112

    1. Initial program 35.8

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

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

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

    if -7.684966148341504e-133 < (- b) < 52.989744707118035

    1. Initial program 12.3

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

      \[\leadsto \color{blue}{\frac{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied div-inv12.4

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

    if 52.989744707118035 < (- b)

    1. Initial program 29.7

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

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;-b \le -2.9518183431889837 \cdot 10^{-19}:\\ \;\;\;\;\frac{c}{b} \cdot \frac{-2}{2}\\ \mathbf{if}\;-b \le -1.03811770724071 \cdot 10^{-112}:\\ \;\;\;\;\frac{\frac{c \cdot \left(a \cdot 4\right)}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}{a \cdot 2}\\ \mathbf{if}\;-b \le -7.684966148341504 \cdot 10^{-133}:\\ \;\;\;\;\frac{c}{b} \cdot \frac{-2}{2}\\ \mathbf{if}\;-b \le 52.989744707118035:\\ \;\;\;\;\frac{1}{a \cdot 2} \cdot \left(\sqrt{(\left(a \cdot 4\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}}\]

Runtime

Time bar (total: 2.0m)Debug logProfile

herbie shell --seed '#(1070706311 3771791028 4128836681 4194990999 2341756049 504035650)' +o rules:numerics
(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)))