?

Average Error: 33.9 → 10.3
Time: 14.6s
Precision: binary64
Cost: 7624

?

\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
\[\begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{+138}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 1.6 \cdot 10^{-132}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\ \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 -5e+138)
   (/ (- b) a)
   (if (<= b 1.6e-132)
     (/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* a 2.0))
     (/ (- 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 <= -5e+138) {
		tmp = -b / a;
	} else if (b <= 1.6e-132) {
		tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
	} else {
		tmp = -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) :: tmp
    if (b <= (-5d+138)) then
        tmp = -b / a
    else if (b <= 1.6d-132) then
        tmp = (sqrt(((b * b) - (4.0d0 * (a * c)))) - b) / (a * 2.0d0)
    else
        tmp = -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 tmp;
	if (b <= -5e+138) {
		tmp = -b / a;
	} else if (b <= 1.6e-132) {
		tmp = (Math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
	} 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 <= -5e+138:
		tmp = -b / a
	elif b <= 1.6e-132:
		tmp = (math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0)
	else:
		tmp = -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)
	tmp = 0.0
	if (b <= -5e+138)
		tmp = Float64(Float64(-b) / a);
	elseif (b <= 1.6e-132)
		tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) - b) / Float64(a * 2.0));
	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 <= -5e+138)
		tmp = -b / a;
	elseif (b <= 1.6e-132)
		tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
	else
		tmp = -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_] := If[LessEqual[b, -5e+138], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.6e-132], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{+138}:\\
\;\;\;\;\frac{-b}{a}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original33.9
Target20.7
Herbie10.3
\[\begin{array}{l} \mathbf{if}\;b < 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \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 3 regimes
  2. if b < -5.00000000000000016e138

    1. Initial program 57.3

      \[\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 2.6

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    3. Simplified2.6

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

      [Start]2.6

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

      associate-*r/ [=>]2.6

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

      mul-1-neg [=>]2.6

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

    if -5.00000000000000016e138 < b < 1.6000000000000001e-132

    1. Initial program 10.7

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

    if 1.6000000000000001e-132 < b

    1. Initial program 50.7

      \[\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 12.1

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

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

      [Start]12.1

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

      associate-*r/ [=>]12.1

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

      neg-mul-1 [<=]12.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{+138}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 1.6 \cdot 10^{-132}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]

Alternatives

Alternative 1
Error10.4
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -2.9 \cdot 10^{+86}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 1.5 \cdot 10^{-132}:\\ \;\;\;\;\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
Error13.8
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -2.35 \cdot 10^{-92}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 1.45 \cdot 10^{-132}:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{\left(a \cdot c\right) \cdot -4} - b\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 3
Error13.8
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -6.8 \cdot 10^{-93}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 1.25 \cdot 10^{-132}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 4
Error39.8
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq 2.65 \cdot 10^{-104}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 5
Error23.0
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq 8.5 \cdot 10^{-218}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 6
Error56.6
Cost64
\[0 \]

Error

Reproduce?

herbie shell --seed 2023027 
(FPCore (a b c)
  :name "quadp (p42, positive)"
  :precision binary64

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

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