Average Error: 34.1 → 11.3
Time: 1.1m
Precision: 64
Internal Precision: 128
\[\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 -1.2275576669103459 \cdot 10^{+128}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 3.4538165630872146 \cdot 10^{-131}:\\ \;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.0625442301628973 \cdot 10^{-09}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 1.2098422568232927 \cdot 10^{+22}:\\ \;\;\;\;\frac{\frac{\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{\sqrt{\sqrt{2}}}}{\sqrt{\sqrt{2}}}}{\left(a \cdot \sqrt{\sqrt{\sqrt{2}}}\right) \cdot \left(\sqrt{\sqrt{2}} \cdot \sqrt{\sqrt{\sqrt{2}}}\right)}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.1
Target21.4
Herbie11.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 < -1.2275576669103459e+128

    1. Initial program 51.2

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

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

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

    if -1.2275576669103459e+128 < b < 3.4538165630872146e-131

    1. Initial program 11.8

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

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

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

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

    if 3.4538165630872146e-131 < b < 2.0625442301628973e-09 or 1.2098422568232927e+22 < b

    1. Initial program 51.1

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

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

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

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

    if 2.0625442301628973e-09 < b < 1.2098422568232927e+22

    1. Initial program 42.9

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

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

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

      \[\leadsto \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{\color{blue}{\sqrt{2} \cdot \left(\sqrt{2} \cdot a\right)}}\]
    6. Applied associate-/r*43.2

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

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

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

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

      \[\leadsto \frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{\color{blue}{\sqrt{\sqrt{2}} \cdot \sqrt{\sqrt{2}}}}}{\sqrt{\sqrt{2}} \cdot \left(\sqrt{\sqrt{2}} \cdot a\right)}\]
    13. Applied associate-/r*43.3

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

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

      \[\leadsto \frac{\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{\sqrt{\sqrt{2}}}}{\sqrt{\sqrt{2}}}}{\sqrt{\sqrt{2}} \cdot \left(\color{blue}{\left(\sqrt{\sqrt{\sqrt{2}}} \cdot \sqrt{\sqrt{\sqrt{2}}}\right)} \cdot a\right)}\]
    17. Applied associate-*l*43.2

      \[\leadsto \frac{\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{\sqrt{\sqrt{2}}}}{\sqrt{\sqrt{2}}}}{\sqrt{\sqrt{2}} \cdot \color{blue}{\left(\sqrt{\sqrt{\sqrt{2}}} \cdot \left(\sqrt{\sqrt{\sqrt{2}}} \cdot a\right)\right)}}\]
    18. Applied associate-*r*43.2

      \[\leadsto \frac{\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{\sqrt{\sqrt{2}}}}{\sqrt{\sqrt{2}}}}{\color{blue}{\left(\sqrt{\sqrt{2}} \cdot \sqrt{\sqrt{\sqrt{2}}}\right) \cdot \left(\sqrt{\sqrt{\sqrt{2}}} \cdot a\right)}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification11.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.2275576669103459 \cdot 10^{+128}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 3.4538165630872146 \cdot 10^{-131}:\\ \;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.0625442301628973 \cdot 10^{-09}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 1.2098422568232927 \cdot 10^{+22}:\\ \;\;\;\;\frac{\frac{\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{\sqrt{\sqrt{2}}}}{\sqrt{\sqrt{2}}}}{\left(a \cdot \sqrt{\sqrt{\sqrt{2}}}\right) \cdot \left(\sqrt{\sqrt{2}} \cdot \sqrt{\sqrt{\sqrt{2}}}\right)}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019088 
(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)))