Average Error: 33.2 → 15.4
Time: 34.2s
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.9929209198465677 \cdot 10^{+119}:\\ \;\;\;\;\frac{(\left(\frac{2}{b}\right) \cdot \left(c \cdot a\right) + \left(b \cdot -2\right))_*}{2 \cdot a}\\ \mathbf{elif}\;b \le 1.0745192433987663 \cdot 10^{-99}:\\ \;\;\;\;\frac{(\left(\sqrt[3]{-b} \cdot \sqrt[3]{-b}\right) \cdot \left(\sqrt[3]{-b}\right) + \left(\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\right))_*}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2 \cdot \frac{c \cdot a}{b}}{2 \cdot a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.2
Target20.4
Herbie15.4
\[\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.9929209198465677e+119

    1. Initial program 48.7

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

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}{2 \cdot a}\]
    3. Simplified8.3

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

    if -1.9929209198465677e+119 < b < 1.0745192433987663e-99

    1. Initial program 11.8

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt12.0

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

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

    if 1.0745192433987663e-99 < b

    1. Initial program 51.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.9929209198465677 \cdot 10^{+119}:\\ \;\;\;\;\frac{(\left(\frac{2}{b}\right) \cdot \left(c \cdot a\right) + \left(b \cdot -2\right))_*}{2 \cdot a}\\ \mathbf{elif}\;b \le 1.0745192433987663 \cdot 10^{-99}:\\ \;\;\;\;\frac{(\left(\sqrt[3]{-b} \cdot \sqrt[3]{-b}\right) \cdot \left(\sqrt[3]{-b}\right) + \left(\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\right))_*}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2 \cdot \frac{c \cdot a}{b}}{2 \cdot a}\\ \end{array}\]

Runtime

Time bar (total: 34.2s)Debug logProfile

herbie shell --seed 2018235 +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)))