Average Error: 33.5 → 15.3
Time: 36.9s
Precision: 64
Internal Precision: 128
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -7.944041631868353 \cdot 10^{-304}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.0307449119860003 \cdot 10^{+150}:\\ \;\;\;\;\left(c \cdot \frac{1}{2}\right) \cdot \frac{-4}{\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} + b}\\ \mathbf{else}:\\ \;\;\;\;\frac{-4 \cdot \left(a \cdot c\right)}{\left(a \cdot 2\right) \cdot \left(2 \cdot b\right)}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.5
Target20.7
Herbie15.3
\[\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 3 regimes
  2. if b < -7.944041631868353e-304

    1. Initial program 21.5

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

      \[\leadsto \frac{\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} - b}{2 \cdot a}\]
    3. Taylor expanded around -inf 21.5

      \[\leadsto \frac{\sqrt{\color{blue}{{b}^{2} - 4 \cdot \left(a \cdot c\right)}} - b}{2 \cdot a}\]
    4. Simplified21.5

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

    if -7.944041631868353e-304 < b < 2.0307449119860003e+150

    1. Initial program 34.2

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

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

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

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

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

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

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

    if 2.0307449119860003e+150 < b

    1. Initial program 62.5

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

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

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

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

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

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

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

Runtime

Time bar (total: 36.9s)Debug logProfile

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