Average Error: 33.7 → 9.4
Time: 1.5m
Precision: 64
Internal Precision: 3392
\[\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 -1.3338600865169524 \cdot 10^{+85}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \le 1.5616348041811878 \cdot 10^{-106}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} - b\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.9849414744995752 \cdot 10^{+82}:\\ \;\;\;\;\frac{\frac{\left(a \cdot c\right) \cdot \left(-4\right)}{a \cdot 2}}{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} + b}\\ \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.7
Target21.0
Herbie9.4
\[\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 4 regimes
  2. if b < -1.3338600865169524e+85

    1. Initial program 42.2

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    4. Simplified3.9

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

    if -1.3338600865169524e+85 < b < 1.5616348041811878e-106

    1. Initial program 12.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Initial simplification12.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-inv12.7

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

    if 1.5616348041811878e-106 < b < 2.9849414744995752e+82

    1. Initial program 42.7

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

      \[\leadsto \frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}\]
    3. Using strategy rm
    4. Applied div-inv42.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. Using strategy rm
    6. Applied flip--42.8

      \[\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}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}} \cdot \frac{1}{2 \cdot a}\]
    7. Applied associate-*l/42.8

      \[\leadsto \color{blue}{\frac{\left(\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\right) \cdot \frac{1}{2 \cdot a}}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}}\]
    8. Simplified15.9

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

    if 2.9849414744995752e+82 < b

    1. Initial program 57.8

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

      \[\leadsto \frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}\]
    3. Using strategy rm
    4. Applied div-inv57.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.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.3338600865169524 \cdot 10^{+85}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \le 1.5616348041811878 \cdot 10^{-106}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} - b\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.9849414744995752 \cdot 10^{+82}:\\ \;\;\;\;\frac{\frac{\left(a \cdot c\right) \cdot \left(-4\right)}{a \cdot 2}}{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} + b}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Runtime

Time bar (total: 1.5m)Debug logProfile

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