Average Error: 33.2 → 13.0
Time: 3.0m
Precision: 64
Internal Precision: 3392
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;\frac{e^{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)}}{2 \cdot a} \le -7.800203871611098 \cdot 10^{+307}:\\ \;\;\;\;\frac{c}{-b}\\ \mathbf{if}\;\frac{e^{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)}}{2 \cdot a} \le -2.0061841269910144 \cdot 10^{-307}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}}\\ \mathbf{if}\;\frac{e^{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)}}{2 \cdot a} \le 5.715336273106866 \cdot 10^{-231}:\\ \;\;\;\;\frac{c}{-b}\\ \mathbf{if}\;\frac{e^{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b\right)}}{2 \cdot a} \le 1.6689973109210984 \cdot 10^{+307}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{-b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.2
Target20.4
Herbie13.0
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if (/ (exp (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (* 2 a)) < -7.800203871611098e+307 or -2.0061841269910144e-307 < (/ (exp (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (* 2 a)) < 5.715336273106866e-231 or 1.6689973109210984e+307 < (/ (exp (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (* 2 a))

    1. Initial program 58.3

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{-1 \cdot \frac{b}{c}}}\]
    9. Applied simplify21.7

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

    if -7.800203871611098e+307 < (/ (exp (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (* 2 a)) < -2.0061841269910144e-307 or 5.715336273106866e-231 < (/ (exp (log (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (* 2 a)) < 1.6689973109210984e+307

    1. Initial program 2.1

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

      \[\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 clear-num2.2

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

Runtime

Time bar (total: 3.0m)Debug logProfile

herbie shell --seed 2018199 +o rules:numerics
(FPCore (a b c)
  :name "quadp (p42, positive)"

  :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)))