?

Average Error: 33.8 → 10.7
Time: 8.3s
Precision: binary64
Cost: 7624

?

\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
\[\begin{array}{l} \mathbf{if}\;b \leq -5.5 \cdot 10^{+126}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 3 \cdot 10^{-134}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c)
 :precision binary64
 (if (<= b -5.5e+126)
   (/ (* b -2.0) (* 3.0 a))
   (if (<= b 3e-134)
     (/ (- (sqrt (+ (* b b) (* c (* a -3.0)))) b) (* 3.0 a))
     (* -0.5 (/ c b)))))
double code(double a, double b, double c) {
	return (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
double code(double a, double b, double c) {
	double tmp;
	if (b <= -5.5e+126) {
		tmp = (b * -2.0) / (3.0 * a);
	} else if (b <= 3e-134) {
		tmp = (sqrt(((b * b) + (c * (a * -3.0)))) - b) / (3.0 * a);
	} else {
		tmp = -0.5 * (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) - ((3.0d0 * a) * c)))) / (3.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) :: tmp
    if (b <= (-5.5d+126)) then
        tmp = (b * (-2.0d0)) / (3.0d0 * a)
    else if (b <= 3d-134) then
        tmp = (sqrt(((b * b) + (c * (a * (-3.0d0))))) - b) / (3.0d0 * a)
    else
        tmp = (-0.5d0) * (c / b)
    end if
    code = tmp
end function
public static double code(double a, double b, double c) {
	return (-b + Math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
public static double code(double a, double b, double c) {
	double tmp;
	if (b <= -5.5e+126) {
		tmp = (b * -2.0) / (3.0 * a);
	} else if (b <= 3e-134) {
		tmp = (Math.sqrt(((b * b) + (c * (a * -3.0)))) - b) / (3.0 * a);
	} else {
		tmp = -0.5 * (c / b);
	}
	return tmp;
}
def code(a, b, c):
	return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
def code(a, b, c):
	tmp = 0
	if b <= -5.5e+126:
		tmp = (b * -2.0) / (3.0 * a)
	elif b <= 3e-134:
		tmp = (math.sqrt(((b * b) + (c * (a * -3.0)))) - b) / (3.0 * a)
	else:
		tmp = -0.5 * (c / b)
	return tmp
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a))
end
function code(a, b, c)
	tmp = 0.0
	if (b <= -5.5e+126)
		tmp = Float64(Float64(b * -2.0) / Float64(3.0 * a));
	elseif (b <= 3e-134)
		tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -3.0)))) - b) / Float64(3.0 * a));
	else
		tmp = Float64(-0.5 * Float64(c / b));
	end
	return tmp
end
function tmp = code(a, b, c)
	tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
end
function tmp_2 = code(a, b, c)
	tmp = 0.0;
	if (b <= -5.5e+126)
		tmp = (b * -2.0) / (3.0 * a);
	elseif (b <= 3e-134)
		tmp = (sqrt(((b * b) + (c * (a * -3.0)))) - b) / (3.0 * a);
	else
		tmp = -0.5 * (c / b);
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := If[LessEqual[b, -5.5e+126], N[(N[(b * -2.0), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3e-134], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -5.5 \cdot 10^{+126}:\\
\;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\

\mathbf{elif}\;b \leq 3 \cdot 10^{-134}:\\
\;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{3 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \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 < -5.5000000000000004e126

    1. Initial program 54.9

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

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

      [Start]54.9

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

      rational_best-simplify-62 [=>]54.9

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

      rational_best-simplify-51 [=>]54.9

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

      rational_best-simplify-61 [=>]54.9

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

      rational_best-simplify-52 [=>]54.9

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

      rational_best-simplify-52 [=>]54.9

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

      metadata-eval [=>]54.9

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

      \[\leadsto \frac{\color{blue}{-2 \cdot b}}{3 \cdot a} \]
    4. Simplified3.4

      \[\leadsto \frac{\color{blue}{b \cdot -2}}{3 \cdot a} \]
      Proof

      [Start]3.4

      \[ \frac{-2 \cdot b}{3 \cdot a} \]

      rational_best-simplify-3 [=>]3.4

      \[ \frac{\color{blue}{b \cdot -2}}{3 \cdot a} \]

    if -5.5000000000000004e126 < b < 3e-134

    1. Initial program 10.7

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

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

      [Start]10.7

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

      rational_best-simplify-62 [=>]10.7

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

      rational_best-simplify-51 [=>]10.7

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

      rational_best-simplify-61 [=>]10.7

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

      rational_best-simplify-52 [=>]10.7

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

      rational_best-simplify-52 [=>]10.7

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

      metadata-eval [=>]10.7

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

    if 3e-134 < b

    1. Initial program 50.1

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

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

      [Start]50.1

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

      rational_best-simplify-62 [=>]50.1

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

      rational_best-simplify-51 [=>]50.1

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

      rational_best-simplify-61 [=>]50.1

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

      rational_best-simplify-52 [=>]50.1

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

      rational_best-simplify-52 [=>]50.1

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

      metadata-eval [=>]50.1

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification10.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -5.5 \cdot 10^{+126}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 3 \cdot 10^{-134}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]

Alternatives

Alternative 1
Error14.8
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -1.05 \cdot 10^{-154}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 4.9 \cdot 10^{-135}:\\ \;\;\;\;\frac{\sqrt{-3 \cdot \left(c \cdot a\right)} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 2
Error14.8
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -1.05 \cdot 10^{-154}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 3 \cdot 10^{-134}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -3\right)} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 3
Error15.0
Cost7240
\[\begin{array}{l} \mathbf{if}\;b \leq -4.4 \cdot 10^{-159}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 1.05 \cdot 10^{-134}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -3\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 4
Error14.9
Cost7240
\[\begin{array}{l} \mathbf{if}\;b \leq -8.8 \cdot 10^{-156}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 8 \cdot 10^{-136}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -3\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 5
Error20.2
Cost7112
\[\begin{array}{l} \mathbf{if}\;b \leq -2.8 \cdot 10^{-165}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 10^{-168}:\\ \;\;\;\;0.3333333333333333 \cdot \sqrt{\frac{c}{a} \cdot -3}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 6
Error22.9
Cost580
\[\begin{array}{l} \mathbf{if}\;b \leq 5.2 \cdot 10^{-301}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 7
Error37.0
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 9.8 \cdot 10^{-301}:\\ \;\;\;\;-0.3333333333333333 \cdot \frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 8
Error22.9
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 7.8 \cdot 10^{-301}:\\ \;\;\;\;\frac{b}{a} \cdot -0.6666666666666666\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 9
Error40.3
Cost320
\[-0.5 \cdot \frac{c}{b} \]

Error

Reproduce?

herbie shell --seed 2023104 
(FPCore (a b c)
  :name "Cubic critical"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))