Average Error: 33.0 → 9.5
Time: 2.5m
Precision: 64
Internal Precision: 3200
\[\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 -6.192751456905388 \cdot 10^{-56}:\\ \;\;\;\;\frac{\frac{\frac{4}{1}}{2} \cdot c}{(a \cdot \left(\frac{c + c}{b}\right) + \left(\left(-b\right) - b\right))_*}\\ \mathbf{if}\;-b \le 5.212416467940643 \cdot 10^{+55}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.0
Target19.8
Herbie9.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 3 regimes
  2. if (- b) < -6.192751456905388e-56

    1. Initial program 53.8

      \[\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-+53.9

      \[\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 simplify24.7

      \[\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}\]
    5. Taylor expanded around inf 18.4

      \[\leadsto \frac{\frac{\left(c \cdot a\right) \cdot 4}{\left(-b\right) - \color{blue}{\left(b - 2 \cdot \frac{c \cdot a}{b}\right)}}}{2 \cdot a}\]
    6. Applied simplify7.7

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

    if -6.192751456905388e-56 < (- b) < 5.212416467940643e+55

    1. Initial program 12.9

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

      \[\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 5.212416467940643e+55 < (- b)

    1. Initial program 36.5

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

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

      \[\leadsto \color{blue}{\frac{-b}{a}}\]
  3. Recombined 3 regimes into one program.

Runtime

Time bar (total: 2.5m)Debug logProfile

herbie shell --seed '#(1070355188 2193211668 3977393919 3454156579 3755371326 1656365382)' +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)))