Average Error: 34.5 → 11.6
Time: 21.0s
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 -1.25 \cdot 10^{+91}:\\ \;\;\;\;\frac{b \cdot -0.6666666666666666}{a}\\ \mathbf{elif}\;b \leq 2.9 \cdot 10^{-167}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3}\\ \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.25e+91)
   (/ (* b -0.6666666666666666) a)
   (if (<= b 2.9e-167)
     (/ (- (sqrt (+ (* b b) (* c (* a -3.0)))) b) (* a 3.0))
     (* -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.25e+91) {
		tmp = (b * -0.6666666666666666) / a;
	} else if (b <= 2.9e-167) {
		tmp = (sqrt(((b * b) + (c * (a * -3.0)))) - b) / (a * 3.0);
	} 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.25d+91)) then
        tmp = (b * (-0.6666666666666666d0)) / a
    else if (b <= 2.9d-167) then
        tmp = (sqrt(((b * b) + (c * (a * (-3.0d0))))) - b) / (a * 3.0d0)
    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.25e+91) {
		tmp = (b * -0.6666666666666666) / a;
	} else if (b <= 2.9e-167) {
		tmp = (Math.sqrt(((b * b) + (c * (a * -3.0)))) - b) / (a * 3.0);
	} 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.25e+91:
		tmp = (b * -0.6666666666666666) / a
	elif b <= 2.9e-167:
		tmp = (math.sqrt(((b * b) + (c * (a * -3.0)))) - b) / (a * 3.0)
	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.25e+91)
		tmp = Float64(Float64(b * -0.6666666666666666) / a);
	elseif (b <= 2.9e-167)
		tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -3.0)))) - b) / Float64(a * 3.0));
	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.25e+91)
		tmp = (b * -0.6666666666666666) / a;
	elseif (b <= 2.9e-167)
		tmp = (sqrt(((b * b) + (c * (a * -3.0)))) - b) / (a * 3.0);
	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.25e+91], N[(N[(b * -0.6666666666666666), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 2.9e-167], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $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.25 \cdot 10^{+91}:\\
\;\;\;\;\frac{b \cdot -0.6666666666666666}{a}\\

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

\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.2500000000000001e91

    1. Initial program 44.8

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

      \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b\right) \cdot \frac{0.3333333333333333}{a}} \]
      Proof
      (*.f64 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 c (*.f64 a -3)))) b) (/.f64 1/3 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 c (*.f64 a (Rewrite<= metadata-eval (neg.f64 3)))))) b) (/.f64 1/3 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 c (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 a 3)))))) b) (/.f64 1/3 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (-.f64 (sqrt.f64 (fma.f64 b b (*.f64 c (neg.f64 (Rewrite<= *-commutative_binary64 (*.f64 3 a)))))) b) (/.f64 1/3 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (-.f64 (sqrt.f64 (fma.f64 b b (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 c (*.f64 3 a)))))) b) (/.f64 1/3 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (-.f64 (sqrt.f64 (fma.f64 b b (neg.f64 (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 3 a) c))))) b) (/.f64 1/3 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (-.f64 (sqrt.f64 (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) b) (/.f64 1/3 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= unsub-neg_binary64 (+.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c))) (neg.f64 b))) (/.f64 1/3 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= +-commutative_binary64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c))))) (/.f64 1/3 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= /-rgt-identity_binary64 (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) 1)) (/.f64 1/3 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (Rewrite<= metadata-eval (*.f64 -1 -1))) (/.f64 1/3 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= associate-/l/_binary64 (/.f64 (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) -1) -1)) (/.f64 1/3 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 (/.f64 (+.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 b)) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) -1) -1) (/.f64 1/3 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 (/.f64 (Rewrite=> associate-+l-_binary64 (-.f64 0 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))))) -1) -1) (/.f64 1/3 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 (/.f64 (Rewrite=> sub0-neg_binary64 (neg.f64 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))))) -1) -1) (/.f64 1/3 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 (/.f64 (Rewrite=> neg-mul-1_binary64 (*.f64 -1 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))))) -1) -1) (/.f64 1/3 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 (/.f64 (Rewrite=> *-commutative_binary64 (*.f64 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) -1)) -1) -1) (/.f64 1/3 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 (Rewrite=> associate-/l*_binary64 (/.f64 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (/.f64 -1 -1))) -1) (/.f64 1/3 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 (/.f64 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (Rewrite=> metadata-eval 1)) -1) (/.f64 1/3 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 (Rewrite=> /-rgt-identity_binary64 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c))))) -1) (/.f64 1/3 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) -1) (/.f64 (Rewrite<= metadata-eval (/.f64 1 3)) a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) -1) (/.f64 (/.f64 (Rewrite<= metadata-eval (neg.f64 -1)) 3) a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) -1) (Rewrite<= associate-/r*_binary64 (/.f64 (neg.f64 -1) (*.f64 3 a)))): 13 points increase in error, 21 points decrease in error
      (Rewrite<= times-frac_binary64 (/.f64 (*.f64 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (neg.f64 -1)) (*.f64 -1 (*.f64 3 a)))): 10 points increase in error, 20 points decrease in error
      (/.f64 (*.f64 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (neg.f64 -1)) (Rewrite=> *-commutative_binary64 (*.f64 (*.f64 3 a) -1))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> times-frac_binary64 (*.f64 (/.f64 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) (/.f64 (neg.f64 -1) -1))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) (/.f64 (Rewrite=> metadata-eval 1) -1)): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) (Rewrite=> metadata-eval -1)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) -1) (*.f64 3 a))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 -1 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))))) (*.f64 3 a)): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))))) (*.f64 3 a)): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= sub0-neg_binary64 (-.f64 0 (-.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))))) (*.f64 3 a)): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 0 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c))))) (*.f64 3 a)): 0 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 b)) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr44.9

      \[\leadsto \left(\sqrt{\color{blue}{c \cdot \left(a \cdot -3\right) + b \cdot b}} - b\right) \cdot \frac{0.3333333333333333}{a} \]
    4. Applied egg-rr44.9

      \[\leadsto \left(\sqrt{\color{blue}{\mathsf{fma}\left(c \cdot -3, a, b \cdot b\right)}} - b\right) \cdot \frac{0.3333333333333333}{a} \]
    5. Applied egg-rr36.5

      \[\leadsto \color{blue}{\frac{\left(\mathsf{hypot}\left(b, \sqrt{c \cdot \left(-3 \cdot a\right)}\right) - b\right) \cdot 0.3333333333333333}{a}} \]
    6. Taylor expanded in b around -inf 4.0

      \[\leadsto \frac{\color{blue}{-0.6666666666666666 \cdot b}}{a} \]
    7. Simplified4.0

      \[\leadsto \frac{\color{blue}{b \cdot -0.6666666666666666}}{a} \]
      Proof
      (*.f64 b -2/3): 0 points increase in error, 0 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 -2/3 b)): 0 points increase in error, 0 points decrease in error

    if -1.2500000000000001e91 < b < 2.90000000000000003e-167

    1. Initial program 11.9

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

    if 2.90000000000000003e-167 < b

    1. Initial program 49.2

      \[\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 14.2

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

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

Alternatives

Alternative 1
Error11.6
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -1.6 \cdot 10^{+113}:\\ \;\;\;\;\frac{b \cdot -0.6666666666666666}{a}\\ \mathbf{elif}\;b \leq 2.9 \cdot 10^{-167}:\\ \;\;\;\;\left(\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b\right) \cdot \frac{0.3333333333333333}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 2
Error14.6
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -2 \cdot 10^{-59}:\\ \;\;\;\;\frac{b \cdot -0.6666666666666666}{a}\\ \mathbf{elif}\;b \leq 2.9 \cdot 10^{-167}:\\ \;\;\;\;\frac{0.3333333333333333 \cdot \left(\sqrt{a \cdot \left(c \cdot -3\right)} - b\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 3
Error14.6
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -2 \cdot 10^{-59}:\\ \;\;\;\;\frac{b \cdot -0.6666666666666666}{a}\\ \mathbf{elif}\;b \leq 2.9 \cdot 10^{-167}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 4
Error14.6
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -2 \cdot 10^{-59}:\\ \;\;\;\;\frac{b \cdot -0.6666666666666666}{a}\\ \mathbf{elif}\;b \leq 2.9 \cdot 10^{-167}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 5
Error23.0
Cost580
\[\begin{array}{l} \mathbf{if}\;b \leq 9.8 \cdot 10^{-253}:\\ \;\;\;\;\frac{b \cdot -2}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 6
Error39.9
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 5.8 \cdot 10^{-24}:\\ \;\;\;\;\frac{b \cdot -0.6666666666666666}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot 0.5\\ \end{array} \]
Alternative 7
Error23.3
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 9.8 \cdot 10^{-253}:\\ \;\;\;\;\frac{b \cdot -0.6666666666666666}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5}{\frac{b}{c}}\\ \end{array} \]
Alternative 8
Error23.0
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 9.8 \cdot 10^{-253}:\\ \;\;\;\;\frac{b \cdot -0.6666666666666666}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 9
Error45.5
Cost320
\[\frac{b \cdot -0.6666666666666666}{a} \]

Error

Reproduce

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