?

Average Error: 34.0 → 10.5
Time: 24.9s
Precision: binary64
Cost: 7688

?

\[\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 -1.15 \cdot 10^{+73}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 3.3 \cdot 10^{-25}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot 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 -1.15e+73)
   (/ (* b -2.0) (* 3.0 a))
   (if (<= b 3.3e-25)
     (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 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 <= -1.15e+73) {
		tmp = (b * -2.0) / (3.0 * a);
	} else if (b <= 3.3e-25) {
		tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (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 <= (-1.15d+73)) then
        tmp = (b * (-2.0d0)) / (3.0d0 * a)
    else if (b <= 3.3d-25) then
        tmp = (-b + sqrt(((b * b) - ((3.0d0 * a) * c)))) / (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 <= -1.15e+73) {
		tmp = (b * -2.0) / (3.0 * a);
	} else if (b <= 3.3e-25) {
		tmp = (-b + Math.sqrt(((b * b) - ((3.0 * a) * c)))) / (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 <= -1.15e+73:
		tmp = (b * -2.0) / (3.0 * a)
	elif b <= 3.3e-25:
		tmp = (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (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 <= -1.15e+73)
		tmp = Float64(Float64(b * -2.0) / Float64(3.0 * a));
	elseif (b <= 3.3e-25)
		tmp = Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a));
	else
		tmp = Float64(Float64(-0.5 * 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 <= -1.15e+73)
		tmp = (b * -2.0) / (3.0 * a);
	elseif (b <= 3.3e-25)
		tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (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, -1.15e+73], N[(N[(b * -2.0), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.3e-25], 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], N[(N[(-0.5 * c), $MachinePrecision] / b), $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 -1.15 \cdot 10^{+73}:\\
\;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot 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 < -1.15e73

    1. Initial program 42.2

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

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

      [Start]42.2

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

      rational_best-simplify-2 [=>]42.2

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

      rational_best-simplify-44 [=>]42.2

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

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

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

      [Start]4.7

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

      rational_best-simplify-2 [=>]4.7

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

    if -1.15e73 < b < 3.2999999999999998e-25

    1. Initial program 15.5

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

    if 3.2999999999999998e-25 < b

    1. Initial program 54.6

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b}} \]
    3. Applied egg-rr6.7

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

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

Alternatives

Alternative 1
Error10.7
Cost7688
\[\begin{array}{l} \mathbf{if}\;b \leq -3.8 \cdot 10^{+48}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 4.2 \cdot 10^{-25}:\\ \;\;\;\;\frac{0.3333333333333333}{a} \cdot \left(\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} + \left(-b\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
Alternative 2
Error10.5
Cost7688
\[\begin{array}{l} \mathbf{if}\;b \leq -1.15 \cdot 10^{+73}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 6.8 \cdot 10^{-25}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 3 \cdot \left(c \cdot a\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
Alternative 3
Error14.0
Cost7432
\[\begin{array}{l} \mathbf{if}\;b \leq -4.4 \cdot 10^{-84}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 3.3 \cdot 10^{-25}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{-3 \cdot \left(c \cdot a\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
Alternative 4
Error14.0
Cost7432
\[\begin{array}{l} \mathbf{if}\;b \leq -2.8 \cdot 10^{-85}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 1.75 \cdot 10^{-25}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -3\right)} + \left(-b\right)}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
Alternative 5
Error20.0
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -4.5 \cdot 10^{-137}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 3.3 \cdot 10^{-180}:\\ \;\;\;\;0.3333333333333333 \cdot \sqrt{c \cdot \frac{-2}{a} - \frac{c}{a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
Alternative 6
Error20.0
Cost7112
\[\begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{-139}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 1.2 \cdot 10^{-180}:\\ \;\;\;\;0.3333333333333333 \cdot \sqrt{-3 \cdot \frac{c}{a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
Alternative 7
Error20.0
Cost7112
\[\begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{-139}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{elif}\;b \leq 3.3 \cdot 10^{-180}:\\ \;\;\;\;\sqrt{c \cdot \frac{-3}{a}} \cdot 0.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
Alternative 8
Error23.0
Cost580
\[\begin{array}{l} \mathbf{if}\;b \leq 2.5 \cdot 10^{-217}:\\ \;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
Alternative 9
Error23.0
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 9 \cdot 10^{-217}:\\ \;\;\;\;b \cdot \frac{-0.6666666666666666}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 10
Error23.0
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 1.65 \cdot 10^{-217}:\\ \;\;\;\;\frac{-0.6666666666666666}{\frac{a}{b}}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 11
Error23.0
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 2.5 \cdot 10^{-217}:\\ \;\;\;\;\frac{-0.6666666666666666}{\frac{a}{b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot c}{b}\\ \end{array} \]
Alternative 12
Error39.9
Cost320
\[-0.5 \cdot \frac{c}{b} \]

Error

Reproduce?

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