Average Error: 33.4 → 12.9
Time: 1.9m
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 -3.5190623530971513 \cdot 10^{-242}:\\ \;\;\;\;\frac{\frac{1}{2}}{a} \cdot \left(\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*} - b\right)\\ \mathbf{if}\;b \le 5.136864675556751 \cdot 10^{+72}:\\ \;\;\;\;\frac{\frac{c}{\frac{-1}{2}}}{\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*} + b}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2 \cdot c}{b + b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.4
Target20.5
Herbie12.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 3 regimes
  2. if b < -3.5190623530971513e-242

    1. Initial program 21.6

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

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

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

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

    if -3.5190623530971513e-242 < b < 5.136864675556751e+72

    1. Initial program 28.9

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

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

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

      \[\leadsto \left(\sqrt{(c \cdot \left(-4 \cdot a\right) + \left(b \cdot b\right))_*} - b\right) \cdot \color{blue}{\frac{\frac{1}{2}}{a}}\]
    6. Using strategy rm
    7. Applied flip--29.0

      \[\leadsto \color{blue}{\frac{\sqrt{(c \cdot \left(-4 \cdot a\right) + \left(b \cdot b\right))_*} \cdot \sqrt{(c \cdot \left(-4 \cdot a\right) + \left(b \cdot b\right))_*} - b \cdot b}{\sqrt{(c \cdot \left(-4 \cdot a\right) + \left(b \cdot b\right))_*} + b}} \cdot \frac{\frac{1}{2}}{a}\]
    8. Applied associate-*l/29.1

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

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

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

      \[\leadsto \frac{\color{blue}{{\left(\frac{\frac{1}{2}}{a}\right)}^{1}} \cdot {\left(\left(c \cdot a\right) \cdot -4\right)}^{1}}{\sqrt{(c \cdot \left(-4 \cdot a\right) + \left(b \cdot b\right))_*} + b}\]
    13. Applied pow-prod-down16.2

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

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

    if 5.136864675556751e+72 < b

    1. Initial program 57.5

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

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

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

      \[\leadsto \left(\sqrt{(c \cdot \left(-4 \cdot a\right) + \left(b \cdot b\right))_*} - b\right) \cdot \color{blue}{\frac{\frac{1}{2}}{a}}\]
    6. Using strategy rm
    7. Applied flip--57.6

      \[\leadsto \color{blue}{\frac{\sqrt{(c \cdot \left(-4 \cdot a\right) + \left(b \cdot b\right))_*} \cdot \sqrt{(c \cdot \left(-4 \cdot a\right) + \left(b \cdot b\right))_*} - b \cdot b}{\sqrt{(c \cdot \left(-4 \cdot a\right) + \left(b \cdot b\right))_*} + b}} \cdot \frac{\frac{1}{2}}{a}\]
    8. Applied associate-*l/57.6

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

      \[\leadsto \frac{\color{blue}{\frac{\frac{1}{2}}{a} \cdot \left(\left(c \cdot a\right) \cdot -4\right)}}{\sqrt{(c \cdot \left(-4 \cdot a\right) + \left(b \cdot b\right))_*} + b}\]
    10. Taylor expanded around 0 7.7

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

      \[\leadsto \color{blue}{\frac{-2 \cdot c}{b + b}}\]
  3. Recombined 3 regimes into one program.
  4. Applied simplify12.9

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -3.5190623530971513 \cdot 10^{-242}:\\ \;\;\;\;\frac{\frac{1}{2}}{a} \cdot \left(\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*} - b\right)\\ \mathbf{if}\;b \le 5.136864675556751 \cdot 10^{+72}:\\ \;\;\;\;\frac{\frac{c}{\frac{-1}{2}}}{\sqrt{(c \cdot \left(a \cdot -4\right) + \left(b \cdot b\right))_*} + b}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2 \cdot c}{b + b}\\ \end{array}}\]

Runtime

Time bar (total: 1.9m)Debug logProfile

herbie shell --seed '#(1070991898 1055468627 4280279443 640792587 928206309 3646738750)' +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)))