Average Error: 33.3 → 9.2
Time: 51.6s
Precision: 64
Internal Precision: 3392
\[\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.3133359992031699 \cdot 10^{+84}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -9.014335931769693 \cdot 10^{-94}:\\ \;\;\;\;\frac{\left(4 \cdot c\right) \cdot a}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}\right)}\\ \mathbf{elif}\;b \le 1.4450909442925608 \cdot 10^{+100}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.3
Target20.7
Herbie9.2
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\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.3133359992031699e+84

    1. Initial program 57.8

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

      \[\leadsto \frac{\left(-b\right) - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}{2 \cdot a}\]
    3. Taylor expanded around 0 57.8

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    6. Simplified2.9

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

    if -1.3133359992031699e+84 < b < -9.014335931769693e-94

    1. Initial program 40.5

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Initial simplification40.5

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}}}\]
    5. Using strategy rm
    6. Applied associate-/r/40.6

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

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

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

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

    if -9.014335931769693e-94 < b < 1.4450909442925608e+100

    1. Initial program 12.2

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}}}\]
    5. Using strategy rm
    6. Applied associate-/r/12.3

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

    if 1.4450909442925608e+100 < b

    1. Initial program 45.7

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Initial simplification45.7

      \[\leadsto \frac{\left(-b\right) - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}{2 \cdot a}\]
    3. Taylor expanded around 0 45.7

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.3133359992031699 \cdot 10^{+84}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -9.014335931769693 \cdot 10^{-94}:\\ \;\;\;\;\frac{\left(4 \cdot c\right) \cdot a}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}\right)}\\ \mathbf{elif}\;b \le 1.4450909442925608 \cdot 10^{+100}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Runtime

Time bar (total: 51.6s)Debug logProfile

BaselineHerbieOracleSpan%
Regimes33.49.25.627.886.8%
herbie shell --seed 2018286 +o rules:numerics
(FPCore (a b c)
  :name "quadm (p42, negative)"

  :herbie-target
  (if (< b 0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))