Average Error: 33.7 → 8.9
Time: 59.7s
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 -3.078342506081658 \cdot 10^{+108}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \le 8.171464894339612 \cdot 10^{-202}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}\\ \mathbf{elif}\;b \le 6.595096142091074 \cdot 10^{+68}:\\ \;\;\;\;\frac{4}{a \cdot 2} \cdot \frac{c \cdot a}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{4}{2} \cdot c}{(c \cdot \left(\frac{a}{b}\right) + \left(-b\right))_* \cdot 2}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.7
Target20.5
Herbie8.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 < -3.078342506081658e+108

    1. Initial program 47.2

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    3. Simplified3.6

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

    if -3.078342506081658e+108 < b < 8.171464894339612e-202

    1. Initial program 9.9

      \[\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-num10.0

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

    if 8.171464894339612e-202 < b < 6.595096142091074e+68

    1. Initial program 34.9

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

      \[\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 associate-/l/38.9

      \[\leadsto \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(2 \cdot a\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    5. Simplified21.4

      \[\leadsto \frac{\color{blue}{4 \cdot \left(c \cdot a\right)}}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\]
    6. Using strategy rm
    7. Applied times-frac17.5

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

    if 6.595096142091074e+68 < b

    1. Initial program 57.4

      \[\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-+57.4

      \[\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 associate-/l/57.7

      \[\leadsto \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(2 \cdot a\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    5. Simplified29.7

      \[\leadsto \frac{\color{blue}{4 \cdot \left(c \cdot a\right)}}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\]
    6. Using strategy rm
    7. Applied times-frac29.9

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

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

      \[\leadsto \color{blue}{{\left(\frac{4}{2 \cdot a}\right)}^{1}} \cdot {\left(\frac{c \cdot a}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right)}^{1}\]
    11. Applied pow-prod-down29.9

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

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

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

      \[\leadsto {\left(\frac{\frac{c}{1} \cdot \frac{4}{2}}{\color{blue}{(c \cdot \left(\frac{a}{b}\right) + \left(-b\right))_* \cdot 2}}\right)}^{1}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification8.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.078342506081658 \cdot 10^{+108}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \le 8.171464894339612 \cdot 10^{-202}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}\\ \mathbf{elif}\;b \le 6.595096142091074 \cdot 10^{+68}:\\ \;\;\;\;\frac{4}{a \cdot 2} \cdot \frac{c \cdot a}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{4}{2} \cdot c}{(c \cdot \left(\frac{a}{b}\right) + \left(-b\right))_* \cdot 2}\\ \end{array}\]

Runtime

Time bar (total: 59.7s)Debug logProfile

herbie shell --seed 2018221 +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)))