?

Average Accuracy: 47.4% → 84.2%
Time: 18.2s
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 -2.9 \cdot 10^{+134}:\\ \;\;\;\;b \cdot \frac{\frac{1}{a}}{-1.5}\\ \mathbf{elif}\;b \leq 4.2 \cdot 10^{-68}:\\ \;\;\;\;\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 -2.9e+134)
   (* b (/ (/ 1.0 a) -1.5))
   (if (<= b 4.2e-68)
     (/ (- (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 <= -2.9e+134) {
		tmp = b * ((1.0 / a) / -1.5);
	} else if (b <= 4.2e-68) {
		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 <= (-2.9d+134)) then
        tmp = b * ((1.0d0 / a) / (-1.5d0))
    else if (b <= 4.2d-68) 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 <= -2.9e+134) {
		tmp = b * ((1.0 / a) / -1.5);
	} else if (b <= 4.2e-68) {
		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 <= -2.9e+134:
		tmp = b * ((1.0 / a) / -1.5)
	elif b <= 4.2e-68:
		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 <= -2.9e+134)
		tmp = Float64(b * Float64(Float64(1.0 / a) / -1.5));
	elseif (b <= 4.2e-68)
		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 <= -2.9e+134)
		tmp = b * ((1.0 / a) / -1.5);
	elseif (b <= 4.2e-68)
		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, -2.9e+134], N[(b * N[(N[(1.0 / a), $MachinePrecision] / -1.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.2e-68], 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 -2.9 \cdot 10^{+134}:\\
\;\;\;\;b \cdot \frac{\frac{1}{a}}{-1.5}\\

\mathbf{elif}\;b \leq 4.2 \cdot 10^{-68}:\\
\;\;\;\;\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 < -2.90000000000000012e134

    1. Initial program 11.9%

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

      \[\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]11.9

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

      remove-double-neg [<=]11.9

      \[ \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 [<=]11.9

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

      div-sub [=>]11.9

      \[ \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 [=>]11.9

      \[ \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/ [<=]11.9

      \[ \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 [=>]11.9

      \[ \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 [=>]11.9

      \[ \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 [<=]11.9

      \[ \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 [<=]11.9

      \[ \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* [<=]11.9

      \[ \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 [<=]11.9

      \[ \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 [<=]11.9

      \[ \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 [<=]11.9

      \[ \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 [=>]11.9

      \[ \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 95.8%

      \[\leadsto \color{blue}{-0.6666666666666666 \cdot \frac{b}{a}} \]
    4. Simplified95.8%

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

      [Start]95.8

      \[ -0.6666666666666666 \cdot \frac{b}{a} \]

      *-commutative [=>]95.8

      \[ \color{blue}{\frac{b}{a} \cdot -0.6666666666666666} \]
    5. Applied egg-rr95.7%

      \[\leadsto \color{blue}{\frac{1}{\frac{a}{b \cdot -0.6666666666666666}}} \]
      Proof

      [Start]95.8

      \[ \frac{b}{a} \cdot -0.6666666666666666 \]

      associate-*l/ [=>]95.8

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

      clear-num [=>]95.7

      \[ \color{blue}{\frac{1}{\frac{a}{b \cdot -0.6666666666666666}}} \]
    6. Applied egg-rr95.4%

      \[\leadsto \frac{1}{\frac{a}{\color{blue}{{\left(\sqrt{b \cdot -0.6666666666666666}\right)}^{2}}}} \]
      Proof

      [Start]95.7

      \[ \frac{1}{\frac{a}{b \cdot -0.6666666666666666}} \]

      add-sqr-sqrt [=>]95.4

      \[ \frac{1}{\frac{a}{\color{blue}{\sqrt{b \cdot -0.6666666666666666} \cdot \sqrt{b \cdot -0.6666666666666666}}}} \]

      pow2 [=>]95.4

      \[ \frac{1}{\frac{a}{\color{blue}{{\left(\sqrt{b \cdot -0.6666666666666666}\right)}^{2}}}} \]
    7. Applied egg-rr95.8%

      \[\leadsto \color{blue}{\frac{\frac{1}{a}}{-1.5} \cdot b} \]
      Proof

      [Start]95.4

      \[ \frac{1}{\frac{a}{{\left(\sqrt{b \cdot -0.6666666666666666}\right)}^{2}}} \]

      div-inv [=>]95.3

      \[ \frac{1}{\color{blue}{a \cdot \frac{1}{{\left(\sqrt{b \cdot -0.6666666666666666}\right)}^{2}}}} \]

      associate-/r* [=>]95.4

      \[ \color{blue}{\frac{\frac{1}{a}}{\frac{1}{{\left(\sqrt{b \cdot -0.6666666666666666}\right)}^{2}}}} \]

      unpow2 [=>]95.4

      \[ \frac{\frac{1}{a}}{\frac{1}{\color{blue}{\sqrt{b \cdot -0.6666666666666666} \cdot \sqrt{b \cdot -0.6666666666666666}}}} \]

      add-sqr-sqrt [<=]95.6

      \[ \frac{\frac{1}{a}}{\frac{1}{\color{blue}{b \cdot -0.6666666666666666}}} \]

      *-commutative [=>]95.6

      \[ \frac{\frac{1}{a}}{\frac{1}{\color{blue}{-0.6666666666666666 \cdot b}}} \]

      associate-/r* [=>]95.8

      \[ \frac{\frac{1}{a}}{\color{blue}{\frac{\frac{1}{-0.6666666666666666}}{b}}} \]

      associate-/r/ [=>]95.8

      \[ \color{blue}{\frac{\frac{1}{a}}{\frac{1}{-0.6666666666666666}} \cdot b} \]

      metadata-eval [=>]95.8

      \[ \frac{\frac{1}{a}}{\color{blue}{-1.5}} \cdot b \]

    if -2.90000000000000012e134 < b < 4.20000000000000016e-68

    1. Initial program 80.0%

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

    if 4.20000000000000016e-68 < b

    1. Initial program 17.6%

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

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

      [Start]17.6

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

      *-lft-identity [<=]17.6

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

      metadata-eval [<=]17.6

      \[ \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 [<=]17.6

      \[ \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 [<=]17.6

      \[ \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 [=>]17.6

      \[ \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/ [=>]17.6

      \[ \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. Taylor expanded in b around inf 85.8%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{c}{b}} \]
    4. Simplified85.8%

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

      [Start]85.8

      \[ -0.5 \cdot \frac{c}{b} \]

      associate-*r/ [=>]85.8

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

      *-commutative [=>]85.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.9 \cdot 10^{+134}:\\ \;\;\;\;b \cdot \frac{\frac{1}{a}}{-1.5}\\ \mathbf{elif}\;b \leq 4.2 \cdot 10^{-68}:\\ \;\;\;\;\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
Accuracy84.2%
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -2.45 \cdot 10^{+134}:\\ \;\;\;\;b \cdot \frac{\frac{1}{a}}{-1.5}\\ \mathbf{elif}\;b \leq 5.9 \cdot 10^{-68}:\\ \;\;\;\;\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
Accuracy75.7%
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -9.2 \cdot 10^{-195}:\\ \;\;\;\;b \cdot \frac{\frac{1}{a}}{-1.5}\\ \mathbf{elif}\;b \leq 4.7 \cdot 10^{-68}:\\ \;\;\;\;\frac{\sqrt{-3 \cdot \left(a \cdot c\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 3
Accuracy75.7%
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -9.2 \cdot 10^{-195}:\\ \;\;\;\;b \cdot \frac{\frac{1}{a}}{-1.5}\\ \mathbf{elif}\;b \leq 6.6 \cdot 10^{-68}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -3\right)} - b}{a \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 4
Accuracy63.5%
Cost6980
\[\begin{array}{l} \mathbf{if}\;b \leq 1.05 \cdot 10^{-154}:\\ \;\;\;\;\frac{1}{\frac{a}{\frac{\left|b\right|}{1.5}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 5
Accuracy64.1%
Cost580
\[\begin{array}{l} \mathbf{if}\;b \leq 9.5 \cdot 10^{-276}:\\ \;\;\;\;b \cdot \frac{\frac{1}{a}}{-1.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 6
Accuracy64.0%
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 6.2 \cdot 10^{-276}:\\ \;\;\;\;\frac{b}{a} \cdot -0.6666666666666666\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{-0.5}{b}\\ \end{array} \]
Alternative 7
Accuracy64.0%
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 1.1 \cdot 10^{-275}:\\ \;\;\;\;\frac{b}{a \cdot -1.5}\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{-0.5}{b}\\ \end{array} \]
Alternative 8
Accuracy64.1%
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 2.3 \cdot 10^{-275}:\\ \;\;\;\;\frac{b}{a \cdot -1.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot -0.5}{b}\\ \end{array} \]
Alternative 9
Accuracy37.5%
Cost320
\[c \cdot \frac{-0.5}{b} \]

Error

Reproduce?

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