Average Error: 32.9 → 10.3
Time: 19.2s
Precision: 64
\[\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 -9.088000531423294 \cdot 10^{+152}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 9.354082991670835 \cdot 10^{-125}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}}{a}}{2} - \frac{\frac{b}{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]
\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 -9.088000531423294 \cdot 10^{+152}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \le 9.354082991670835 \cdot 10^{-125}:\\
\;\;\;\;\frac{\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}}{a}}{2} - \frac{\frac{b}{a}}{2}\\

\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\

\end{array}
double f(double a, double b, double c) {
        double r1546447 = b;
        double r1546448 = -r1546447;
        double r1546449 = r1546447 * r1546447;
        double r1546450 = 4.0;
        double r1546451 = a;
        double r1546452 = c;
        double r1546453 = r1546451 * r1546452;
        double r1546454 = r1546450 * r1546453;
        double r1546455 = r1546449 - r1546454;
        double r1546456 = sqrt(r1546455);
        double r1546457 = r1546448 + r1546456;
        double r1546458 = 2.0;
        double r1546459 = r1546458 * r1546451;
        double r1546460 = r1546457 / r1546459;
        return r1546460;
}

double f(double a, double b, double c) {
        double r1546461 = b;
        double r1546462 = -9.088000531423294e+152;
        bool r1546463 = r1546461 <= r1546462;
        double r1546464 = c;
        double r1546465 = r1546464 / r1546461;
        double r1546466 = a;
        double r1546467 = r1546461 / r1546466;
        double r1546468 = r1546465 - r1546467;
        double r1546469 = 9.354082991670835e-125;
        bool r1546470 = r1546461 <= r1546469;
        double r1546471 = r1546461 * r1546461;
        double r1546472 = 4.0;
        double r1546473 = r1546466 * r1546472;
        double r1546474 = r1546473 * r1546464;
        double r1546475 = r1546471 - r1546474;
        double r1546476 = sqrt(r1546475);
        double r1546477 = r1546476 / r1546466;
        double r1546478 = 2.0;
        double r1546479 = r1546477 / r1546478;
        double r1546480 = r1546467 / r1546478;
        double r1546481 = r1546479 - r1546480;
        double r1546482 = -r1546465;
        double r1546483 = r1546470 ? r1546481 : r1546482;
        double r1546484 = r1546463 ? r1546468 : r1546483;
        return r1546484;
}

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

Original32.9
Target20.3
Herbie10.3
\[\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 < -9.088000531423294e+152

    1. Initial program 60.4

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

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

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

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

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

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

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

    if -9.088000531423294e+152 < b < 9.354082991670835e-125

    1. Initial program 10.9

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

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

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

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

    if 9.354082991670835e-125 < b

    1. Initial program 49.8

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a}}{2}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity49.8

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

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

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

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

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

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

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

Reproduce

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