Average Error: 33.4 → 8.9
Time: 1.9m
Precision: 64
Internal Precision: 3456
\[\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 -57.05332371598462:\\ \;\;\;\;\frac{-2}{2} \cdot \frac{c}{b}\\ \mathbf{if}\;-b \le -6.041090339021061 \cdot 10^{-192}:\\ \;\;\;\;\frac{\frac{\left(c \cdot a\right) \cdot 4}{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}}{a + a}\\ \mathbf{if}\;-b \le 1.5285447525713952 \cdot 10^{+127}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + \left(-b\right)\right) \cdot \frac{1}{a + a}\\ \mathbf{else}:\\ \;\;\;\;\frac{(\left(\frac{a}{b}\right) \cdot c + \left(-b\right))_*}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.4
Target20.7
Herbie8.9
\[\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 (- b) < -57.05332371598462

    1. Initial program 55.3

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

      \[\leadsto \frac{\color{blue}{-2 \cdot \frac{c \cdot a}{b}}}{2 \cdot a}\]
    3. Applied simplify6.1

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

    if -57.05332371598462 < (- b) < -6.041090339021061e-192

    1. Initial program 31.0

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

      \[\leadsto \frac{\color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
    4. Applied simplify18.3

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

    if -6.041090339021061e-192 < (- b) < 1.5285447525713952e+127

    1. Initial program 9.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied div-inv9.8

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

    if 1.5285447525713952e+127 < (- b)

    1. Initial program 52.7

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

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;-b \le -57.05332371598462:\\ \;\;\;\;\frac{-2}{2} \cdot \frac{c}{b}\\ \mathbf{if}\;-b \le -6.041090339021061 \cdot 10^{-192}:\\ \;\;\;\;\frac{\frac{\left(c \cdot a\right) \cdot 4}{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}}{a + a}\\ \mathbf{if}\;-b \le 1.5285447525713952 \cdot 10^{+127}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + \left(-b\right)\right) \cdot \frac{1}{a + a}\\ \mathbf{else}:\\ \;\;\;\;\frac{(\left(\frac{a}{b}\right) \cdot c + \left(-b\right))_*}{a}\\ \end{array}}\]

Runtime

Time bar (total: 1.9m)Debug logProfile

herbie shell --seed '#(1064300848 3212030778 2049303162 3567222883 2277747821 1384278011)' +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)))