Average Error: 33.5 → 9.3
Time: 2.4m
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 -3.1208214551232244 \cdot 10^{+117}:\\ \;\;\;\;\frac{\frac{4}{2} \cdot c}{\frac{c + c}{\frac{b}{a}} - \left(b + b\right)}\\ \mathbf{if}\;-b \le -2.118907474743662 \cdot 10^{-210}:\\ \;\;\;\;\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{if}\;-b \le 7.665518801524091 \cdot 10^{+112}:\\ \;\;\;\;\frac{1}{\frac{a + a}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a + a}{\frac{b}{c}} - \left(b - \left(-b\right)\right)}{a + a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.5
Target20.7
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) < -3.1208214551232244e+117

    1. Initial program 60.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-+60.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 simplify33.9

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

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

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

    if -3.1208214551232244e+117 < (- b) < -2.118907474743662e-210

    1. Initial program 36.6

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

      \[\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 simplify16.4

      \[\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 -2.118907474743662e-210 < (- b) < 7.665518801524091e+112

    1. Initial program 10.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 clear-num10.8

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

    if 7.665518801524091e+112 < (- b)

    1. Initial program 47.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 clear-num47.9

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

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;-b \le -3.1208214551232244 \cdot 10^{+117}:\\ \;\;\;\;\frac{\frac{4}{2} \cdot c}{\frac{c + c}{\frac{b}{a}} - \left(b + b\right)}\\ \mathbf{if}\;-b \le -2.118907474743662 \cdot 10^{-210}:\\ \;\;\;\;\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{if}\;-b \le 7.665518801524091 \cdot 10^{+112}:\\ \;\;\;\;\frac{1}{\frac{a + a}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a + a}{\frac{b}{c}} - \left(b - \left(-b\right)\right)}{a + a}\\ \end{array}}\]

Runtime

Time bar (total: 2.4m)Debug logProfile

herbie shell --seed '#(1064173506 2580572819 2847706409 4129882574 1125180799 1845288547)' 
(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)))