?

Average Error: 28.5 → 5.9
Time: 2.4min
Precision: binary64
Cost: 38016

?

\[\left(\left(1.0536712127723509 \cdot 10^{-8} < a \land a < 94906265.62425156\right) \land \left(1.0536712127723509 \cdot 10^{-8} < b \land b < 94906265.62425156\right)\right) \land \left(1.0536712127723509 \cdot 10^{-8} < c \land c < 94906265.62425156\right)\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
\[\begin{array}{l} t_0 := -2 \cdot \left(c \cdot a\right)\\ t_1 := \left(t_0 \cdot a\right) \cdot c\\ t_2 := \left(t_0 \cdot -0.5\right) \cdot \left(2 \cdot \left(c \cdot a\right)\right)\\ t_3 := {t_0}^{2}\\ -1 \cdot \frac{c}{b} + \left(-0.25 \cdot \frac{{\left(\frac{1}{b}\right)}^{7} \cdot \left(4 \cdot \left(t_1 \cdot t_1\right) + t_2 \cdot t_2\right)}{a} + \left(-0.5 \cdot \left(c \cdot \left({\left(\frac{1}{b}\right)}^{5} \cdot t_3\right)\right) + -0.25 \cdot \frac{{b}^{-3} \cdot t_3}{a}\right)\right) \end{array} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
 :precision binary64
 (let* ((t_0 (* -2.0 (* c a)))
        (t_1 (* (* t_0 a) c))
        (t_2 (* (* t_0 -0.5) (* 2.0 (* c a))))
        (t_3 (pow t_0 2.0)))
   (+
    (* -1.0 (/ c b))
    (+
     (*
      -0.25
      (/ (* (pow (/ 1.0 b) 7.0) (+ (* 4.0 (* t_1 t_1)) (* t_2 t_2))) a))
     (+
      (* -0.5 (* c (* (pow (/ 1.0 b) 5.0) t_3)))
      (* -0.25 (/ (* (pow b -3.0) t_3) a)))))))
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) {
	double t_0 = -2.0 * (c * a);
	double t_1 = (t_0 * a) * c;
	double t_2 = (t_0 * -0.5) * (2.0 * (c * a));
	double t_3 = pow(t_0, 2.0);
	return (-1.0 * (c / b)) + ((-0.25 * ((pow((1.0 / b), 7.0) * ((4.0 * (t_1 * t_1)) + (t_2 * t_2))) / a)) + ((-0.5 * (c * (pow((1.0 / b), 5.0) * t_3))) + (-0.25 * ((pow(b, -3.0) * t_3) / a))));
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    t_0 = (-2.0d0) * (c * a)
    t_1 = (t_0 * a) * c
    t_2 = (t_0 * (-0.5d0)) * (2.0d0 * (c * a))
    t_3 = t_0 ** 2.0d0
    code = ((-1.0d0) * (c / b)) + (((-0.25d0) * ((((1.0d0 / b) ** 7.0d0) * ((4.0d0 * (t_1 * t_1)) + (t_2 * t_2))) / a)) + (((-0.5d0) * (c * (((1.0d0 / b) ** 5.0d0) * t_3))) + ((-0.25d0) * (((b ** (-3.0d0)) * t_3) / a))))
end function
public static double code(double a, double b, double c) {
	return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
public static double code(double a, double b, double c) {
	double t_0 = -2.0 * (c * a);
	double t_1 = (t_0 * a) * c;
	double t_2 = (t_0 * -0.5) * (2.0 * (c * a));
	double t_3 = Math.pow(t_0, 2.0);
	return (-1.0 * (c / b)) + ((-0.25 * ((Math.pow((1.0 / b), 7.0) * ((4.0 * (t_1 * t_1)) + (t_2 * t_2))) / a)) + ((-0.5 * (c * (Math.pow((1.0 / b), 5.0) * t_3))) + (-0.25 * ((Math.pow(b, -3.0) * t_3) / a))));
}
def code(a, b, c):
	return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
def code(a, b, c):
	t_0 = -2.0 * (c * a)
	t_1 = (t_0 * a) * c
	t_2 = (t_0 * -0.5) * (2.0 * (c * a))
	t_3 = math.pow(t_0, 2.0)
	return (-1.0 * (c / b)) + ((-0.25 * ((math.pow((1.0 / b), 7.0) * ((4.0 * (t_1 * t_1)) + (t_2 * t_2))) / a)) + ((-0.5 * (c * (math.pow((1.0 / b), 5.0) * t_3))) + (-0.25 * ((math.pow(b, -3.0) * t_3) / a))))
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)
	t_0 = Float64(-2.0 * Float64(c * a))
	t_1 = Float64(Float64(t_0 * a) * c)
	t_2 = Float64(Float64(t_0 * -0.5) * Float64(2.0 * Float64(c * a)))
	t_3 = t_0 ^ 2.0
	return Float64(Float64(-1.0 * Float64(c / b)) + Float64(Float64(-0.25 * Float64(Float64((Float64(1.0 / b) ^ 7.0) * Float64(Float64(4.0 * Float64(t_1 * t_1)) + Float64(t_2 * t_2))) / a)) + Float64(Float64(-0.5 * Float64(c * Float64((Float64(1.0 / b) ^ 5.0) * t_3))) + Float64(-0.25 * Float64(Float64((b ^ -3.0) * t_3) / a)))))
end
function tmp = code(a, b, c)
	tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
end
function tmp = code(a, b, c)
	t_0 = -2.0 * (c * a);
	t_1 = (t_0 * a) * c;
	t_2 = (t_0 * -0.5) * (2.0 * (c * a));
	t_3 = t_0 ^ 2.0;
	tmp = (-1.0 * (c / b)) + ((-0.25 * ((((1.0 / b) ^ 7.0) * ((4.0 * (t_1 * t_1)) + (t_2 * t_2))) / a)) + ((-0.5 * (c * (((1.0 / b) ^ 5.0) * t_3))) + (-0.25 * (((b ^ -3.0) * t_3) / a))));
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_] := Block[{t$95$0 = N[(-2.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(t$95$0 * a), $MachinePrecision] * c), $MachinePrecision]}, Block[{t$95$2 = N[(N[(t$95$0 * -0.5), $MachinePrecision] * N[(2.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Power[t$95$0, 2.0], $MachinePrecision]}, N[(N[(-1.0 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(N[(-0.25 * N[(N[(N[Power[N[(1.0 / b), $MachinePrecision], 7.0], $MachinePrecision] * N[(N[(4.0 * N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision] + N[(t$95$2 * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] + N[(N[(-0.5 * N[(c * N[(N[Power[N[(1.0 / b), $MachinePrecision], 5.0], $MachinePrecision] * t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.25 * N[(N[(N[Power[b, -3.0], $MachinePrecision] * t$95$3), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
t_0 := -2 \cdot \left(c \cdot a\right)\\
t_1 := \left(t_0 \cdot a\right) \cdot c\\
t_2 := \left(t_0 \cdot -0.5\right) \cdot \left(2 \cdot \left(c \cdot a\right)\right)\\
t_3 := {t_0}^{2}\\
-1 \cdot \frac{c}{b} + \left(-0.25 \cdot \frac{{\left(\frac{1}{b}\right)}^{7} \cdot \left(4 \cdot \left(t_1 \cdot t_1\right) + t_2 \cdot t_2\right)}{a} + \left(-0.5 \cdot \left(c \cdot \left({\left(\frac{1}{b}\right)}^{5} \cdot t_3\right)\right) + -0.25 \cdot \frac{{b}^{-3} \cdot t_3}{a}\right)\right)
\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 28.5

    \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
  2. Taylor expanded in b around inf 5.9

    \[\leadsto \color{blue}{-1 \cdot \frac{c}{b} + \left(-0.25 \cdot \frac{{\left(\frac{1}{b}\right)}^{7} \cdot \left(4 \cdot \left({\left(-2 \cdot \left(c \cdot a\right)\right)}^{2} \cdot \left({a}^{2} \cdot {c}^{2}\right)\right) + {\left(-0.5 \cdot {\left(-2 \cdot \left(c \cdot a\right)\right)}^{2}\right)}^{2}\right)}{a} + \left(-0.5 \cdot \left(c \cdot \left({\left(\frac{1}{b}\right)}^{5} \cdot {\left(-2 \cdot \left(c \cdot a\right)\right)}^{2}\right)\right) + -0.25 \cdot \frac{{\left(\frac{1}{b}\right)}^{3} \cdot {\left(-2 \cdot \left(c \cdot a\right)\right)}^{2}}{a}\right)\right)} \]
  3. Applied egg-rr5.9

    \[\leadsto -1 \cdot \frac{c}{b} + \left(-0.25 \cdot \frac{{\left(\frac{1}{b}\right)}^{7} \cdot \left(4 \cdot \color{blue}{\left(\left(\left(\left(-2 \cdot \left(c \cdot a\right)\right) \cdot a\right) \cdot c\right) \cdot \left(\left(\left(-2 \cdot \left(c \cdot a\right)\right) \cdot a\right) \cdot c\right)\right)} + {\left(-0.5 \cdot {\left(-2 \cdot \left(c \cdot a\right)\right)}^{2}\right)}^{2}\right)}{a} + \left(-0.5 \cdot \left(c \cdot \left({\left(\frac{1}{b}\right)}^{5} \cdot {\left(-2 \cdot \left(c \cdot a\right)\right)}^{2}\right)\right) + -0.25 \cdot \frac{{\left(\frac{1}{b}\right)}^{3} \cdot {\left(-2 \cdot \left(c \cdot a\right)\right)}^{2}}{a}\right)\right) \]
  4. Taylor expanded in b around 0 5.9

    \[\leadsto -1 \cdot \frac{c}{b} + \left(-0.25 \cdot \frac{{\left(\frac{1}{b}\right)}^{7} \cdot \left(4 \cdot \left(\left(\left(\left(-2 \cdot \left(c \cdot a\right)\right) \cdot a\right) \cdot c\right) \cdot \left(\left(\left(-2 \cdot \left(c \cdot a\right)\right) \cdot a\right) \cdot c\right)\right) + {\left(-0.5 \cdot {\left(-2 \cdot \left(c \cdot a\right)\right)}^{2}\right)}^{2}\right)}{a} + \left(-0.5 \cdot \left(c \cdot \left({\left(\frac{1}{b}\right)}^{5} \cdot {\left(-2 \cdot \left(c \cdot a\right)\right)}^{2}\right)\right) + -0.25 \cdot \frac{\color{blue}{{b}^{-3}} \cdot {\left(-2 \cdot \left(c \cdot a\right)\right)}^{2}}{a}\right)\right) \]
  5. Applied egg-rr5.9

    \[\leadsto -1 \cdot \frac{c}{b} + \left(-0.25 \cdot \frac{{\left(\frac{1}{b}\right)}^{7} \cdot \left(4 \cdot \left(\left(\left(\left(-2 \cdot \left(c \cdot a\right)\right) \cdot a\right) \cdot c\right) \cdot \left(\left(\left(-2 \cdot \left(c \cdot a\right)\right) \cdot a\right) \cdot c\right)\right) + \color{blue}{\left(\left(\left(-2 \cdot \left(c \cdot a\right)\right) \cdot -0.5\right) \cdot \left(2 \cdot \left(c \cdot a\right)\right)\right) \cdot \left(\left(\left(-2 \cdot \left(c \cdot a\right)\right) \cdot -0.5\right) \cdot \left(2 \cdot \left(c \cdot a\right)\right)\right)}\right)}{a} + \left(-0.5 \cdot \left(c \cdot \left({\left(\frac{1}{b}\right)}^{5} \cdot {\left(-2 \cdot \left(c \cdot a\right)\right)}^{2}\right)\right) + -0.25 \cdot \frac{{b}^{-3} \cdot {\left(-2 \cdot \left(c \cdot a\right)\right)}^{2}}{a}\right)\right) \]

Alternatives

Alternative 1
Error7.3
Cost28100
\[\begin{array}{l} t_0 := {\left(-2 \cdot \left(c \cdot a\right)\right)}^{2}\\ \mathbf{if}\;b \leq 15:\\ \;\;\;\;\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)} - b}{2}}{a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b} + \left(-0.5 \cdot \left(c \cdot \left({\left(\frac{1}{b}\right)}^{5} \cdot t_0\right)\right) + -0.25 \cdot \frac{{\left(\frac{1}{b}\right)}^{3} \cdot t_0}{a}\right)\\ \end{array} \]
Alternative 2
Error9.8
Cost27848
\[\begin{array}{l} \mathbf{if}\;b \leq 21.5:\\ \;\;\;\;\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)} - b}{2}}{a}\\ \mathbf{elif}\;\frac{b \cdot -0.5}{a} \ne 0:\\ \;\;\;\;\frac{\left(-c\right) + -0.25 \cdot \left(a \cdot {\left(\frac{-2 \cdot c}{\left|b\right|}\right)}^{2}\right)}{\left|b\right|} + -0.5 \cdot \frac{\left(1 - \frac{\left|b\right|}{b}\right) \cdot b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\sqrt{\mathsf{fma}\left(a \cdot -4, c, {b}^{2}\right)} - b}{2}}{a}\\ \end{array} \]
Alternative 3
Error9.7
Cost14020
\[\begin{array}{l} \mathbf{if}\;b \leq 21.5:\\ \;\;\;\;\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)} - b}{2}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.25 \cdot \frac{{\left(-2 \cdot \left(c \cdot a\right)\right)}^{2}}{{b}^{3}}}{a} - \frac{c}{b}\\ \end{array} \]
Alternative 4
Error16.9
Cost13764
\[\begin{array}{l} \mathbf{if}\;b \leq 1980:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{\mathsf{fma}\left(a \cdot -4, c, b \cdot b\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 5
Error16.8
Cost13764
\[\begin{array}{l} \mathbf{if}\;b \leq 1980:\\ \;\;\;\;\frac{\frac{\sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)} - b}{2}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 6
Error16.9
Cost7556
\[\begin{array}{l} \mathbf{if}\;b \leq 1980:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 7
Error22.9
Cost256
\[\frac{-c}{b} \]

Error

Reproduce?

herbie shell --seed 2023033 
(FPCore (a b c)
  :name "Quadratic roots, narrow range"
  :precision binary64
  :pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))