Average Error: 33.8 → 12.9
Time: 23.8s
Precision: 64
Internal Precision: 128
\[\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 4.749272592981165 \cdot 10^{-276}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}{2 \cdot a} - \frac{b}{2 \cdot a}\\ \mathbf{elif}\;b \le 5.2192804628009176 \cdot 10^{+129}:\\ \;\;\;\;\frac{c \cdot -2}{b + \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -2}{b + b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.8
Target20.6
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 < 4.749272592981165e-276

    1. Initial program 21.1

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Initial simplification21.1

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

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

    if 4.749272592981165e-276 < b < 5.2192804628009176e+129

    1. Initial program 35.6

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

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

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

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

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

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

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

    if 5.2192804628009176e+129 < b

    1. Initial program 60.5

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le 4.749272592981165 \cdot 10^{-276}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}{2 \cdot a} - \frac{b}{2 \cdot a}\\ \mathbf{elif}\;b \le 5.2192804628009176 \cdot 10^{+129}:\\ \;\;\;\;\frac{c \cdot -2}{b + \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -2}{b + b}\\ \end{array}\]

Runtime

Time bar (total: 23.8s)Debug logProfile

BaselineHerbieOracleSpan%
Regimes29.012.912.416.696.9%
herbie shell --seed 2018353 +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)))