?

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

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

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original33.8
Target20.7
Herbie10.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 3 regimes
  2. if b < -3.5000000000000001e-69

    1. Initial program 53.2

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

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

      [Start]53.2

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

      rational_best-simplify-53 [=>]54.3

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

      rational_best-simplify-54 [=>]53.2

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

      rational_best-simplify-12 [<=]53.2

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

      rational_best-simplify-2 [=>]53.2

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

      rational_best-simplify-10 [=>]53.2

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

      rational_best-simplify-49 [=>]53.2

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

      rational_best-simplify-4 [=>]53.2

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

      rational_best-simplify-2 [=>]53.2

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

      rational_best-simplify-44 [=>]53.2

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

      metadata-eval [=>]53.2

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

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

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

      [Start]8.9

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

      rational_best-simplify-2 [=>]8.9

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

      rational_best-simplify-12 [=>]8.9

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

      rational_best-simplify-9 [=>]8.9

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

      rational_best-simplify-48 [=>]8.9

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

      rational_best-simplify-2 [=>]8.9

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

      rational_best-simplify-13 [<=]8.9

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

    if -3.5000000000000001e-69 < b < 7.9999999999999999e46

    1. Initial program 13.2

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

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

      [Start]13.2

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

      rational_best-simplify-53 [=>]13.2

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

      rational_best-simplify-54 [=>]13.2

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

      rational_best-simplify-12 [<=]13.2

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

      rational_best-simplify-2 [=>]13.2

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

      rational_best-simplify-10 [=>]13.2

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

      rational_best-simplify-49 [=>]13.2

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

      rational_best-simplify-4 [=>]13.2

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

      rational_best-simplify-2 [=>]13.2

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

      rational_best-simplify-44 [=>]13.2

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

      metadata-eval [=>]13.2

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

    if 7.9999999999999999e46 < b

    1. Initial program 36.8

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

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

      [Start]36.8

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

      rational_best-simplify-53 [=>]36.7

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

      rational_best-simplify-54 [=>]36.8

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

      rational_best-simplify-12 [<=]36.8

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

      rational_best-simplify-2 [=>]36.8

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

      rational_best-simplify-10 [=>]36.8

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

      rational_best-simplify-49 [=>]36.8

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

      rational_best-simplify-4 [=>]36.8

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

      rational_best-simplify-2 [=>]36.8

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

      rational_best-simplify-44 [=>]36.8

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

      metadata-eval [=>]36.8

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

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

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

      [Start]5.7

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

      rational_best-simplify-2 [=>]5.7

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

      rational_best-simplify-12 [=>]5.7

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

      rational_best-simplify-9 [=>]5.7

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

      rational_best-simplify-48 [=>]5.7

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

      rational_best-simplify-2 [<=]5.7

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

      rational_best-simplify-13 [<=]5.7

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

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

Alternatives

Alternative 1
Error13.7
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -5.4 \cdot 10^{-73}:\\ \;\;\;\;\frac{c}{-b}\\ \mathbf{elif}\;b \leq 3.5 \cdot 10^{-12}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} + b}{a \cdot -2}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{-a}\\ \end{array} \]
Alternative 2
Error19.4
Cost7112
\[\begin{array}{l} \mathbf{if}\;b \leq -3.15 \cdot 10^{-136}:\\ \;\;\;\;\frac{c}{-b}\\ \mathbf{elif}\;b \leq 6.3 \cdot 10^{-133}:\\ \;\;\;\;-0.5 \cdot \sqrt{-4 \cdot \frac{c}{a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{-a}\\ \end{array} \]
Alternative 3
Error39.5
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq -6 \cdot 10^{+29}:\\ \;\;\;\;\frac{c}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{-a}\\ \end{array} \]
Alternative 4
Error22.5
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq -1.25 \cdot 10^{-224}:\\ \;\;\;\;\frac{c}{-b}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{-a}\\ \end{array} \]
Alternative 5
Error56.3
Cost192
\[\frac{c}{b} \]

Error

Reproduce?

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