?

Average Error: 34.6 → 10.3
Time: 27.3s
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.22 \cdot 10^{+153}:\\ \;\;\;\;\frac{b}{a} \cdot -0.6666666666666666 + 0.5 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \leq 1.7 \cdot 10^{-34}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{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 -1.22e+153)
   (+ (* (/ b a) -0.6666666666666666) (* 0.5 (/ c b)))
   (if (<= b 1.7e-34)
     (/ (+ (- 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.22e+153) {
		tmp = ((b / a) * -0.6666666666666666) + (0.5 * (c / b));
	} else if (b <= 1.7e-34) {
		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.22d+153)) then
        tmp = ((b / a) * (-0.6666666666666666d0)) + (0.5d0 * (c / b))
    else if (b <= 1.7d-34) 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.22e+153) {
		tmp = ((b / a) * -0.6666666666666666) + (0.5 * (c / b));
	} else if (b <= 1.7e-34) {
		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.22e+153:
		tmp = ((b / a) * -0.6666666666666666) + (0.5 * (c / b))
	elif b <= 1.7e-34:
		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.22e+153)
		tmp = Float64(Float64(Float64(b / a) * -0.6666666666666666) + Float64(0.5 * Float64(c / b)));
	elseif (b <= 1.7e-34)
		tmp = Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / 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 <= -1.22e+153)
		tmp = ((b / a) * -0.6666666666666666) + (0.5 * (c / b));
	elseif (b <= 1.7e-34)
		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.22e+153], N[(N[(N[(b / a), $MachinePrecision] * -0.6666666666666666), $MachinePrecision] + N[(0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.7e-34], 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[(-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 -1.22 \cdot 10^{+153}:\\
\;\;\;\;\frac{b}{a} \cdot -0.6666666666666666 + 0.5 \cdot \frac{c}{b}\\

\mathbf{elif}\;b \leq 1.7 \cdot 10^{-34}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{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 < -1.22000000000000007e153

    1. Initial program 63.2

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

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

      [Start]63.2

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

      rational.json-simplify-2 [=>]63.2

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

      rational.json-simplify-2 [=>]63.2

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

      rational.json-simplify-43 [=>]63.2

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

      \[\leadsto \color{blue}{-0.6666666666666666 \cdot \frac{b}{a} + 0.5 \cdot \frac{c}{b}} \]
    4. Simplified2.7

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

      [Start]2.7

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

      rational.json-simplify-2 [=>]2.7

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

    if -1.22000000000000007e153 < b < 1.7e-34

    1. Initial program 14.1

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

    if 1.7e-34 < b

    1. Initial program 55.1

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

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

      [Start]55.1

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

      rational.json-simplify-2 [=>]55.1

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

      rational.json-simplify-2 [=>]55.1

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

      rational.json-simplify-43 [=>]55.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.22 \cdot 10^{+153}:\\ \;\;\;\;\frac{b}{a} \cdot -0.6666666666666666 + 0.5 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \leq 1.7 \cdot 10^{-34}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]

Alternatives

Alternative 1
Error10.3
Cost7688
\[\begin{array}{l} \mathbf{if}\;b \leq -1.9 \cdot 10^{+153}:\\ \;\;\;\;\frac{b}{a} \cdot -0.6666666666666666 + 0.5 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \leq 1.05 \cdot 10^{-34}:\\ \;\;\;\;\frac{0.3333333333333333}{a} \cdot \left(\sqrt{b \cdot b - 3 \cdot \left(a \cdot c\right)} + \left(-b\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 2
Error10.3
Cost7688
\[\begin{array}{l} \mathbf{if}\;b \leq -3.7 \cdot 10^{+153}:\\ \;\;\;\;\frac{b}{a} \cdot -0.6666666666666666 + 0.5 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \leq 2.2 \cdot 10^{-36}:\\ \;\;\;\;\frac{0.3333333333333333}{a} \cdot \left(\sqrt{b \cdot b - a \cdot \left(3 \cdot c\right)} + \left(-b\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 3
Error10.3
Cost7688
\[\begin{array}{l} \mathbf{if}\;b \leq -1.4 \cdot 10^{+153}:\\ \;\;\;\;\frac{b}{a} \cdot -0.6666666666666666 + 0.5 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \leq 2.2 \cdot 10^{-36}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - a \cdot \left(3 \cdot c\right)}}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 4
Error13.8
Cost7432
\[\begin{array}{l} \mathbf{if}\;b \leq -1.5 \cdot 10^{-88}:\\ \;\;\;\;\frac{\frac{b \cdot -4 + a \cdot \left(3 \cdot \frac{c}{b}\right)}{a}}{6}\\ \mathbf{elif}\;b \leq 2.8 \cdot 10^{-36}:\\ \;\;\;\;\frac{0.3333333333333333}{a} \cdot \left(\sqrt{a \cdot \left(c \cdot -3\right)} + \left(-b\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 5
Error13.8
Cost7432
\[\begin{array}{l} \mathbf{if}\;b \leq -2.15 \cdot 10^{-88}:\\ \;\;\;\;\frac{\frac{b \cdot -4 + a \cdot \left(3 \cdot \frac{c}{b}\right)}{a}}{6}\\ \mathbf{elif}\;b \leq 1.75 \cdot 10^{-36}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -3\right)} + \left(-b\right)}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 6
Error14.0
Cost7240
\[\begin{array}{l} \mathbf{if}\;b \leq -2.15 \cdot 10^{-88}:\\ \;\;\;\;\frac{\frac{b \cdot -4 + a \cdot \left(3 \cdot \frac{c}{b}\right)}{a}}{6}\\ \mathbf{elif}\;b \leq 1.5 \cdot 10^{-34}:\\ \;\;\;\;\frac{0.3333333333333333}{a} \cdot \sqrt{a \cdot \left(c \cdot -3\right)}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 7
Error14.0
Cost7240
\[\begin{array}{l} \mathbf{if}\;b \leq -1.15 \cdot 10^{-89}:\\ \;\;\;\;\frac{\frac{b \cdot -4 + a \cdot \left(3 \cdot \frac{c}{b}\right)}{a}}{6}\\ \mathbf{elif}\;b \leq 9 \cdot 10^{-35}:\\ \;\;\;\;\frac{0.3333333333333333}{a} \cdot \sqrt{c \cdot \left(a \cdot -3\right)}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 8
Error14.0
Cost7240
\[\begin{array}{l} \mathbf{if}\;b \leq -1.15 \cdot 10^{-89}:\\ \;\;\;\;\frac{\frac{b \cdot -4 + a \cdot \left(3 \cdot \frac{c}{b}\right)}{a}}{6}\\ \mathbf{elif}\;b \leq 1.72 \cdot 10^{-34}:\\ \;\;\;\;\frac{\sqrt{-3 \cdot \left(c \cdot a\right)}}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 9
Error19.2
Cost7112
\[\begin{array}{l} \mathbf{if}\;b \leq -9.5 \cdot 10^{-169}:\\ \;\;\;\;\frac{b}{a} \cdot -0.6666666666666666 + \frac{0.5}{\frac{b}{c}}\\ \mathbf{elif}\;b \leq 3.55 \cdot 10^{-171}:\\ \;\;\;\;0.3333333333333333 \cdot \sqrt{-3 \cdot \frac{c}{a}}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 10
Error22.4
Cost580
\[\begin{array}{l} \mathbf{if}\;b \leq 6 \cdot 10^{-220}:\\ \;\;\;\;\frac{\frac{b}{a \cdot 0.5}}{-3}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 11
Error22.4
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 1.8 \cdot 10^{-219}:\\ \;\;\;\;b \cdot \frac{-0.6666666666666666}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 12
Error22.4
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 2.55 \cdot 10^{-220}:\\ \;\;\;\;\frac{b}{a} \cdot -0.6666666666666666\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 13
Error39.6
Cost320
\[-0.5 \cdot \frac{c}{b} \]

Error

Reproduce?

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