Average Error: 33.5 → 8.7
Time: 1.7m
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 -1.0997908275242063 \cdot 10^{+151}:\\ \;\;\;\;\frac{\frac{c}{b}}{1} - \frac{b}{a}\\ \mathbf{if}\;b \le 4.812686842305236 \cdot 10^{-167}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a + a}\\ \mathbf{if}\;b \le 72164228273.94012:\\ \;\;\;\;\frac{\frac{4 \cdot \left(c \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}{a + a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{2} \cdot 4}{\left(c + c\right) \cdot \frac{a}{b} - \left(b + b\right)}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.5
Target20.5
Herbie8.7
\[\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.0997908275242063e+151

    1. Initial program 59.9

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

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

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

    if -1.0997908275242063e+151 < b < 4.812686842305236e-167

    1. Initial program 9.7

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

    if 4.812686842305236e-167 < b < 72164228273.94012

    1. Initial program 33.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-+33.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 simplify18.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}\]

    if 72164228273.94012 < b

    1. Initial program 55.5

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

      \[\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 simplify26.8

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

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -1.0997908275242063 \cdot 10^{+151}:\\ \;\;\;\;\frac{\frac{c}{b}}{1} - \frac{b}{a}\\ \mathbf{if}\;b \le 4.812686842305236 \cdot 10^{-167}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a + a}\\ \mathbf{if}\;b \le 72164228273.94012:\\ \;\;\;\;\frac{\frac{4 \cdot \left(c \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}{a + a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{2} \cdot 4}{\left(c + c\right) \cdot \frac{a}{b} - \left(b + b\right)}\\ \end{array}}\]

Runtime

Time bar (total: 1.7m)Debug log

herbie shell --seed '#(212267722 3993171362 1093346726 3605783651 2106536041 3335990851)' 
(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)))