Average Error: 33.8 → 10.9
Time: 47.6s
Precision: 64
Internal Precision: 2368
\[\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 -8.391478813092284:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 4.2554586162183576 \cdot 10^{+103}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{b}{a} - \frac{\sqrt{a \cdot \left(-4 \cdot c\right) + b \cdot b}}{\frac{a}{\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.8
Target21.0
Herbie10.9
\[\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 3 regimes
  2. if b < -8.391478813092284

    1. Initial program 55.0

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

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

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

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

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

    if -8.391478813092284 < b < 4.2554586162183576e+103

    1. Initial program 16.5

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

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

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

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

      \[\leadsto \color{blue}{{\left(\left(-b\right) - \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}\right)}^{1}} \cdot {\left(\frac{1}{2 \cdot a}\right)}^{1}\]
    8. Applied pow-prod-down16.6

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

      \[\leadsto {\color{blue}{\left(\frac{\left(-b\right) - \sqrt{\left(-4 \cdot c\right) \cdot a + b \cdot b}}{\frac{a}{\frac{1}{2}}}\right)}}^{1}\]
    10. Using strategy rm
    11. Applied div-sub16.6

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

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

    if 4.2554586162183576e+103 < b

    1. Initial program 45.6

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -8.391478813092284:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 4.2554586162183576 \cdot 10^{+103}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{b}{a} - \frac{\sqrt{a \cdot \left(-4 \cdot c\right) + b \cdot b}}{\frac{a}{\frac{1}{2}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Runtime

Time bar (total: 47.6s)Debug logProfile

herbie shell --seed 2018257 
(FPCore (a b c)
  :name "The quadratic formula (r2)"

  :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)))