?

Average Error: 52.3 → 0.4
Time: 7.8s
Precision: binary64
Cost: 22276

?

\[\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} \]
\[\begin{array}{l} t_0 := \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}\\ t_1 := \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\\ \frac{\begin{array}{l} \mathbf{if}\;b + t_0 \ne 0:\\ \;\;\;\;\frac{a \cdot \left(-4 \cdot c\right)}{\frac{\left(-b\right) - \left(b + \left(t_1 + t_1\right)\right)}{-2}}\\ \mathbf{else}:\\ \;\;\;\;t_0 - b\\ \end{array}}{a \cdot 2} \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 (sqrt (+ (* b b) (* a (* c -4.0)))))
        (t_1 (sqrt (- (* b b) (* a (* c 4.0))))))
   (/
    (if (!= (+ b t_0) 0.0)
      (/ (* a (* -4.0 c)) (/ (- (- b) (+ b (+ t_1 t_1))) -2.0))
      (- t_0 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) {
	double t_0 = sqrt(((b * b) + (a * (c * -4.0))));
	double t_1 = sqrt(((b * b) - (a * (c * 4.0))));
	double tmp;
	if ((b + t_0) != 0.0) {
		tmp = (a * (-4.0 * c)) / ((-b - (b + (t_1 + t_1))) / -2.0);
	} else {
		tmp = t_0 - b;
	}
	return tmp / (a * 2.0);
}
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) :: tmp
    t_0 = sqrt(((b * b) + (a * (c * (-4.0d0)))))
    t_1 = sqrt(((b * b) - (a * (c * 4.0d0))))
    if ((b + t_0) /= 0.0d0) then
        tmp = (a * ((-4.0d0) * c)) / ((-b - (b + (t_1 + t_1))) / (-2.0d0))
    else
        tmp = t_0 - b
    end if
    code = tmp / (a * 2.0d0)
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 = Math.sqrt(((b * b) + (a * (c * -4.0))));
	double t_1 = Math.sqrt(((b * b) - (a * (c * 4.0))));
	double tmp;
	if ((b + t_0) != 0.0) {
		tmp = (a * (-4.0 * c)) / ((-b - (b + (t_1 + t_1))) / -2.0);
	} else {
		tmp = t_0 - b;
	}
	return tmp / (a * 2.0);
}
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 = math.sqrt(((b * b) + (a * (c * -4.0))))
	t_1 = math.sqrt(((b * b) - (a * (c * 4.0))))
	tmp = 0
	if (b + t_0) != 0.0:
		tmp = (a * (-4.0 * c)) / ((-b - (b + (t_1 + t_1))) / -2.0)
	else:
		tmp = t_0 - b
	return tmp / (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)
	t_0 = sqrt(Float64(Float64(b * b) + Float64(a * Float64(c * -4.0))))
	t_1 = sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))
	tmp = 0.0
	if (Float64(b + t_0) != 0.0)
		tmp = Float64(Float64(a * Float64(-4.0 * c)) / Float64(Float64(Float64(-b) - Float64(b + Float64(t_1 + t_1))) / -2.0));
	else
		tmp = Float64(t_0 - b);
	end
	return Float64(tmp / Float64(a * 2.0))
end
function tmp = code(a, b, c)
	tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
end
function tmp_2 = code(a, b, c)
	t_0 = sqrt(((b * b) + (a * (c * -4.0))));
	t_1 = sqrt(((b * b) - (a * (c * 4.0))));
	tmp = 0.0;
	if ((b + t_0) ~= 0.0)
		tmp = (a * (-4.0 * c)) / ((-b - (b + (t_1 + t_1))) / -2.0);
	else
		tmp = t_0 - b;
	end
	tmp_2 = tmp / (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_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(If[Unequal[N[(b + t$95$0), $MachinePrecision], 0.0], N[(N[(a * N[(-4.0 * c), $MachinePrecision]), $MachinePrecision] / N[(N[((-b) - N[(b + N[(t$95$1 + t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / -2.0), $MachinePrecision]), $MachinePrecision], N[(t$95$0 - b), $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}
\begin{array}{l}
t_0 := \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}\\
t_1 := \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\\
\frac{\begin{array}{l}
\mathbf{if}\;b + t_0 \ne 0:\\
\;\;\;\;\frac{a \cdot \left(-4 \cdot c\right)}{\frac{\left(-b\right) - \left(b + \left(t_1 + t_1\right)\right)}{-2}}\\

\mathbf{else}:\\
\;\;\;\;t_0 - b\\


\end{array}}{a \cdot 2}
\end{array}

Error?

Derivation?

  1. Initial program 52.3

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

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

    [Start]52.3

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

    rational_best-simplify-62 [=>]52.3

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

    rational_best-simplify-51 [=>]52.3

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

    rational_best-simplify-3 [=>]52.3

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

    rational_best-simplify-3 [=>]52.3

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

    rational_best-simplify-113 [=>]52.3

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

    rational_best-simplify-3 [=>]52.3

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

    \[\leadsto \frac{\color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} \ne 0:\\ \;\;\;\;\frac{\sqrt{\left(b \cdot b + a \cdot \left(c \cdot -4\right)\right) \cdot \left(b \cdot b + a \cdot \left(c \cdot -4\right)\right)} - b \cdot b}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b\\ } \end{array}}}{a \cdot 2} \]
  4. Taylor expanded in b around 0 0.4

    \[\leadsto \frac{\begin{array}{l} \mathbf{if}\;b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} \ne 0:\\ \;\;\;\;\frac{\color{blue}{-4 \cdot \left(c \cdot a\right)}}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b\\ \end{array}}{a \cdot 2} \]
  5. Simplified0.4

    \[\leadsto \frac{\begin{array}{l} \mathbf{if}\;b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} \ne 0:\\ \;\;\;\;\frac{\color{blue}{a \cdot \left(-4 \cdot c\right)}}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b\\ \end{array}}{a \cdot 2} \]
    Proof

    [Start]0.4

    \[ \frac{\begin{array}{l} \mathbf{if}\;b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} \ne 0:\\ \;\;\;\;\frac{-4 \cdot \left(c \cdot a\right)}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b\\ \end{array}}{a \cdot 2} \]

    rational_best-simplify-3 [=>]0.4

    \[ \frac{\begin{array}{l} \mathbf{if}\;b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} \ne 0:\\ \;\;\;\;\frac{-4 \cdot \color{blue}{\left(a \cdot c\right)}}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b\\ \end{array}}{a \cdot 2} \]

    rational_best-simplify-113 [=>]0.4

    \[ \frac{\begin{array}{l} \mathbf{if}\;b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} \ne 0:\\ \;\;\;\;\frac{\color{blue}{a \cdot \left(-4 \cdot c\right)}}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b\\ \end{array}}{a \cdot 2} \]
  6. Applied egg-rr0.4

    \[\leadsto \frac{\begin{array}{l} \mathbf{if}\;b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} \ne 0:\\ \;\;\;\;\frac{a \cdot \left(-4 \cdot c\right)}{\color{blue}{\frac{\left(-b\right) - \left(b + \left(\sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)} + \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\right)\right)}{-2}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b\\ \end{array}}{a \cdot 2} \]
  7. Final simplification0.4

    \[\leadsto \frac{\begin{array}{l} \mathbf{if}\;b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} \ne 0:\\ \;\;\;\;\frac{a \cdot \left(-4 \cdot c\right)}{\frac{\left(-b\right) - \left(b + \left(\sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)} + \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\right)\right)}{-2}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b\\ \end{array}}{a \cdot 2} \]

Alternatives

Alternative 1
Error5.9
Cost14852
\[\begin{array}{l} \mathbf{if}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \leq -0.004:\\ \;\;\;\;\frac{\sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
Alternative 2
Error0.4
Cost8004
\[\begin{array}{l} t_0 := \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}\\ \frac{\begin{array}{l} \mathbf{if}\;b \cdot 2 \ne 0:\\ \;\;\;\;\frac{a \cdot \left(-4 \cdot c\right)}{b + t_0}\\ \mathbf{else}:\\ \;\;\;\;t_0 - b\\ \end{array}}{a \cdot 2} \end{array} \]
Alternative 3
Error6.4
Cost256
\[-\frac{c}{b} \]

Error

Reproduce?

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