?

Average Error: 33.8 → 10.6
Time: 9.0s
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 -7 \cdot 10^{+126}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq 2.7 \cdot 10^{-134}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + \left(a \cdot c\right) \cdot -4} - 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 -7e+126)
   (- (/ b a))
   (if (<= b 2.7e-134)
     (/ (- (sqrt (+ (* b b) (* (* a c) -4.0))) 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 <= -7e+126) {
		tmp = -(b / a);
	} else if (b <= 2.7e-134) {
		tmp = (sqrt(((b * b) + ((a * c) * -4.0))) - 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 <= (-7d+126)) then
        tmp = -(b / a)
    else if (b <= 2.7d-134) then
        tmp = (sqrt(((b * b) + ((a * c) * (-4.0d0)))) - 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 <= -7e+126) {
		tmp = -(b / a);
	} else if (b <= 2.7e-134) {
		tmp = (Math.sqrt(((b * b) + ((a * c) * -4.0))) - 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 <= -7e+126:
		tmp = -(b / a)
	elif b <= 2.7e-134:
		tmp = (math.sqrt(((b * b) + ((a * c) * -4.0))) - 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 <= -7e+126)
		tmp = Float64(-Float64(b / a));
	elseif (b <= 2.7e-134)
		tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(Float64(a * c) * -4.0))) - 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 <= -7e+126)
		tmp = -(b / a);
	elseif (b <= 2.7e-134)
		tmp = (sqrt(((b * b) + ((a * c) * -4.0))) - 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, -7e+126], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 2.7e-134], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(N[(a * c), $MachinePrecision] * -4.0), $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 -7 \cdot 10^{+126}:\\
\;\;\;\;-\frac{b}{a}\\

\mathbf{elif}\;b \leq 2.7 \cdot 10^{-134}:\\
\;\;\;\;\frac{\sqrt{b \cdot b + \left(a \cdot c\right) \cdot -4} - 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.8
Target20.7
Herbie10.6
\[\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 < -7.0000000000000005e126

    1. Initial program 54.9

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

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

      [Start]54.9

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

      rational_best-simplify-62 [=>]54.9

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

      rational_best-simplify-61 [=>]54.9

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

      rational_best-simplify-52 [=>]54.9

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

      metadata-eval [=>]54.9

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

      rational_best-simplify-51 [=>]54.9

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

      rational_best-simplify-3 [=>]54.9

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    4. Simplified3.0

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

      [Start]3.0

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

      rational_best-simplify-3 [=>]3.0

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

      rational_best-simplify-17 [=>]3.0

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

    if -7.0000000000000005e126 < b < 2.6999999999999998e-134

    1. Initial program 10.6

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

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

      [Start]10.6

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

      rational_best-simplify-62 [=>]10.6

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

      rational_best-simplify-61 [=>]10.6

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

      rational_best-simplify-52 [=>]10.6

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

      metadata-eval [=>]10.6

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

      rational_best-simplify-51 [=>]10.6

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

      rational_best-simplify-3 [=>]10.6

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

    if 2.6999999999999998e-134 < b

    1. Initial program 50.1

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

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

      [Start]50.1

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

      rational_best-simplify-62 [=>]50.1

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

      rational_best-simplify-61 [=>]50.1

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

      rational_best-simplify-52 [=>]50.1

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

      metadata-eval [=>]50.1

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

      rational_best-simplify-51 [=>]50.1

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

      rational_best-simplify-3 [=>]50.1

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

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

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

      [Start]12.9

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

      rational_best-simplify-3 [=>]12.9

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

      rational_best-simplify-17 [=>]12.9

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

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

Alternatives

Alternative 1
Error19.9
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -9.6 \cdot 10^{-155}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 5.5 \cdot 10^{-171}:\\ \;\;\;\;0.5 \cdot \left(\sqrt{\frac{c}{a} \cdot -4} - \frac{b}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
Alternative 2
Error14.6
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -1.05 \cdot 10^{-154}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 2.3 \cdot 10^{-134}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
Alternative 3
Error20.0
Cost7112
\[\begin{array}{l} \mathbf{if}\;b \leq -2 \cdot 10^{-155}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 8.5 \cdot 10^{-169}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{c}{a} \cdot -4}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
Alternative 4
Error39.3
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq 6 \cdot 10^{+37}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b}\\ \end{array} \]
Alternative 5
Error22.8
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq 6.5 \cdot 10^{-301}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
Alternative 6
Error56.7
Cost192
\[\frac{c}{b} \]

Error

Reproduce?

herbie shell --seed 2023104 
(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)))