Average Error: 33.4 → 12.7
Time: 30.3s
Precision: 64
Internal Precision: 128
\[\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 -2.0199568394375094 \cdot 10^{-202}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.0174565485703704 \cdot 10^{+110}:\\ \;\;\;\;\frac{c \cdot -2}{b + \sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -2}{b + b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.4
Target20.2
Herbie12.7
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \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 < -2.0199568394375094e-202

    1. Initial program 21.8

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

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

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

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

    if -2.0199568394375094e-202 < b < 1.0174565485703704e+110

    1. Initial program 30.5

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(a \cdot \left(-4 \cdot c\right)\right) \cdot \frac{\frac{1}{2}}{a}}}{\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} + b}\]
    9. Taylor expanded around 0 9.7

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

    if 1.0174565485703704e+110 < b

    1. Initial program 59.3

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(a \cdot \left(-4 \cdot c\right)\right) \cdot \frac{\frac{1}{2}}{a}}}{\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} + b}\]
    9. Taylor expanded around 0 30.2

      \[\leadsto \frac{\color{blue}{-2 \cdot c}}{\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} + b}\]
    10. Taylor expanded around 0 1.9

      \[\leadsto \frac{-2 \cdot c}{\color{blue}{b} + b}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification12.7

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

Runtime

Time bar (total: 30.3s)Debug logProfile

herbie shell --seed 2018348 +o rules:numerics
(FPCore (a b c)
  :name "quadp (p42, positive)"

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