Average Error: 33.4 → 10.5
Time: 34.1s
Precision: 64
Internal Precision: 3136
\[\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 -3.234401054883418 \cdot 10^{+110}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 2.713756923051816 \cdot 10^{-06}:\\ \;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}}{2} \cdot \frac{\sqrt{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}}{a}\\ \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

Original33.4
Target20.9
Herbie10.5
\[\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 < -3.234401054883418e+110

    1. Initial program 46.6

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

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

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

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

    if -3.234401054883418e+110 < b < 2.713756923051816e-06

    1. Initial program 15.4

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

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

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

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

    if 2.713756923051816e-06 < b

    1. Initial program 54.6

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

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

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

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

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

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

Runtime

Time bar (total: 34.1s)Debug logProfile

herbie shell --seed 2018227 
(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)))