Average Error: 33.2 → 6.8
Time: 34.3s
Precision: 64
Internal Precision: 3392
\[\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.2802147447265656 \cdot 10^{+121}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 2.337064913572966 \cdot 10^{-250}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} + \left(-b\right)}{a \cdot 2}\\ \mathbf{elif}\;b \le 4.416316979263219 \cdot 10^{+80}:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.2
Target20.5
Herbie6.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 4 regimes
  2. if b < -1.2802147447265656e+121

    1. Initial program 50.3

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

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

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

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

    if -1.2802147447265656e+121 < b < 2.337064913572966e-250

    1. Initial program 9.4

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

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

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

    if 2.337064913572966e-250 < b < 4.416316979263219e+80

    1. Initial program 33.4

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

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}}{2 \cdot a}\]
    4. Using strategy rm
    5. Applied div-inv33.5

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

      \[\leadsto \color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} \cdot \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}{\left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}} \cdot \frac{1}{2 \cdot a}\]
    8. Applied associate-*l/33.6

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

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

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

    if 4.416316979263219e+80 < b

    1. Initial program 57.5

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

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{\color{blue}{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}}{2 \cdot a}\]
    4. Using strategy rm
    5. Applied div-inv57.5

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.2802147447265656 \cdot 10^{+121}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 2.337064913572966 \cdot 10^{-250}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} + \left(-b\right)}{a \cdot 2}\\ \mathbf{elif}\;b \le 4.416316979263219 \cdot 10^{+80}:\\ \;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Runtime

Time bar (total: 34.3s)Debug logProfile

BaselineHerbieOracleSpan%
Regimes29.26.85.823.495.6%
herbie shell --seed 2018290 +o rules:numerics
(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)))