Average Error: 33.6 → 9.8
Time: 24.3s
Precision: 64
Internal Precision: 128
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.9226835678529536 \cdot 10^{+89}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 4.788197275480391 \cdot 10^{-88}:\\ \;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}}{2} \cdot \frac{\sqrt{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}}{a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.6
Target20.6
Herbie9.8
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if b < -1.9226835678529536e+89

    1. Initial program 42.9

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

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

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

    if -1.9226835678529536e+89 < b < 4.788197275480391e-88

    1. Initial program 12.4

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

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

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

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

    if 4.788197275480391e-88 < b

    1. Initial program 52.3

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    4. Simplified9.4

      \[\leadsto \color{blue}{-\frac{c}{b}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification9.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.9226835678529536 \cdot 10^{+89}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 4.788197275480391 \cdot 10^{-88}:\\ \;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}}{2} \cdot \frac{\sqrt{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}}{a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019053 
(FPCore (a b c)
  :name "The quadratic formula (r1)"

  :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)))