Average Error: 33.3 → 9.3
Time: 2.1m
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}\;b \le -1.3026234282048264 \cdot 10^{+154}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{if}\;b \le 5.56140200863305 \cdot 10^{-112}:\\ \;\;\;\;\frac{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}{a \cdot 2}\\ \mathbf{if}\;b \le 7.500840778510721 \cdot 10^{-26}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot c\right) \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.3
Target21.0
Herbie9.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 4 regimes
  2. if b < -1.3026234282048264e+154

    1. Initial program 60.8

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

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

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

    if -1.3026234282048264e+154 < b < 5.56140200863305e-112

    1. Initial program 11.7

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

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

    if 5.56140200863305e-112 < b < 7.500840778510721e-26

    1. Initial program 34.1

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

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

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

    if 7.500840778510721e-26 < b

    1. Initial program 53.9

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

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

      \[\leadsto \color{blue}{\frac{-c}{\frac{b}{1}}}\]
  3. Recombined 4 regimes into one program.
  4. Applied simplify9.3

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -1.3026234282048264 \cdot 10^{+154}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{if}\;b \le 5.56140200863305 \cdot 10^{-112}:\\ \;\;\;\;\frac{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} - b}{a \cdot 2}\\ \mathbf{if}\;b \le 7.500840778510721 \cdot 10^{-26}:\\ \;\;\;\;\frac{\frac{\left(4 \cdot c\right) \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 2.1m)Debug logProfile

herbie shell --seed '#(1072936661 1621281212 3440817831 3219514234 460296804 1258167384)' +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)))