Average Error: 19.6 → 6.4
Time: 10.0s
Precision: binary64
\[\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array} \]
\[\begin{array}{l} t_0 := \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\\ t_1 := \left(-b\right) - b\\ t_2 := \frac{2 \cdot c}{\left(-b\right) - t_0}\\ t_3 := \frac{t_0 - b}{2 \cdot a}\\ \mathbf{if}\;b \leq -6.729379008114002 \cdot 10^{+152}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \leq 4.778234809810149 \cdot 10^{+105}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{t_1}\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
(FPCore (a b c)
 :precision binary64
 (if (>= b 0.0)
   (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))
   (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))))
(FPCore (a b c)
 :precision binary64
 (let* ((t_0 (sqrt (- (* b b) (* c (* 4.0 a)))))
        (t_1 (- (- b) b))
        (t_2 (/ (* 2.0 c) (- (- b) t_0)))
        (t_3 (/ (- t_0 b) (* 2.0 a))))
   (if (<= b -6.729379008114002e+152)
     (if (>= b 0.0) t_2 (/ t_1 (* 2.0 a)))
     (if (<= b 4.778234809810149e+105)
       (if (>= b 0.0) t_2 t_3)
       (if (>= b 0.0) (/ (* 2.0 c) t_1) t_3)))))
double code(double a, double b, double c) {
	double tmp;
	if (b >= 0.0) {
		tmp = (2.0 * c) / (-b - sqrt(((b * b) - ((4.0 * a) * c))));
	} else {
		tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
	}
	return tmp;
}
double code(double a, double b, double c) {
	double t_0 = sqrt(((b * b) - (c * (4.0 * a))));
	double t_1 = -b - b;
	double t_2 = (2.0 * c) / (-b - t_0);
	double t_3 = (t_0 - b) / (2.0 * a);
	double tmp_1;
	if (b <= -6.729379008114002e+152) {
		double tmp_2;
		if (b >= 0.0) {
			tmp_2 = t_2;
		} else {
			tmp_2 = t_1 / (2.0 * a);
		}
		tmp_1 = tmp_2;
	} else if (b <= 4.778234809810149e+105) {
		double tmp_3;
		if (b >= 0.0) {
			tmp_3 = t_2;
		} else {
			tmp_3 = t_3;
		}
		tmp_1 = tmp_3;
	} else if (b >= 0.0) {
		tmp_1 = (2.0 * c) / t_1;
	} else {
		tmp_1 = t_3;
	}
	return tmp_1;
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b >= 0.0d0) then
        tmp = (2.0d0 * c) / (-b - sqrt(((b * b) - ((4.0d0 * a) * c))))
    else
        tmp = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
    end if
    code = tmp
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
    real(8) :: tmp
    real(8) :: tmp_1
    real(8) :: tmp_2
    real(8) :: tmp_3
    t_0 = sqrt(((b * b) - (c * (4.0d0 * a))))
    t_1 = -b - b
    t_2 = (2.0d0 * c) / (-b - t_0)
    t_3 = (t_0 - b) / (2.0d0 * a)
    if (b <= (-6.729379008114002d+152)) then
        if (b >= 0.0d0) then
            tmp_2 = t_2
        else
            tmp_2 = t_1 / (2.0d0 * a)
        end if
        tmp_1 = tmp_2
    else if (b <= 4.778234809810149d+105) then
        if (b >= 0.0d0) then
            tmp_3 = t_2
        else
            tmp_3 = t_3
        end if
        tmp_1 = tmp_3
    else if (b >= 0.0d0) then
        tmp_1 = (2.0d0 * c) / t_1
    else
        tmp_1 = t_3
    end if
    code = tmp_1
end function
public static double code(double a, double b, double c) {
	double tmp;
	if (b >= 0.0) {
		tmp = (2.0 * c) / (-b - Math.sqrt(((b * b) - ((4.0 * a) * c))));
	} else {
		tmp = (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
	}
	return tmp;
}
public static double code(double a, double b, double c) {
	double t_0 = Math.sqrt(((b * b) - (c * (4.0 * a))));
	double t_1 = -b - b;
	double t_2 = (2.0 * c) / (-b - t_0);
	double t_3 = (t_0 - b) / (2.0 * a);
	double tmp_1;
	if (b <= -6.729379008114002e+152) {
		double tmp_2;
		if (b >= 0.0) {
			tmp_2 = t_2;
		} else {
			tmp_2 = t_1 / (2.0 * a);
		}
		tmp_1 = tmp_2;
	} else if (b <= 4.778234809810149e+105) {
		double tmp_3;
		if (b >= 0.0) {
			tmp_3 = t_2;
		} else {
			tmp_3 = t_3;
		}
		tmp_1 = tmp_3;
	} else if (b >= 0.0) {
		tmp_1 = (2.0 * c) / t_1;
	} else {
		tmp_1 = t_3;
	}
	return tmp_1;
}
def code(a, b, c):
	tmp = 0
	if b >= 0.0:
		tmp = (2.0 * c) / (-b - math.sqrt(((b * b) - ((4.0 * a) * c))))
	else:
		tmp = (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
	return tmp
def code(a, b, c):
	t_0 = math.sqrt(((b * b) - (c * (4.0 * a))))
	t_1 = -b - b
	t_2 = (2.0 * c) / (-b - t_0)
	t_3 = (t_0 - b) / (2.0 * a)
	tmp_1 = 0
	if b <= -6.729379008114002e+152:
		tmp_2 = 0
		if b >= 0.0:
			tmp_2 = t_2
		else:
			tmp_2 = t_1 / (2.0 * a)
		tmp_1 = tmp_2
	elif b <= 4.778234809810149e+105:
		tmp_3 = 0
		if b >= 0.0:
			tmp_3 = t_2
		else:
			tmp_3 = t_3
		tmp_1 = tmp_3
	elif b >= 0.0:
		tmp_1 = (2.0 * c) / t_1
	else:
		tmp_1 = t_3
	return tmp_1
function code(a, b, c)
	tmp = 0.0
	if (b >= 0.0)
		tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))));
	else
		tmp = Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a));
	end
	return tmp
end
function code(a, b, c)
	t_0 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a))))
	t_1 = Float64(Float64(-b) - b)
	t_2 = Float64(Float64(2.0 * c) / Float64(Float64(-b) - t_0))
	t_3 = Float64(Float64(t_0 - b) / Float64(2.0 * a))
	tmp_1 = 0.0
	if (b <= -6.729379008114002e+152)
		tmp_2 = 0.0
		if (b >= 0.0)
			tmp_2 = t_2;
		else
			tmp_2 = Float64(t_1 / Float64(2.0 * a));
		end
		tmp_1 = tmp_2;
	elseif (b <= 4.778234809810149e+105)
		tmp_3 = 0.0
		if (b >= 0.0)
			tmp_3 = t_2;
		else
			tmp_3 = t_3;
		end
		tmp_1 = tmp_3;
	elseif (b >= 0.0)
		tmp_1 = Float64(Float64(2.0 * c) / t_1);
	else
		tmp_1 = t_3;
	end
	return tmp_1
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b >= 0.0)
		tmp = (2.0 * c) / (-b - sqrt(((b * b) - ((4.0 * a) * c))));
	else
		tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
	end
	tmp_2 = tmp;
end
function tmp_5 = code(a, b, c)
	t_0 = sqrt(((b * b) - (c * (4.0 * a))));
	t_1 = -b - b;
	t_2 = (2.0 * c) / (-b - t_0);
	t_3 = (t_0 - b) / (2.0 * a);
	tmp_2 = 0.0;
	if (b <= -6.729379008114002e+152)
		tmp_3 = 0.0;
		if (b >= 0.0)
			tmp_3 = t_2;
		else
			tmp_3 = t_1 / (2.0 * a);
		end
		tmp_2 = tmp_3;
	elseif (b <= 4.778234809810149e+105)
		tmp_4 = 0.0;
		if (b >= 0.0)
			tmp_4 = t_2;
		else
			tmp_4 = t_3;
		end
		tmp_2 = tmp_4;
	elseif (b >= 0.0)
		tmp_2 = (2.0 * c) / t_1;
	else
		tmp_2 = t_3;
	end
	tmp_5 = tmp_2;
end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[((-b) - b), $MachinePrecision]}, Block[{t$95$2 = N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(t$95$0 - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -6.729379008114002e+152], If[GreaterEqual[b, 0.0], t$95$2, N[(t$95$1 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 4.778234809810149e+105], If[GreaterEqual[b, 0.0], t$95$2, t$95$3], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / t$95$1), $MachinePrecision], t$95$3]]]]]]]
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\


\end{array}
\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\\
t_1 := \left(-b\right) - b\\
t_2 := \frac{2 \cdot c}{\left(-b\right) - t_0}\\
t_3 := \frac{t_0 - b}{2 \cdot a}\\
\mathbf{if}\;b \leq -6.729379008114002 \cdot 10^{+152}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;\frac{t_1}{2 \cdot a}\\


\end{array}\\

\mathbf{elif}\;b \leq 4.778234809810149 \cdot 10^{+105}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;t_3\\


\end{array}\\

\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{t_1}\\

\mathbf{else}:\\
\;\;\;\;t_3\\


\end{array}

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

Derivation

  1. Split input into 3 regimes
  2. if b < -6.72937900811400207e152

    1. Initial program 63.6

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

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

    if -6.72937900811400207e152 < b < 4.7782348098101495e105

    1. Initial program 8.6

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

    if 4.7782348098101495e105 < b

    1. Initial program 31.4

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification6.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -6.729379008114002 \cdot 10^{+152}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \leq 4.778234809810149 \cdot 10^{+105}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{elif}\;b \geq 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\ \end{array} \]

Reproduce

herbie shell --seed 2022134 
(FPCore (a b c)
  :name "jeff quadratic root 2"
  :precision binary64
  (if (>= b 0.0) (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))))