?

Average Error: 34.3 → 11.3
Time: 16.8s
Precision: binary64
Cost: 9096

?

\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
\[\begin{array}{l} t_0 := b \cdot b - 4 \cdot \left(a \cdot c\right)\\ t_1 := -\frac{c}{b}\\ \mathbf{if}\;b \leq -1.5 \cdot 10^{+51}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq -5.8 \cdot 10^{+15}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{t_0 \cdot \left(t_0 \cdot \frac{1}{t_0}\right)}}{a \cdot 2}\\ \mathbf{elif}\;b \leq -4.6 \cdot 10^{-76}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 4.6 \cdot 10^{+115}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{t_0}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\left(-\frac{b}{a}\right) + \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
 (let* ((t_0 (- (* b b) (* 4.0 (* a c)))) (t_1 (- (/ c b))))
   (if (<= b -1.5e+51)
     t_1
     (if (<= b -5.8e+15)
       (/ (- (- b) (sqrt (* t_0 (* t_0 (/ 1.0 t_0))))) (* a 2.0))
       (if (<= b -4.6e-76)
         t_1
         (if (<= b 4.6e+115)
           (/ (- (- b) (sqrt t_0)) (* 2.0 a))
           (+ (- (/ b a)) (/ 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 t_0 = (b * b) - (4.0 * (a * c));
	double t_1 = -(c / b);
	double tmp;
	if (b <= -1.5e+51) {
		tmp = t_1;
	} else if (b <= -5.8e+15) {
		tmp = (-b - sqrt((t_0 * (t_0 * (1.0 / t_0))))) / (a * 2.0);
	} else if (b <= -4.6e-76) {
		tmp = t_1;
	} else if (b <= 4.6e+115) {
		tmp = (-b - sqrt(t_0)) / (2.0 * a);
	} else {
		tmp = -(b / a) + (c / 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) - (4.0d0 * (a * c))))) / (2.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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (b * b) - (4.0d0 * (a * c))
    t_1 = -(c / b)
    if (b <= (-1.5d+51)) then
        tmp = t_1
    else if (b <= (-5.8d+15)) then
        tmp = (-b - sqrt((t_0 * (t_0 * (1.0d0 / t_0))))) / (a * 2.0d0)
    else if (b <= (-4.6d-76)) then
        tmp = t_1
    else if (b <= 4.6d+115) then
        tmp = (-b - sqrt(t_0)) / (2.0d0 * a)
    else
        tmp = -(b / a) + (c / b)
    end if
    code = tmp
end function
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 * b) - (4.0 * (a * c));
	double t_1 = -(c / b);
	double tmp;
	if (b <= -1.5e+51) {
		tmp = t_1;
	} else if (b <= -5.8e+15) {
		tmp = (-b - Math.sqrt((t_0 * (t_0 * (1.0 / t_0))))) / (a * 2.0);
	} else if (b <= -4.6e-76) {
		tmp = t_1;
	} else if (b <= 4.6e+115) {
		tmp = (-b - Math.sqrt(t_0)) / (2.0 * a);
	} else {
		tmp = -(b / a) + (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):
	t_0 = (b * b) - (4.0 * (a * c))
	t_1 = -(c / b)
	tmp = 0
	if b <= -1.5e+51:
		tmp = t_1
	elif b <= -5.8e+15:
		tmp = (-b - math.sqrt((t_0 * (t_0 * (1.0 / t_0))))) / (a * 2.0)
	elif b <= -4.6e-76:
		tmp = t_1
	elif b <= 4.6e+115:
		tmp = (-b - math.sqrt(t_0)) / (2.0 * a)
	else:
		tmp = -(b / a) + (c / b)
	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(b * b) - Float64(4.0 * Float64(a * c)))
	t_1 = Float64(-Float64(c / b))
	tmp = 0.0
	if (b <= -1.5e+51)
		tmp = t_1;
	elseif (b <= -5.8e+15)
		tmp = Float64(Float64(Float64(-b) - sqrt(Float64(t_0 * Float64(t_0 * Float64(1.0 / t_0))))) / Float64(a * 2.0));
	elseif (b <= -4.6e-76)
		tmp = t_1;
	elseif (b <= 4.6e+115)
		tmp = Float64(Float64(Float64(-b) - sqrt(t_0)) / Float64(2.0 * a));
	else
		tmp = Float64(Float64(-Float64(b / a)) + 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)
	t_0 = (b * b) - (4.0 * (a * c));
	t_1 = -(c / b);
	tmp = 0.0;
	if (b <= -1.5e+51)
		tmp = t_1;
	elseif (b <= -5.8e+15)
		tmp = (-b - sqrt((t_0 * (t_0 * (1.0 / t_0))))) / (a * 2.0);
	elseif (b <= -4.6e-76)
		tmp = t_1;
	elseif (b <= 4.6e+115)
		tmp = (-b - sqrt(t_0)) / (2.0 * a);
	else
		tmp = -(b / a) + (c / b);
	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 * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = (-N[(c / b), $MachinePrecision])}, If[LessEqual[b, -1.5e+51], t$95$1, If[LessEqual[b, -5.8e+15], N[(N[((-b) - N[Sqrt[N[(t$95$0 * N[(t$95$0 * N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -4.6e-76], t$95$1, If[LessEqual[b, 4.6e+115], N[(N[((-b) - N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[((-N[(b / a), $MachinePrecision]) + N[(c / b), $MachinePrecision]), $MachinePrecision]]]]]]]
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\begin{array}{l}
t_0 := b \cdot b - 4 \cdot \left(a \cdot c\right)\\
t_1 := -\frac{c}{b}\\
\mathbf{if}\;b \leq -1.5 \cdot 10^{+51}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;b \leq -5.8 \cdot 10^{+15}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{t_0 \cdot \left(t_0 \cdot \frac{1}{t_0}\right)}}{a \cdot 2}\\

\mathbf{elif}\;b \leq -4.6 \cdot 10^{-76}:\\
\;\;\;\;t_1\\

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

\mathbf{else}:\\
\;\;\;\;\left(-\frac{b}{a}\right) + \frac{c}{b}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original34.3
Target21.1
Herbie11.3
\[\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 b < -1.5e51 or -5.8e15 < b < -4.60000000000000012e-76

    1. Initial program 53.6

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

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

      [Start]53.6

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

      rational_best-simplify-2 [=>]53.6

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    4. Simplified8.7

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

      [Start]8.7

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

      rational_best-simplify-2 [=>]8.7

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

      rational_best-simplify-12 [=>]8.7

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

    if -1.5e51 < b < -5.8e15

    1. Initial program 45.1

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

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

      [Start]45.1

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

      rational_best-simplify-2 [=>]45.1

      \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{a \cdot 2}} \]
    3. Applied egg-rr45.8

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

    if -4.60000000000000012e-76 < b < 4.60000000000000007e115

    1. Initial program 13.1

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

    if 4.60000000000000007e115 < b

    1. Initial program 51.6

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

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

      [Start]51.6

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

      rational_best-simplify-2 [=>]51.6

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

      \[\leadsto \color{blue}{\frac{c}{b} + -1 \cdot \frac{b}{a}} \]
    4. Simplified2.9

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

      [Start]2.9

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

      rational_best-simplify-1 [=>]2.9

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

      rational_best-simplify-2 [=>]2.9

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

      rational_best-simplify-12 [=>]2.9

      \[ \color{blue}{\left(-\frac{b}{a}\right)} + \frac{c}{b} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification11.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.5 \cdot 10^{+51}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq -5.8 \cdot 10^{+15}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{\left(b \cdot b - 4 \cdot \left(a \cdot c\right)\right) \cdot \left(\left(b \cdot b - 4 \cdot \left(a \cdot c\right)\right) \cdot \frac{1}{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}}{a \cdot 2}\\ \mathbf{elif}\;b \leq -4.6 \cdot 10^{-76}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 4.6 \cdot 10^{+115}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\left(-\frac{b}{a}\right) + \frac{c}{b}\\ \end{array} \]

Alternatives

Alternative 1
Error11.3
Cost7952
\[\begin{array}{l} t_0 := -\frac{c}{b}\\ t_1 := \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{if}\;b \leq -1.5 \cdot 10^{+51}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq -5 \cdot 10^{+15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq -2.5 \cdot 10^{-76}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 2 \cdot 10^{+114}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left(-\frac{b}{a}\right) + \frac{c}{b}\\ \end{array} \]
Alternative 2
Error15.1
Cost7696
\[\begin{array}{l} t_0 := -\frac{c}{b}\\ t_1 := \frac{\left(-b\right) - \sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\ \mathbf{if}\;b \leq -1.5 \cdot 10^{+51}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq -5.8 \cdot 10^{+15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq -4.7 \cdot 10^{-76}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 1.85 \cdot 10^{-65}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left(-\frac{b}{a}\right) + \frac{c}{b}\\ \end{array} \]
Alternative 3
Error13.9
Cost7304
\[\begin{array}{l} \mathbf{if}\;b \leq -4.1 \cdot 10^{-76}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 2 \cdot 10^{-66}:\\ \;\;\;\;\frac{-\sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\left(-\frac{b}{a}\right) + \frac{c}{b}\\ \end{array} \]
Alternative 4
Error20.6
Cost7112
\[\begin{array}{l} \mathbf{if}\;b \leq -3.35 \cdot 10^{-77}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 7.3 \cdot 10^{-68}:\\ \;\;\;\;-0.5 \cdot \sqrt{-4 \cdot \frac{c}{a}}\\ \mathbf{else}:\\ \;\;\;\;\left(-\frac{b}{a}\right) + \frac{c}{b}\\ \end{array} \]
Alternative 5
Error22.7
Cost644
\[\begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;\left(-\frac{b}{a}\right) + \frac{c}{b}\\ \end{array} \]
Alternative 6
Error22.7
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq -1.38 \cdot 10^{-285}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array} \]
Alternative 7
Error45.4
Cost256
\[-\frac{b}{a} \]

Error

Reproduce?

herbie shell --seed 2023092 
(FPCore (a b c)
  :name "The quadratic formula (r2)"
  :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)))