Average Error: 34.0 → 11.1
Time: 23.6s
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 \cdot 10^{+158}:\\ \;\;\;\;\frac{\left(\frac{1.5 \cdot c}{\frac{b}{a}} - b\right) - b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 2.5 \cdot 10^{-121}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{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 -5e+158)
   (/ (- (- (/ (* 1.5 c) (/ b a)) b) b) (* a 3.0))
   (if (<= b 2.5e-121)
     (/ (- (sqrt (+ (* b b) (* c (* a -3.0)))) b) (* a 3.0))
     (/ (* c -0.5) 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 <= -5e+158) {
		tmp = ((((1.5 * c) / (b / a)) - b) - b) / (a * 3.0);
	} else if (b <= 2.5e-121) {
		tmp = (sqrt(((b * b) + (c * (a * -3.0)))) - b) / (a * 3.0);
	} else {
		tmp = (c * -0.5) / 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 <= (-5d+158)) then
        tmp = ((((1.5d0 * c) / (b / a)) - b) - b) / (a * 3.0d0)
    else if (b <= 2.5d-121) then
        tmp = (sqrt(((b * b) + (c * (a * (-3.0d0))))) - b) / (a * 3.0d0)
    else
        tmp = (c * (-0.5d0)) / 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 <= -5e+158) {
		tmp = ((((1.5 * c) / (b / a)) - b) - b) / (a * 3.0);
	} else if (b <= 2.5e-121) {
		tmp = (Math.sqrt(((b * b) + (c * (a * -3.0)))) - b) / (a * 3.0);
	} else {
		tmp = (c * -0.5) / 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 <= -5e+158:
		tmp = ((((1.5 * c) / (b / a)) - b) - b) / (a * 3.0)
	elif b <= 2.5e-121:
		tmp = (math.sqrt(((b * b) + (c * (a * -3.0)))) - b) / (a * 3.0)
	else:
		tmp = (c * -0.5) / 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 <= -5e+158)
		tmp = Float64(Float64(Float64(Float64(Float64(1.5 * c) / Float64(b / a)) - b) - b) / Float64(a * 3.0));
	elseif (b <= 2.5e-121)
		tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -3.0)))) - b) / Float64(a * 3.0));
	else
		tmp = Float64(Float64(c * -0.5) / 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 <= -5e+158)
		tmp = ((((1.5 * c) / (b / a)) - b) - b) / (a * 3.0);
	elseif (b <= 2.5e-121)
		tmp = (sqrt(((b * b) + (c * (a * -3.0)))) - b) / (a * 3.0);
	else
		tmp = (c * -0.5) / 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, -5e+158], N[(N[(N[(N[(N[(1.5 * c), $MachinePrecision] / N[(b / a), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.5e-121], 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[(N[(c * -0.5), $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 -5 \cdot 10^{+158}:\\
\;\;\;\;\frac{\left(\frac{1.5 \cdot c}{\frac{b}{a}} - b\right) - b}{a \cdot 3}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{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 < -4.9999999999999996e158

    1. Initial program 64.0

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

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

      [Start]64.0

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

      *-lft-identity [<=]64.0

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

      metadata-eval [<=]64.0

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

      times-frac [<=]64.0

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

      *-commutative [<=]64.0

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

      times-frac [=>]64.0

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

      associate-*r/ [=>]64.0

      \[ \color{blue}{\frac{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-1} \cdot -1}{3 \cdot a}} \]
    3. Applied egg-rr64.0

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

      \[\leadsto \frac{\color{blue}{\left(1.5 \cdot \frac{c \cdot a}{b} + -1 \cdot b\right)} - b}{3 \cdot a} \]
    5. Simplified2.2

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

      [Start]10.0

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

      mul-1-neg [=>]10.0

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

      unsub-neg [=>]10.0

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

      associate-/l* [=>]2.2

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

      associate-*r/ [=>]2.2

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

    if -4.9999999999999996e158 < b < 2.49999999999999995e-121

    1. Initial program 12.4

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

    if 2.49999999999999995e-121 < b

    1. Initial program 51.0

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

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

      [Start]51.0

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

      remove-double-neg [<=]51.0

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

      sub-neg [<=]51.0

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

      div-sub [=>]51.6

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

      neg-mul-1 [=>]51.6

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

      associate-*l/ [<=]52.4

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

      distribute-frac-neg [=>]52.4

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

      fma-neg [=>]54.5

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

      /-rgt-identity [<=]54.5

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

      metadata-eval [<=]54.5

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

      associate-/l* [<=]54.5

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

      *-commutative [<=]54.5

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

      neg-mul-1 [<=]54.5

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

      fma-neg [<=]52.4

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

      neg-mul-1 [=>]52.4

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b}} \]
    4. Applied egg-rr11.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{+158}:\\ \;\;\;\;\frac{\left(\frac{1.5 \cdot c}{\frac{b}{a}} - b\right) - b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 2.5 \cdot 10^{-121}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]

Alternatives

Alternative 1
Error10.9
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -2 \cdot 10^{+153}:\\ \;\;\;\;\frac{\left(\frac{1.5 \cdot c}{\frac{b}{a}} - b\right) - b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 1.25 \cdot 10^{-119}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + a \cdot \left(c \cdot -3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 2
Error14.2
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -1.05 \cdot 10^{-78}:\\ \;\;\;\;\frac{\left(\frac{1.5 \cdot c}{\frac{b}{a}} - b\right) - b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 1.18 \cdot 10^{-119}:\\ \;\;\;\;0.3333333333333333 \cdot \frac{\sqrt{a \cdot \left(c \cdot -3\right)} - b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 3
Error14.2
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -1.45 \cdot 10^{-76}:\\ \;\;\;\;\frac{\left(\frac{1.5 \cdot c}{\frac{b}{a}} - b\right) - b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 1.25 \cdot 10^{-119}:\\ \;\;\;\;\frac{-0.3333333333333333 \cdot \left(b - \sqrt{a \cdot \left(c \cdot -3\right)}\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 4
Error14.2
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -1.65 \cdot 10^{-81}:\\ \;\;\;\;\frac{\left(\frac{1.5 \cdot c}{\frac{b}{a}} - b\right) - b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 1.2 \cdot 10^{-119}:\\ \;\;\;\;\frac{\sqrt{-3 \cdot \left(c \cdot a\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 5
Error14.2
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -7.2 \cdot 10^{-76}:\\ \;\;\;\;\frac{\left(\frac{1.5 \cdot c}{\frac{b}{a}} - b\right) - b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 1.8 \cdot 10^{-120}:\\ \;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 6
Error14.2
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -1.5 \cdot 10^{-77}:\\ \;\;\;\;\frac{\left(\frac{1.5 \cdot c}{\frac{b}{a}} - b\right) - b}{a \cdot 3}\\ \mathbf{elif}\;b \leq 1.02 \cdot 10^{-119}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 7
Error23.3
Cost1092
\[\begin{array}{l} \mathbf{if}\;b \leq -8 \cdot 10^{-308}:\\ \;\;\;\;\frac{\left(\frac{1.5 \cdot c}{\frac{b}{a}} - b\right) - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 8
Error36.7
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 2.7 \cdot 10^{-257}:\\ \;\;\;\;\frac{b}{a} \cdot -0.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 9
Error23.2
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 4.7 \cdot 10^{-262}:\\ \;\;\;\;b \cdot \frac{-0.6666666666666666}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 10
Error23.2
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 3.2 \cdot 10^{-260}:\\ \;\;\;\;\frac{b}{a \cdot -1.5}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 11
Error23.2
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 8.8 \cdot 10^{-253}:\\ \;\;\;\;\frac{b}{a \cdot -1.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 12
Error39.9
Cost320
\[-0.5 \cdot \frac{c}{b} \]

Error

Reproduce

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