?

Average Accuracy: 17.8% → 99.4%
Time: 12.2s
Precision: binary64
Cost: 14016

?

\[\left(\left(4.930380657631324 \cdot 10^{-32} < a \land a < 2.028240960365167 \cdot 10^{+31}\right) \land \left(4.930380657631324 \cdot 10^{-32} < b \land b < 2.028240960365167 \cdot 10^{+31}\right)\right) \land \left(4.930380657631324 \cdot 10^{-32} < c \land c < 2.028240960365167 \cdot 10^{+31}\right)\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
\[\frac{\frac{-4 \cdot \left(c \cdot a\right)}{b + \sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)}}}{a \cdot 2} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
 :precision binary64
 (/ (/ (* -4.0 (* c a)) (+ b (sqrt (fma c (* -4.0 a) (* b b))))) (* a 2.0)))
double code(double a, double b, double c) {
	return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
double code(double a, double b, double c) {
	return ((-4.0 * (c * a)) / (b + sqrt(fma(c, (-4.0 * a), (b * b))))) / (a * 2.0);
}
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a))
end
function code(a, b, c)
	return Float64(Float64(Float64(-4.0 * Float64(c * a)) / Float64(b + sqrt(fma(c, Float64(-4.0 * a), Float64(b * b))))) / Float64(a * 2.0))
end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := N[(N[(N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(c * N[(-4.0 * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\frac{\frac{-4 \cdot \left(c \cdot a\right)}{b + \sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)}}}{a \cdot 2}

Error?

Derivation?

  1. Initial program 17.8%

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

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

    [Start]17.8

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

    sub-neg [=>]17.8

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

    flip-+ [=>]17.8

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

    pow2 [=>]17.8

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

    pow2 [=>]17.8

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

    pow-prod-up [=>]17.8

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

    metadata-eval [=>]17.8

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

    *-commutative [=>]17.8

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

    distribute-rgt-neg-in [=>]17.8

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

    *-commutative [=>]17.8

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

    distribute-rgt-neg-in [=>]17.8

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

    metadata-eval [=>]17.8

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

    *-commutative [=>]17.8

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

    distribute-rgt-neg-in [=>]17.8

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

    *-commutative [=>]17.8

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

    distribute-rgt-neg-in [=>]17.8

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

    metadata-eval [=>]17.8

    \[ \frac{\left(-b\right) + \sqrt{\frac{{b}^{4} - \left(c \cdot \left(a \cdot -4\right)\right) \cdot \left(c \cdot \left(a \cdot \color{blue}{-4}\right)\right)}{b \cdot b - \left(-\left(4 \cdot a\right) \cdot c\right)}}}{2 \cdot a} \]
  3. Applied egg-rr18.2%

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

    [Start]17.8

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

    +-commutative [=>]17.8

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

    flip-+ [=>]17.7

    \[ \frac{\color{blue}{\frac{\sqrt{\frac{{b}^{4} - \left(c \cdot \left(a \cdot -4\right)\right) \cdot \left(c \cdot \left(a \cdot -4\right)\right)}{b \cdot b - c \cdot \left(a \cdot -4\right)}} \cdot \sqrt{\frac{{b}^{4} - \left(c \cdot \left(a \cdot -4\right)\right) \cdot \left(c \cdot \left(a \cdot -4\right)\right)}{b \cdot b - c \cdot \left(a \cdot -4\right)}} - \left(-b\right) \cdot \left(-b\right)}{\sqrt{\frac{{b}^{4} - \left(c \cdot \left(a \cdot -4\right)\right) \cdot \left(c \cdot \left(a \cdot -4\right)\right)}{b \cdot b - c \cdot \left(a \cdot -4\right)}} - \left(-b\right)}}}{2 \cdot a} \]
  4. Simplified18.3%

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

    [Start]18.2

    \[ \frac{\frac{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) - b \cdot b}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{2 \cdot a} \]

    /-rgt-identity [<=]18.2

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

    /-rgt-identity [=>]18.2

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

    fma-def [<=]18.3

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

    +-commutative [<=]18.3

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

    fma-def [=>]18.3

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

    fma-def [<=]18.3

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

    +-commutative [<=]18.3

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

    fma-def [=>]18.3

    \[ \frac{\frac{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right) - b \cdot b}{b + \sqrt{\color{blue}{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}}{2 \cdot a} \]
  5. Taylor expanded in c around 0 99.4%

    \[\leadsto \frac{\frac{\color{blue}{-4 \cdot \left(c \cdot a\right)}}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}{2 \cdot a} \]
  6. Final simplification99.4%

    \[\leadsto \frac{\frac{-4 \cdot \left(c \cdot a\right)}{b + \sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)}}}{a \cdot 2} \]

Alternatives

Alternative 1
Accuracy99.4%
Cost7744
\[\frac{\frac{-4 \cdot \left(c \cdot a\right)}{b + \sqrt{b \cdot b + c \cdot \left(-4 \cdot a\right)}}}{a \cdot 2} \]
Alternative 2
Accuracy95.2%
Cost7232
\[\frac{-c}{b} - a \cdot \frac{c}{\frac{{b}^{3}}{c}} \]
Alternative 3
Accuracy95.1%
Cost576
\[\frac{1}{\frac{a}{b} - \frac{b}{c}} \]
Alternative 4
Accuracy90.4%
Cost256
\[\frac{-c}{b} \]
Alternative 5
Accuracy1.7%
Cost192
\[\frac{c}{b} \]

Error

Reproduce?

herbie shell --seed 2023144 
(FPCore (a b c)
  :name "Quadratic roots, wide range"
  :precision binary64
  :pre (and (and (and (< 4.930380657631324e-32 a) (< a 2.028240960365167e+31)) (and (< 4.930380657631324e-32 b) (< b 2.028240960365167e+31))) (and (< 4.930380657631324e-32 c) (< c 2.028240960365167e+31)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))