?

Average Error: 33.8 → 9.6
Time: 1.2min
Precision: binary64
Cost: 15048

?

\[\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 - 4 \cdot \left(a \cdot c\right)}\\ \mathbf{if}\;b \leq -8.5 \cdot 10^{+85}:\\ \;\;\;\;\frac{c}{b} + \frac{-b}{a}\\ \mathbf{elif}\;b \leq 5.5 \cdot 10^{-36}:\\ \;\;\;\;\frac{t_0}{4 \cdot a} - \frac{b + \left(b - t_0\right)}{4 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \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) (* 4.0 (* a c))))))
   (if (<= b -8.5e+85)
     (+ (/ c b) (/ (- b) a))
     (if (<= b 5.5e-36)
       (- (/ t_0 (* 4.0 a)) (/ (+ b (- b t_0)) (* 4.0 a)))
       (- (/ c b))))))
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) - (4.0 * (a * c))));
	double tmp;
	if (b <= -8.5e+85) {
		tmp = (c / b) + (-b / a);
	} else if (b <= 5.5e-36) {
		tmp = (t_0 / (4.0 * a)) - ((b + (b - t_0)) / (4.0 * a));
	} else {
		tmp = -(c / b);
	}
	return tmp;
}
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) :: tmp
    t_0 = sqrt(((b * b) - (4.0d0 * (a * c))))
    if (b <= (-8.5d+85)) then
        tmp = (c / b) + (-b / a)
    else if (b <= 5.5d-36) then
        tmp = (t_0 / (4.0d0 * a)) - ((b + (b - t_0)) / (4.0d0 * a))
    else
        tmp = -(c / b)
    end if
    code = tmp
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) - (4.0 * (a * c))));
	double tmp;
	if (b <= -8.5e+85) {
		tmp = (c / b) + (-b / a);
	} else if (b <= 5.5e-36) {
		tmp = (t_0 / (4.0 * a)) - ((b + (b - t_0)) / (4.0 * a));
	} else {
		tmp = -(c / b);
	}
	return tmp;
}
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) - (4.0 * (a * c))))
	tmp = 0
	if b <= -8.5e+85:
		tmp = (c / b) + (-b / a)
	elif b <= 5.5e-36:
		tmp = (t_0 / (4.0 * a)) - ((b + (b - t_0)) / (4.0 * a))
	else:
		tmp = -(c / b)
	return tmp
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(4.0 * Float64(a * c))))
	tmp = 0.0
	if (b <= -8.5e+85)
		tmp = Float64(Float64(c / b) + Float64(Float64(-b) / a));
	elseif (b <= 5.5e-36)
		tmp = Float64(Float64(t_0 / Float64(4.0 * a)) - Float64(Float64(b + Float64(b - t_0)) / Float64(4.0 * a)));
	else
		tmp = Float64(-Float64(c / b));
	end
	return tmp
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) - (4.0 * (a * c))));
	tmp = 0.0;
	if (b <= -8.5e+85)
		tmp = (c / b) + (-b / a);
	elseif (b <= 5.5e-36)
		tmp = (t_0 / (4.0 * a)) - ((b + (b - t_0)) / (4.0 * a));
	else
		tmp = -(c / b);
	end
	tmp_2 = tmp;
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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -8.5e+85], N[(N[(c / b), $MachinePrecision] + N[((-b) / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.5e-36], N[(N[(t$95$0 / N[(4.0 * a), $MachinePrecision]), $MachinePrecision] - N[(N[(b + N[(b - t$95$0), $MachinePrecision]), $MachinePrecision] / N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[(c / b), $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 - 4 \cdot \left(a \cdot c\right)}\\
\mathbf{if}\;b \leq -8.5 \cdot 10^{+85}:\\
\;\;\;\;\frac{c}{b} + \frac{-b}{a}\\

\mathbf{elif}\;b \leq 5.5 \cdot 10^{-36}:\\
\;\;\;\;\frac{t_0}{4 \cdot a} - \frac{b + \left(b - t_0\right)}{4 \cdot a}\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 3 regimes
  2. if b < -8.4999999999999994e85

    1. Initial program 43.9

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

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

      [Start]43.9

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

      rational_best-simplify-3 [=>]43.9

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

      rational_best-simplify-9 [<=]43.9

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

      rational_best-simplify-56 [=>]43.9

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

      rational_best-simplify-6 [=>]43.9

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

      rational_best-simplify-1 [=>]43.9

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

      \[\leadsto \color{blue}{\frac{c}{b} + -1 \cdot \frac{b}{a}} \]
    4. Simplified4.1

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

      [Start]4.1

      \[ \frac{c}{b} + -1 \cdot \frac{b}{a} \]

      rational_best-simplify-1 [=>]4.1

      \[ \frac{c}{b} + \color{blue}{\frac{b}{a} \cdot -1} \]

      rational_best-simplify-10 [=>]4.1

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

      rational_best-simplify-12 [<=]4.1

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

      rational_best-simplify-49 [<=]4.1

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

      rational_best-simplify-13 [<=]4.1

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

    if -8.4999999999999994e85 < b < 5.49999999999999984e-36

    1. Initial program 14.1

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

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

      [Start]14.1

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

      rational_best-simplify-3 [=>]14.1

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

      rational_best-simplify-9 [<=]14.1

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

      rational_best-simplify-56 [=>]14.1

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

      rational_best-simplify-6 [=>]14.1

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

      rational_best-simplify-1 [=>]14.1

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

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

    if 5.49999999999999984e-36 < b

    1. Initial program 55.1

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

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

      [Start]55.1

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

      rational_best-simplify-3 [=>]55.1

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

      rational_best-simplify-9 [<=]55.1

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

      rational_best-simplify-56 [=>]55.1

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

      rational_best-simplify-6 [=>]55.1

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

      rational_best-simplify-1 [=>]55.1

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    4. Simplified6.3

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

      [Start]6.3

      \[ -1 \cdot \frac{c}{b} \]

      rational_best-simplify-1 [=>]6.3

      \[ \color{blue}{\frac{c}{b} \cdot -1} \]

      rational_best-simplify-10 [=>]6.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -8.5 \cdot 10^{+85}:\\ \;\;\;\;\frac{c}{b} + \frac{-b}{a}\\ \mathbf{elif}\;b \leq 5.5 \cdot 10^{-36}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{4 \cdot a} - \frac{b + \left(b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}{4 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]

Alternatives

Alternative 1
Error9.5
Cost8520
\[\begin{array}{l} \mathbf{if}\;b \leq -3.5 \cdot 10^{+106}:\\ \;\;\;\;\frac{c}{b} + \frac{-b}{a}\\ \mathbf{elif}\;b \leq 5 \cdot 10^{-36}:\\ \;\;\;\;\left(\frac{4 \cdot \sqrt{b \cdot b + \frac{a \cdot c}{-0.25}} - b}{a \cdot 8} - \frac{b}{a \cdot 8}\right) - \frac{b}{4 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
Alternative 2
Error9.5
Cost7752
\[\begin{array}{l} \mathbf{if}\;b \leq -7.2 \cdot 10^{+134}:\\ \;\;\;\;\frac{c}{b} + \frac{-b}{a}\\ \mathbf{elif}\;b \leq 2.5 \cdot 10^{-34}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}}{a} - \frac{b}{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
Alternative 3
Error9.6
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -6.5 \cdot 10^{+101}:\\ \;\;\;\;\frac{c}{b} + \frac{-b}{a}\\ \mathbf{elif}\;b \leq 1.85 \cdot 10^{-34}:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
Alternative 4
Error9.4
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -3.4 \cdot 10^{+134}:\\ \;\;\;\;\frac{c}{b} + \frac{-b}{a}\\ \mathbf{elif}\;b \leq 2.2 \cdot 10^{-35}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
Alternative 5
Error12.9
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -2.05 \cdot 10^{-73}:\\ \;\;\;\;\frac{c}{b} + \frac{-b}{a}\\ \mathbf{elif}\;b \leq 3.8 \cdot 10^{-36}:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{c \cdot \left(a \cdot -4\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
Alternative 6
Error13.1
Cost7240
\[\begin{array}{l} \mathbf{if}\;b \leq -1.55 \cdot 10^{-76}:\\ \;\;\;\;\frac{c}{b} + \frac{-b}{a}\\ \mathbf{elif}\;b \leq 7.5 \cdot 10^{-36}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
Alternative 7
Error19.5
Cost7112
\[\begin{array}{l} \mathbf{if}\;b \leq -1 \cdot 10^{-114}:\\ \;\;\;\;\frac{c}{b} + \frac{-b}{a}\\ \mathbf{elif}\;b \leq 5 \cdot 10^{-103}:\\ \;\;\;\;0.5 \cdot \sqrt{c \cdot \frac{-4}{a}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
Alternative 8
Error22.4
Cost644
\[\begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\frac{c}{b} + \frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
Alternative 9
Error22.4
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq 2.4 \cdot 10^{-271}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
Alternative 10
Error40.0
Cost256
\[-\frac{c}{b} \]
Alternative 11
Error56.4
Cost64
\[0 \]

Error

Reproduce?

herbie shell --seed 2023099 
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))