Average Error: 33.2 → 22.8
Time: 31.9s
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 1.4625177337647182 \cdot 10^{-163}:\\ \;\;\;\;(b \cdot \left(\frac{\frac{-1}{2}}{a}\right) + \left(\frac{\sqrt{(a \cdot \left(-4 \cdot c\right) + \left(b \cdot b\right))_*}}{\frac{a}{\frac{1}{2}}}\right))_*\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-4 \cdot a\right) \cdot c}{\left(a \cdot 2\right) \cdot \left(\sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*} + b\right)}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.2
Target20.1
Herbie22.8
\[\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 2 regimes
  2. if b < 1.4625177337647182e-163

    1. Initial program 20.5

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

      \[\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-sub20.5

      \[\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}}\]
    5. Using strategy rm
    6. Applied div-inv20.5

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

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

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

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

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

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

    if 1.4625177337647182e-163 < b

    1. Initial program 48.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Initial simplification48.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 flip--48.6

      \[\leadsto \frac{\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}}}{2 \cdot a}\]
    5. Applied associate-/l/50.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}{\left(2 \cdot a\right) \cdot \left(\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} + b\right)}}\]
    6. Simplified25.7

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

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

Runtime

Time bar (total: 31.9s)Debug logProfile

BaselineHerbieOracleSpan%
Regimes33.722.821.811.991.1%
herbie shell --seed 2018295 +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)))