?

Average Error: 34.5 → 7.0
Time: 1.9min
Precision: binary64
Cost: 56976

?

\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
\[\begin{array}{l} t_0 := \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ t_1 := \frac{c + 0.25 \cdot \left(a \cdot {\left(\frac{-2 \cdot c}{\left|b\right|}\right)}^{2}\right)}{\left|b\right|} + \frac{-0.5 \cdot \left(\left|b\right| + b\right)}{a}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq -2 \cdot 10^{-295}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;t_0 \leq 10^{+258}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - \left(4 \cdot c\right) \cdot a}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
        (t_1
         (+
          (/ (+ c (* 0.25 (* a (pow (/ (* -2.0 c) (fabs b)) 2.0)))) (fabs b))
          (/ (* -0.5 (+ (fabs b) b)) a))))
   (if (<= t_0 (- INFINITY))
     t_1
     (if (<= t_0 -2e-295)
       t_0
       (if (<= t_0 0.0)
         (/ (- c) b)
         (if (<= t_0 1e+258)
           (/ (- (- b) (sqrt (- (pow b 2.0) (* (* 4.0 c) a)))) (* 2.0 a))
           t_1))))))
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 = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
	double t_1 = ((c + (0.25 * (a * pow(((-2.0 * c) / fabs(b)), 2.0)))) / fabs(b)) + ((-0.5 * (fabs(b) + b)) / a);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = t_1;
	} else if (t_0 <= -2e-295) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = -c / b;
	} else if (t_0 <= 1e+258) {
		tmp = (-b - sqrt((pow(b, 2.0) - ((4.0 * c) * a)))) / (2.0 * a);
	} else {
		tmp = t_1;
	}
	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 = (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
	double t_1 = ((c + (0.25 * (a * Math.pow(((-2.0 * c) / Math.abs(b)), 2.0)))) / Math.abs(b)) + ((-0.5 * (Math.abs(b) + b)) / a);
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = t_1;
	} else if (t_0 <= -2e-295) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = -c / b;
	} else if (t_0 <= 1e+258) {
		tmp = (-b - Math.sqrt((Math.pow(b, 2.0) - ((4.0 * c) * a)))) / (2.0 * a);
	} else {
		tmp = t_1;
	}
	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 = (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
	t_1 = ((c + (0.25 * (a * math.pow(((-2.0 * c) / math.fabs(b)), 2.0)))) / math.fabs(b)) + ((-0.5 * (math.fabs(b) + b)) / a)
	tmp = 0
	if t_0 <= -math.inf:
		tmp = t_1
	elif t_0 <= -2e-295:
		tmp = t_0
	elif t_0 <= 0.0:
		tmp = -c / b
	elif t_0 <= 1e+258:
		tmp = (-b - math.sqrt((math.pow(b, 2.0) - ((4.0 * c) * a)))) / (2.0 * a)
	else:
		tmp = t_1
	return tmp
function code(a, b, c)
	return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a))
end
function code(a, b, c)
	t_0 = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a))
	t_1 = Float64(Float64(Float64(c + Float64(0.25 * Float64(a * (Float64(Float64(-2.0 * c) / abs(b)) ^ 2.0)))) / abs(b)) + Float64(Float64(-0.5 * Float64(abs(b) + b)) / a))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = t_1;
	elseif (t_0 <= -2e-295)
		tmp = t_0;
	elseif (t_0 <= 0.0)
		tmp = Float64(Float64(-c) / b);
	elseif (t_0 <= 1e+258)
		tmp = Float64(Float64(Float64(-b) - sqrt(Float64((b ^ 2.0) - Float64(Float64(4.0 * c) * a)))) / Float64(2.0 * a));
	else
		tmp = t_1;
	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 = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
	t_1 = ((c + (0.25 * (a * (((-2.0 * c) / abs(b)) ^ 2.0)))) / abs(b)) + ((-0.5 * (abs(b) + b)) / a);
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = t_1;
	elseif (t_0 <= -2e-295)
		tmp = t_0;
	elseif (t_0 <= 0.0)
		tmp = -c / b;
	elseif (t_0 <= 1e+258)
		tmp = (-b - sqrt(((b ^ 2.0) - ((4.0 * c) * a)))) / (2.0 * a);
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := Block[{t$95$0 = N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(c + N[(0.25 * N[(a * N[Power[N[(N[(-2.0 * c), $MachinePrecision] / N[Abs[b], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Abs[b], $MachinePrecision]), $MachinePrecision] + N[(N[(-0.5 * N[(N[Abs[b], $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], t$95$1, If[LessEqual[t$95$0, -2e-295], t$95$0, If[LessEqual[t$95$0, 0.0], N[((-c) / b), $MachinePrecision], If[LessEqual[t$95$0, 1e+258], N[(N[((-b) - N[Sqrt[N[(N[Power[b, 2.0], $MachinePrecision] - N[(N[(4.0 * c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\begin{array}{l}
t_0 := \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
t_1 := \frac{c + 0.25 \cdot \left(a \cdot {\left(\frac{-2 \cdot c}{\left|b\right|}\right)}^{2}\right)}{\left|b\right|} + \frac{-0.5 \cdot \left(\left|b\right| + b\right)}{a}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq -2 \cdot 10^{-295}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;\frac{-c}{b}\\

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

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original34.5
Target20.9
Herbie7.0
\[\begin{array}{l} \mathbf{if}\;b < 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \end{array} \]

Derivation?

  1. Split input into 4 regimes
  2. if (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))) (*.f64 2 a)) < -inf.0 or 1.00000000000000006e258 < (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))) (*.f64 2 a))

    1. Initial program 62.2

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
    2. Taylor expanded in a around 0 62.8

      \[\leadsto \color{blue}{\frac{c}{\sqrt{{b}^{2}}} + \left(0.25 \cdot \frac{a \cdot {\left(-2 \cdot \frac{c}{\sqrt{{b}^{2}}}\right)}^{2}}{\sqrt{{b}^{2}}} + -0.5 \cdot \frac{\sqrt{{b}^{2}} + b}{a}\right)} \]
    3. Simplified13.7

      \[\leadsto \color{blue}{\frac{c + 0.25 \cdot \left(a \cdot {\left(\frac{-2 \cdot c}{\left|b\right|}\right)}^{2}\right)}{\left|b\right|} + \frac{-0.5 \cdot \left(\left|b\right| + b\right)}{a}} \]
      Proof

    if -inf.0 < (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))) (*.f64 2 a)) < -2.00000000000000012e-295

    1. Initial program 4.0

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

    if -2.00000000000000012e-295 < (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))) (*.f64 2 a)) < 0.0

    1. Initial program 54.2

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
    2. Taylor expanded in b around -inf 0.1

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    3. Simplified0.1

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

    if 0.0 < (/.f64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))) (*.f64 2 a)) < 1.00000000000000006e258

    1. Initial program 4.7

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
    2. Applied egg-rr4.7

      \[\leadsto \frac{\left(-b\right) - \sqrt{\color{blue}{{b}^{2} - \left(4 \cdot c\right) \cdot a}}}{2 \cdot a} \]
  3. Recombined 4 regimes into one program.

Alternatives

Alternative 1
Error10.8
Cost14024
\[\begin{array}{l} \mathbf{if}\;b \leq -4.3 \cdot 10^{-162}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \leq 1.52 \cdot 10^{+141}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - \left(4 \cdot c\right) \cdot a}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]
Alternative 2
Error10.8
Cost7688
\[\begin{array}{l} \mathbf{if}\;b \leq -4.3 \cdot 10^{-162}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \leq 5.2 \cdot 10^{+141}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]
Alternative 3
Error14.4
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -4.3 \cdot 10^{-162}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \leq 2.45 \cdot 10^{-23}:\\ \;\;\;\;\frac{-0.5}{a} \cdot \left(\sqrt{-4 \cdot \left(c \cdot a\right)} + b\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]
Alternative 4
Error15.2
Cost7304
\[\begin{array}{l} \mathbf{if}\;b \leq -4.3 \cdot 10^{-162}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \leq 3.6 \cdot 10^{-156}:\\ \;\;\;\;\frac{-\sqrt{-4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]
Alternative 5
Error15.2
Cost7304
\[\begin{array}{l} \mathbf{if}\;b \leq -4.3 \cdot 10^{-162}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \leq 3.6 \cdot 10^{-156}:\\ \;\;\;\;\frac{-\sqrt{\left(-4 \cdot c\right) \cdot a}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]
Alternative 6
Error22.1
Cost580
\[\begin{array}{l} \mathbf{if}\;b \leq -1.8 \cdot 10^{-303}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]
Alternative 7
Error22.3
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq -2.5 \cdot 10^{-196}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{-a}\\ \end{array} \]
Alternative 8
Error45.2
Cost256
\[\frac{b}{-a} \]

Error

Reproduce?

herbie shell --seed 2023033 
(FPCore (a b c)
  :name "quadm (p42, negative)"
  :precision binary64

  :herbie-target
  (if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))