Average Error: 33.6 → 6.2
Time: 2.5m
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 -4.837069134240305 \cdot 10^{+153}:\\ \;\;\;\;\frac{c}{b} - \frac{b + b}{2 \cdot a}\\ \mathbf{if}\;b \le 5.78800039541729 \cdot 10^{-309}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{2 \cdot a} - \frac{b}{2 \cdot a}\\ \mathbf{if}\;b \le 1.9553504592237965 \cdot 10^{+143}:\\ \;\;\;\;\frac{4}{2} \cdot \frac{-c}{b + \sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.6
Target20.4
Herbie6.2
\[\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 < -4.837069134240305e+153

    1. Initial program 60.9

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{2 \cdot a}}\]
    3. Taylor expanded around -inf 12.2

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

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

    if -4.837069134240305e+153 < b < 5.78800039541729e-309

    1. Initial program 8.7

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied div-sub8.7

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

    if 5.78800039541729e-309 < b < 1.9553504592237965e+143

    1. Initial program 33.8

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

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

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

      \[\leadsto \frac{\frac{\color{blue}{\left(-4\right) \cdot \left(c \cdot a\right)}}{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} + b}}{2 \cdot a}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity15.1

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

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

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

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

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

    if 1.9553504592237965e+143 < b

    1. Initial program 61.8

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} - b}{2 \cdot a}}\]
    3. Taylor expanded around inf 37.5

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -4.837069134240305 \cdot 10^{+153}:\\ \;\;\;\;\frac{c}{b} - \frac{b + b}{2 \cdot a}\\ \mathbf{if}\;b \le 5.78800039541729 \cdot 10^{-309}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{2 \cdot a} - \frac{b}{2 \cdot a}\\ \mathbf{if}\;b \le 1.9553504592237965 \cdot 10^{+143}:\\ \;\;\;\;\frac{4}{2} \cdot \frac{-c}{b + \sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 2.5m)Debug logProfile

herbie shell --seed '#(1072361757 3390613284 2339397988 1175251238 145061547 3101881848)' 
(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)))