Average Error: 34.0 → 16.5
Time: 2.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{\frac{1}{2} \cdot \frac{4 \cdot \left(-c\right)}{\sqrt{b + b}}}{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} + b}} \le -0.0007389234522954333:\\ \;\;\;\;\frac{\frac{c \cdot a}{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} + b}} \cdot \frac{-4}{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} + b}}}{2 \cdot a}\\ \mathbf{if}\;\frac{\frac{1}{2} \cdot \frac{4 \cdot \left(-c\right)}{\sqrt{b + b}}}{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} + b}} \le -2.1529323537263655 \cdot 10^{-308}:\\ \;\;\;\;\log_* (1 + (e^{\frac{\left(4 \cdot \left(-c\right)\right) \cdot \frac{1}{2}}{\sqrt{(\left(-c\right) \cdot \left(4 \cdot a\right) + \left(b \cdot b\right))_*} + b}} - 1)^*)\\ \mathbf{if}\;\frac{\frac{1}{2} \cdot \frac{4 \cdot \left(-c\right)}{\sqrt{b + b}}}{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} + b}} \le 8.343038122310654 \cdot 10^{-264}:\\ \;\;\;\;\frac{\frac{\left(c \cdot a\right) \cdot \left(-4\right)}{b + b}}{2 \cdot a}\\ \mathbf{if}\;\frac{\frac{1}{2} \cdot \frac{4 \cdot \left(-c\right)}{\sqrt{b + b}}}{\sqrt{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} + b}} \le 7.433324767498321 \cdot 10^{+28}:\\ \;\;\;\;\log_* (1 + (e^{\frac{\left(4 \cdot \left(-c\right)\right) \cdot \frac{1}{2}}{\sqrt{(\left(-c\right) \cdot \left(4 \cdot a\right) + \left(b \cdot b\right))_*} + b}} - 1)^*)\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.0
Target20.6
Herbie16.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 4 regimes
  2. if (/ (* (/ 1 2) (/ (* 4 (- c)) (sqrt (+ b b)))) (sqrt (+ (sqrt (fma (* 4 a) (- c) (* b b))) b))) < -0.0007389234522954333

    1. Initial program 23.3

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

      \[\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 simplify5.6

      \[\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 add-sqr-sqrt5.8

      \[\leadsto \frac{\frac{\left(c \cdot a\right) \cdot \left(-4\right)}{\color{blue}{\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}\]
    8. Applied times-frac5.8

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

    if -0.0007389234522954333 < (/ (* (/ 1 2) (/ (* 4 (- c)) (sqrt (+ b b)))) (sqrt (+ (sqrt (fma (* 4 a) (- c) (* b b))) b))) < -2.1529323537263655e-308 or 8.343038122310654e-264 < (/ (* (/ 1 2) (/ (* 4 (- c)) (sqrt (+ b b)))) (sqrt (+ (sqrt (fma (* 4 a) (- c) (* b b))) b))) < 7.433324767498321e+28

    1. Initial program 42.9

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

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

      \[\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 simplify15.9

      \[\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 log1p-expm1-u17.4

      \[\leadsto \color{blue}{\log_* (1 + (e^{\frac{\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}}{2 \cdot a}} - 1)^*)}\]
    8. Applied simplify4.2

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

    if -2.1529323537263655e-308 < (/ (* (/ 1 2) (/ (* 4 (- c)) (sqrt (+ b b)))) (sqrt (+ (sqrt (fma (* 4 a) (- c) (* b b))) b))) < 8.343038122310654e-264

    1. Initial program 57.4

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

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

      \[\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 simplify36.6

      \[\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. Taylor expanded around 0 17.3

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

    if 7.433324767498321e+28 < (/ (* (/ 1 2) (/ (* 4 (- c)) (sqrt (+ b b)))) (sqrt (+ (sqrt (fma (* 4 a) (- c) (* b b))) b)))

    1. Initial program 21.8

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

      \[\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 4 regimes into one program.

Runtime

Time bar (total: 2.0m)Debug logProfile

herbie shell --seed '#(1071979731 1496239409 439705970 2863295848 982327776 189749553)' +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)))