Average Error: 34.8 → 5.8
Time: 1.0m
Precision: 64
Ground Truth: 128
\[\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.7321058520772784 \cdot 10^{+67}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{if}\;b \le 2.4619882133710072 \cdot 10^{-287}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{if}\;b \le 2.829973829663237 \cdot 10^{+105}:\\ \;\;\;\;\frac{4}{2} \cdot \frac{c}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{4}{2} \cdot c}{\frac{c \cdot 2}{\frac{b}{a}} - b \cdot 2}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.8
Comparison22.1
Herbie5.8
\[ \begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \end{array} \]

Derivation

  1. Split input into 4 regimes.
  2. if b < -1.7321058520772784e+67

    1. Initial program 41.8

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

      \[\leadsto -1 \cdot \frac{b}{a}\]
    3. Taylor expanded around -inf 0

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    4. Applied simplify 0

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

    if -1.7321058520772784e+67 < b < 2.4619882133710072e-287

    1. Initial program 10.3

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

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

    if 2.4619882133710072e-287 < b < 2.829973829663237e+105

    1. Initial program 33.6

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

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

      \[\leadsto \frac{\frac{\color{blue}{4 \cdot \left(a \cdot c\right)}}{\left(-b\right) - \sqrt{{b}^2 - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity 16.6

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

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

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

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

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

    if 2.829973829663237e+105 < b

    1. Initial program 59.4

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

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

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

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

      \[\leadsto \frac{\frac{4 \cdot \left(a \cdot c\right)}{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}}{2 \cdot a}\]
    7. Applied simplify 1.4

      \[\leadsto \color{blue}{\frac{\frac{1}{\frac{2}{4}} \cdot c}{\frac{c \cdot 2}{\frac{b}{a}} - b \cdot 2}}\]
    8. Applied simplify 1.4

      \[\leadsto \frac{\color{blue}{\frac{4}{2} \cdot c}}{\frac{c \cdot 2}{\frac{b}{a}} - b \cdot 2}\]
  3. Recombined 4 regimes into one program.
  4. Removed slow pow expressions

Runtime

Total time: 1.0m Debug log

Please include this information when filing a bug report:

herbie --seed '#(666576781 4098168481 2738904911 2989985146 2618005959 628145014)'
(FPCore (a b c)
  :name "NMSE p42, positive"

  :target
  (if (< b 0) (/ (+ (- b) (sqrt (- (sqr b) (* 4 (* a c))))) (* 2 a)) (/ c (* a (/ (- (- b) (sqrt (- (sqr b) (* 4 (* a c))))) (* 2 a)))))

  (/ (+ (- b) (sqrt (- (sqr b) (* 4 (* a c))))) (* 2 a)))