Average Error: 33.4 → 11.1
Time: 23.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.414097958926068 \cdot 10^{+52}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -3.3495933623292597 \cdot 10^{+24}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\left(-4 \cdot a\right) \cdot c + b \cdot b}}{a} \cdot \frac{1}{2}\\ \mathbf{elif}\;b \le -3.0952147242065757 \cdot 10^{-27}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -5.048430376004428 \cdot 10^{-61}:\\ \;\;\;\;\frac{a \cdot \left(4 \cdot c\right)}{\left(2 \cdot a\right) \cdot \left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + \left(-b\right)\right)}\\ \mathbf{elif}\;b \le -1.8507836106114313 \cdot 10^{-103}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 1.069932557471162 \cdot 10^{+80}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\left(-4 \cdot a\right) \cdot c + b \cdot b}}{a} \cdot \frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original33.4
Target20.7
Herbie11.1
\[\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.414097958926068e+52 or -3.3495933623292597e+24 < b < -3.0952147242065757e-27 or -5.048430376004428e-61 < b < -1.8507836106114313e-103

    1. Initial program 52.3

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied sub-neg52.3

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    5. Simplified9.2

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

    if -1.414097958926068e+52 < b < -3.3495933623292597e+24 or -1.8507836106114313e-103 < b < 1.069932557471162e+80

    1. Initial program 14.5

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied sub-neg14.5

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

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

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

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

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

    if -3.0952147242065757e-27 < b < -5.048430376004428e-61

    1. Initial program 38.0

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied flip--38.1

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

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

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

    if 1.069932557471162e+80 < b

    1. Initial program 40.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.414097958926068 \cdot 10^{+52}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -3.3495933623292597 \cdot 10^{+24}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\left(-4 \cdot a\right) \cdot c + b \cdot b}}{a} \cdot \frac{1}{2}\\ \mathbf{elif}\;b \le -3.0952147242065757 \cdot 10^{-27}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -5.048430376004428 \cdot 10^{-61}:\\ \;\;\;\;\frac{a \cdot \left(4 \cdot c\right)}{\left(2 \cdot a\right) \cdot \left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + \left(-b\right)\right)}\\ \mathbf{elif}\;b \le -1.8507836106114313 \cdot 10^{-103}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 1.069932557471162 \cdot 10^{+80}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\left(-4 \cdot a\right) \cdot c + b \cdot b}}{a} \cdot \frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Runtime

Time bar (total: 23.6s)Debug logProfile

BaselineHerbieOracleSpan%
Regimes33.411.15.827.780.8%
herbie shell --seed 2018290 
(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)))