Average Error: 33.6 → 12.6
Time: 2.2m
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 -6.928549363244461 \cdot 10^{-231}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{if}\;b \le 8.799077088999076 \cdot 10^{+142}:\\ \;\;\;\;-\frac{\left(4 \cdot c\right) \cdot \frac{1}{2}}{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} + b}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b + b} \cdot \frac{-4}{2}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

  1. Inputs

  2. Original Output:

    Herbie Output:

Target

Original33.6
Target20.4
Herbie12.6
\[\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 < -6.928549363244461e-231

    1. Initial program 21.8

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

    if -6.928549363244461e-231 < b < 8.799077088999076e+142

    1. Initial program 32.0

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

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

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

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

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

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

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

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

    if 8.799077088999076e+142 < b

    1. Initial program 61.7

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

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

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

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

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

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

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

      \[\leadsto -\color{blue}{\frac{\left(4 \cdot c\right) \cdot \frac{1}{2}}{\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} + b}}\]
    11. Using strategy rm
    12. Applied add-exp-log35.1

      \[\leadsto -\frac{\left(4 \cdot c\right) \cdot \frac{1}{2}}{\color{blue}{e^{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*} + b\right)}}}\]
    13. Taylor expanded around 0 5.6

      \[\leadsto -\frac{\left(4 \cdot c\right) \cdot \frac{1}{2}}{e^{\log \left(\color{blue}{b} + b\right)}}\]
    14. Applied simplify1.9

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

Runtime

Time bar (total: 2.2m)Debug logProfile

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