Average Error: 33.7 → 13.5
Time: 2.4m
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{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b} \cdot \sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}}{2 \cdot a} \le -4.6198563120885677 \cdot 10^{+300}:\\ \;\;\;\;\frac{-4}{2} \cdot \frac{c}{b + b}\\ \mathbf{if}\;\frac{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b} \cdot \sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}}{2 \cdot a} \le -1.669199164394288 \cdot 10^{-308}:\\ \;\;\;\;\frac{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \mathbf{if}\;\frac{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b} \cdot \sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}}{2 \cdot a} \le 1.4583544321977194 \cdot 10^{-275}:\\ \;\;\;\;\frac{-4}{2} \cdot \frac{c}{b + b}\\ \mathbf{if}\;\frac{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b} \cdot \sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}}{2 \cdot a} \le 1.2661543501360125 \cdot 10^{+280}:\\ \;\;\;\;\frac{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-4}{2} \cdot \frac{c}{b + b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.7
Target21.0
Herbie13.5
\[\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 (/ (* (sqrt (- (sqrt (fma (* 4 a) (- c) (* b b))) b)) (sqrt (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (* 2 a)) < -4.6198563120885677e+300 or -1.669199164394288e-308 < (/ (* (sqrt (- (sqrt (fma (* 4 a) (- c) (* b b))) b)) (sqrt (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (* 2 a)) < 1.4583544321977194e-275 or 1.2661543501360125e+280 < (/ (* (sqrt (- (sqrt (fma (* 4 a) (- c) (* b b))) b)) (sqrt (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (* 2 a))

    1. Initial program 58.6

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

      \[\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--59.6

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

      \[\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 *-un-lft-identity40.0

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

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

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

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

      \[\leadsto \color{blue}{\frac{-4}{2} \cdot \frac{c}{b + b}}\]

    if -4.6198563120885677e+300 < (/ (* (sqrt (- (sqrt (fma (* 4 a) (- c) (* b b))) b)) (sqrt (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (* 2 a)) < -1.669199164394288e-308 or 1.4583544321977194e-275 < (/ (* (sqrt (- (sqrt (fma (* 4 a) (- c) (* b b))) b)) (sqrt (- (sqrt (fma (* 4 a) (- c) (* b b))) b))) (* 2 a)) < 1.2661543501360125e+280

    1. Initial program 2.2

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

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

Runtime

Time bar (total: 2.4m)Debug logProfile

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