?

Average Accuracy: 46.2% → 78.7%
Time: 22.0s
Precision: binary64
Cost: 57108

?

\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
\[\begin{array}{l} t_0 := \frac{-c}{b}\\ t_1 := \frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_1 \leq -1 \cdot 10^{-258}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+266}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_1 \leq \infty:\\ \;\;\;\;\frac{0.5}{\frac{a}{\mathsf{hypot}\left(b, \sqrt{c \cdot -4} \cdot \sqrt{a}\right) - b}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
 :precision binary64
 (let* ((t_0 (/ (- c) b))
        (t_1 (/ (- (sqrt (+ (* b b) (* c (* a -4.0)))) b) (* a 2.0))))
   (if (<= t_1 (- INFINITY))
     t_0
     (if (<= t_1 -1e-258)
       t_1
       (if (<= t_1 0.0)
         t_0
         (if (<= t_1 5e+266)
           t_1
           (if (<= t_1 INFINITY)
             (/ 0.5 (/ a (- (hypot b (* (sqrt (* c -4.0)) (sqrt a))) b)))
             t_0)))))))
double code(double a, double b, double c) {
	return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
double code(double a, double b, double c) {
	double t_0 = -c / b;
	double t_1 = (sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0);
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = t_0;
	} else if (t_1 <= -1e-258) {
		tmp = t_1;
	} else if (t_1 <= 0.0) {
		tmp = t_0;
	} else if (t_1 <= 5e+266) {
		tmp = t_1;
	} else if (t_1 <= ((double) INFINITY)) {
		tmp = 0.5 / (a / (hypot(b, (sqrt((c * -4.0)) * sqrt(a))) - b));
	} else {
		tmp = t_0;
	}
	return tmp;
}
public static double code(double a, double b, double c) {
	return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
public static double code(double a, double b, double c) {
	double t_0 = -c / b;
	double t_1 = (Math.sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0);
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = t_0;
	} else if (t_1 <= -1e-258) {
		tmp = t_1;
	} else if (t_1 <= 0.0) {
		tmp = t_0;
	} else if (t_1 <= 5e+266) {
		tmp = t_1;
	} else if (t_1 <= Double.POSITIVE_INFINITY) {
		tmp = 0.5 / (a / (Math.hypot(b, (Math.sqrt((c * -4.0)) * Math.sqrt(a))) - b));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c):
	return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
def code(a, b, c):
	t_0 = -c / b
	t_1 = (math.sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0)
	tmp = 0
	if t_1 <= -math.inf:
		tmp = t_0
	elif t_1 <= -1e-258:
		tmp = t_1
	elif t_1 <= 0.0:
		tmp = t_0
	elif t_1 <= 5e+266:
		tmp = t_1
	elif t_1 <= math.inf:
		tmp = 0.5 / (a / (math.hypot(b, (math.sqrt((c * -4.0)) * math.sqrt(a))) - b))
	else:
		tmp = t_0
	return tmp
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a))
end
function code(a, b, c)
	t_0 = Float64(Float64(-c) / b)
	t_1 = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = t_0;
	elseif (t_1 <= -1e-258)
		tmp = t_1;
	elseif (t_1 <= 0.0)
		tmp = t_0;
	elseif (t_1 <= 5e+266)
		tmp = t_1;
	elseif (t_1 <= Inf)
		tmp = Float64(0.5 / Float64(a / Float64(hypot(b, Float64(sqrt(Float64(c * -4.0)) * sqrt(a))) - b)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp = code(a, b, c)
	tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
end
function tmp_2 = code(a, b, c)
	t_0 = -c / b;
	t_1 = (sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0);
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = t_0;
	elseif (t_1 <= -1e-258)
		tmp = t_1;
	elseif (t_1 <= 0.0)
		tmp = t_0;
	elseif (t_1 <= 5e+266)
		tmp = t_1;
	elseif (t_1 <= Inf)
		tmp = 0.5 / (a / (hypot(b, (sqrt((c * -4.0)) * sqrt(a))) - b));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := Block[{t$95$0 = N[((-c) / b), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], t$95$0, If[LessEqual[t$95$1, -1e-258], t$95$1, If[LessEqual[t$95$1, 0.0], t$95$0, If[LessEqual[t$95$1, 5e+266], t$95$1, If[LessEqual[t$95$1, Infinity], N[(0.5 / N[(a / N[(N[Sqrt[b ^ 2 + N[(N[Sqrt[N[(c * -4.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[a], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
t_0 := \frac{-c}{b}\\
t_1 := \frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_1 \leq -1 \cdot 10^{-258}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+266}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_1 \leq \infty:\\
\;\;\;\;\frac{0.5}{\frac{a}{\mathsf{hypot}\left(b, \sqrt{c \cdot -4} \cdot \sqrt{a}\right) - b}}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\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 (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < -inf.0 or -9.99999999999999954e-259 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < 0.0 or +inf.0 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))

    1. Initial program 8.3%

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

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

      [Start]8.3

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

      *-commutative [=>]8.3

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    4. Simplified74.2%

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

      [Start]74.2

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

      mul-1-neg [=>]74.2

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

      distribute-neg-frac [=>]74.2

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

    if -inf.0 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < -9.99999999999999954e-259 or 0.0 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < 4.9999999999999999e266

    1. Initial program 93.5%

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

    if 4.9999999999999999e266 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < +inf.0

    1. Initial program 4.9%

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

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

      [Start]4.9

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

      /-rgt-identity [<=]4.9

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

      metadata-eval [<=]4.9

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

      *-commutative [=>]4.9

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

      associate-/l* [=>]4.9

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

      associate-/l* [<=]4.9

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

      associate-*r/ [<=]4.9

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

      /-rgt-identity [<=]4.9

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

      metadata-eval [<=]4.9

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

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

      [Start]5.0

      \[ \left(\sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)} - b\right) \cdot \frac{0.5}{a} \]

      associate-*r/ [=>]5.0

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

      *-commutative [=>]5.0

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

      associate-/l* [=>]5.0

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

      fma-udef [=>]5.0

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

      add-sqr-sqrt [=>]4.0

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

      hypot-def [=>]30.1

      \[ \frac{0.5}{\frac{a}{\color{blue}{\mathsf{hypot}\left(b, \sqrt{\left(a \cdot c\right) \cdot -4}\right)} - b}} \]

      associate-*l* [=>]30.0

      \[ \frac{0.5}{\frac{a}{\mathsf{hypot}\left(b, \sqrt{\color{blue}{a \cdot \left(c \cdot -4\right)}}\right) - b}} \]
    4. Applied egg-rr51.0%

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

      [Start]30.0

      \[ \frac{0.5}{\frac{a}{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right) - b}} \]

      sqrt-prod [=>]51.0

      \[ \frac{0.5}{\frac{a}{\mathsf{hypot}\left(b, \color{blue}{\sqrt{a} \cdot \sqrt{c \cdot -4}}\right) - b}} \]

      *-commutative [=>]51.0

      \[ \frac{0.5}{\frac{a}{\mathsf{hypot}\left(b, \color{blue}{\sqrt{c \cdot -4} \cdot \sqrt{a}}\right) - b}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification78.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2} \leq -\infty:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2} \leq -1 \cdot 10^{-258}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2} \leq 0:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2} \leq 5 \cdot 10^{+266}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2} \leq \infty:\\ \;\;\;\;\frac{0.5}{\frac{a}{\mathsf{hypot}\left(b, \sqrt{c \cdot -4} \cdot \sqrt{a}\right) - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy84.0%
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -5.7 \cdot 10^{+57}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 8.8 \cdot 10^{-67}:\\ \;\;\;\;\left(\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b\right) \cdot \frac{0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 2
Accuracy84.0%
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -2.8 \cdot 10^{+57}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 9 \cdot 10^{-67}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 3
Accuracy79.0%
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -3.8 \cdot 10^{-42}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 9 \cdot 10^{-67}:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{c \cdot \left(a \cdot -4\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 4
Accuracy79.0%
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -1.06 \cdot 10^{-41}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 5 \cdot 10^{-67}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 5
Accuracy65.7%
Cost580
\[\begin{array}{l} \mathbf{if}\;b \leq -4.1 \cdot 10^{-300}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 6
Accuracy38.9%
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 7
Accuracy65.5%
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq 7.1 \cdot 10^{-202}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 8
Accuracy11.8%
Cost64
\[0 \]

Error

Reproduce?

herbie shell --seed 2023135 
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))