?

Average Accuracy: 47.9% → 85.1%
Time: 17.0s
Precision: binary64
Cost: 13964

?

\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
\[\begin{array}{l} \mathbf{if}\;b \leq -2.6 \cdot 10^{+109}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -4 \cdot 10^{-137}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 9.6 \cdot 10^{-63}:\\ \;\;\;\;\frac{0.5}{\frac{a}{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right) - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \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
 (if (<= b -2.6e+109)
   (- (/ c b) (/ b a))
   (if (<= b -4e-137)
     (/ (- (sqrt (+ (* b b) (* c (* a -4.0)))) b) (* a 2.0))
     (if (<= b 9.6e-63)
       (/ 0.5 (/ a (- (hypot b (sqrt (* a (* c -4.0)))) b)))
       (/ (- c) b)))))
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 tmp;
	if (b <= -2.6e+109) {
		tmp = (c / b) - (b / a);
	} else if (b <= -4e-137) {
		tmp = (sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0);
	} else if (b <= 9.6e-63) {
		tmp = 0.5 / (a / (hypot(b, sqrt((a * (c * -4.0)))) - b));
	} else {
		tmp = -c / b;
	}
	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 tmp;
	if (b <= -2.6e+109) {
		tmp = (c / b) - (b / a);
	} else if (b <= -4e-137) {
		tmp = (Math.sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0);
	} else if (b <= 9.6e-63) {
		tmp = 0.5 / (a / (Math.hypot(b, Math.sqrt((a * (c * -4.0)))) - b));
	} else {
		tmp = -c / b;
	}
	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):
	tmp = 0
	if b <= -2.6e+109:
		tmp = (c / b) - (b / a)
	elif b <= -4e-137:
		tmp = (math.sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0)
	elif b <= 9.6e-63:
		tmp = 0.5 / (a / (math.hypot(b, math.sqrt((a * (c * -4.0)))) - b))
	else:
		tmp = -c / b
	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)
	tmp = 0.0
	if (b <= -2.6e+109)
		tmp = Float64(Float64(c / b) - Float64(b / a));
	elseif (b <= -4e-137)
		tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0));
	elseif (b <= 9.6e-63)
		tmp = Float64(0.5 / Float64(a / Float64(hypot(b, sqrt(Float64(a * Float64(c * -4.0)))) - b)));
	else
		tmp = Float64(Float64(-c) / b);
	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)
	tmp = 0.0;
	if (b <= -2.6e+109)
		tmp = (c / b) - (b / a);
	elseif (b <= -4e-137)
		tmp = (sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0);
	elseif (b <= 9.6e-63)
		tmp = 0.5 / (a / (hypot(b, sqrt((a * (c * -4.0)))) - b));
	else
		tmp = -c / b;
	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_] := If[LessEqual[b, -2.6e+109], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -4e-137], 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[b, 9.6e-63], N[(0.5 / N[(a / N[(N[Sqrt[b ^ 2 + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -2.6 \cdot 10^{+109}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \leq -4 \cdot 10^{-137}:\\
\;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\

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

\mathbf{else}:\\
\;\;\;\;\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 4 regimes
  2. if b < -2.5999999999999998e109

    1. Initial program 23.3%

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

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

      [Start]23.3

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

      *-commutative [=>]23.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 94.5%

      \[\leadsto \color{blue}{\frac{c}{b} + -1 \cdot \frac{b}{a}} \]
    4. Simplified94.5%

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

      [Start]94.5

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

      mul-1-neg [=>]94.5

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

      unsub-neg [=>]94.5

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

    if -2.5999999999999998e109 < b < -3.99999999999999991e-137

    1. Initial program 90.0%

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

    if -3.99999999999999991e-137 < b < 9.6000000000000002e-63

    1. Initial program 72.6%

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

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

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

      /-rgt-identity [<=]72.6

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

      metadata-eval [<=]72.6

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

      *-commutative [=>]72.6

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

      associate-/l* [=>]72.6

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

      associate-/l* [<=]72.6

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

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

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

      \[ \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-rr73.7%

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

    if 9.6000000000000002e-63 < b

    1. Initial program 17.3%

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

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

      [Start]17.3

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

      *-commutative [=>]17.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 86.6%

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

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

      [Start]86.6

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

      mul-1-neg [=>]86.6

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

      distribute-neg-frac [=>]86.6

      \[ \color{blue}{\frac{-c}{b}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification85.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.6 \cdot 10^{+109}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -4 \cdot 10^{-137}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 9.6 \cdot 10^{-63}:\\ \;\;\;\;\frac{0.5}{\frac{a}{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right) - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy84.7%
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -1.25 \cdot 10^{+112}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 9.6 \cdot 10^{-63}:\\ \;\;\;\;\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.8%
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -4 \cdot 10^{+114}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 1.2 \cdot 10^{-58}:\\ \;\;\;\;\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.3%
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -8.5 \cdot 10^{-67}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 2.5 \cdot 10^{-63}:\\ \;\;\;\;\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.2%
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -4.2 \cdot 10^{-62}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 3.1 \cdot 10^{-58}:\\ \;\;\;\;\frac{\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 5
Accuracy38.6%
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq 4.5 \cdot 10^{+31}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b}\\ \end{array} \]
Alternative 6
Accuracy64.5%
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq 1.3 \cdot 10^{-261}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 7
Accuracy11.6%
Cost192
\[\frac{c}{b} \]

Error

Reproduce?

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