Average Error: 34.1 → 9.6
Time: 29.5s
Precision: 64
Internal Precision: 128
\[\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 -5.4734139045519595 \cdot 10^{+113}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.9379739650628456 \cdot 10^{-78}:\\ \;\;\;\;\frac{\sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.5482541494853623 \cdot 10^{-62}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 2.387647669713383 \cdot 10^{-51}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}}\\ \mathbf{elif}\;b \le 1.378908863446963 \cdot 10^{-10}:\\ \;\;\;\;\frac{a \cdot \left(c \cdot -4\right)}{\left(\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + b\right) \cdot \left(a \cdot 2\right)}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \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

Original34.1
Target21.1
Herbie9.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 5 regimes
  2. if b < -5.4734139045519595e+113

    1. Initial program 48.5

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

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

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

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

    if -5.4734139045519595e+113 < b < 1.9379739650628456e-78

    1. Initial program 13.1

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

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

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

    if 1.9379739650628456e-78 < b < 2.5482541494853623e-62 or 1.378908863446963e-10 < b

    1. Initial program 54.7

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

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

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

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

    if 2.5482541494853623e-62 < b < 2.387647669713383e-51

    1. Initial program 34.0

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

      \[\leadsto \frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity34.0

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

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

    if 2.387647669713383e-51 < b < 1.378908863446963e-10

    1. Initial program 38.8

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -5.4734139045519595 \cdot 10^{+113}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.9379739650628456 \cdot 10^{-78}:\\ \;\;\;\;\frac{\sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.5482541494853623 \cdot 10^{-62}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 2.387647669713383 \cdot 10^{-51}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}}\\ \mathbf{elif}\;b \le 1.378908863446963 \cdot 10^{-10}:\\ \;\;\;\;\frac{a \cdot \left(c \cdot -4\right)}{\left(\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + b\right) \cdot \left(a \cdot 2\right)}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Runtime

Time bar (total: 29.5s)Debug logProfile

BaselineHerbieOracleSpan%
Regimes34.19.65.628.586.2%
herbie shell --seed 2018354 
(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)))