?

Average Error: 33.8 → 10.7
Time: 20.0s
Precision: binary64
Cost: 7688

?

\[\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 -1.35 \cdot 10^{+154}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq 4.4 \cdot 10^{-148}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}{a + a}\\ \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 -1.35e+154)
   (- (/ b a))
   (if (<= b 4.4e-148)
     (/ (+ (- b) (sqrt (- (* b b) (* a (* 4.0 c))))) (+ a 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 tmp;
	if (b <= -1.35e+154) {
		tmp = -(b / a);
	} else if (b <= 4.4e-148) {
		tmp = (-b + sqrt(((b * b) - (a * (4.0 * c))))) / (a + a);
	} 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 <= (-1.35d+154)) then
        tmp = -(b / a)
    else if (b <= 4.4d-148) then
        tmp = (-b + sqrt(((b * b) - (a * (4.0d0 * c))))) / (a + a)
    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 <= -1.35e+154) {
		tmp = -(b / a);
	} else if (b <= 4.4e-148) {
		tmp = (-b + Math.sqrt(((b * b) - (a * (4.0 * c))))) / (a + a);
	} 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 <= -1.35e+154:
		tmp = -(b / a)
	elif b <= 4.4e-148:
		tmp = (-b + math.sqrt(((b * b) - (a * (4.0 * c))))) / (a + a)
	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 <= -1.35e+154)
		tmp = Float64(-Float64(b / a));
	elseif (b <= 4.4e-148)
		tmp = Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(a * Float64(4.0 * c))))) / Float64(a + a));
	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 <= -1.35e+154)
		tmp = -(b / a);
	elseif (b <= 4.4e-148)
		tmp = (-b + sqrt(((b * b) - (a * (4.0 * c))))) / (a + a);
	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, -1.35e+154], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 4.4e-148], N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(4.0 * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a + a), $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 -1.35 \cdot 10^{+154}:\\
\;\;\;\;-\frac{b}{a}\\

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

\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.8
Herbie10.7
\[\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 < -1.35000000000000003e154

    1. Initial program 64.0

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

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

      [Start]64.0

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

      rational_best_45_simplify-25 [=>]64.0

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

      rational_best_45_simplify-91 [=>]64.0

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

      metadata-eval [<=]64.0

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

      metadata-eval [<=]64.0

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

      metadata-eval [<=]64.0

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

      rational_best_45_simplify-71 [<=]64.0

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

      rational_best_45_simplify-91 [<=]64.0

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

      rational_best_45_simplify-91 [=>]64.0

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

      rational_best_45_simplify-71 [=>]64.0

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

      rational_best_45_simplify-91 [=>]64.0

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

      metadata-eval [=>]64.0

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

      rational_best_45_simplify-8 [=>]64.0

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

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

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

      [Start]1.9

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

      rational_best_45_simplify-91 [=>]1.9

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

      rational_best_45_simplify-16 [=>]1.9

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

    if -1.35000000000000003e154 < b < 4.40000000000000034e-148

    1. Initial program 10.2

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

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

      [Start]10.2

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

      rational_best_45_simplify-25 [=>]10.2

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

      rational_best_45_simplify-91 [=>]10.2

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

      metadata-eval [<=]10.2

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

      metadata-eval [<=]10.2

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

      metadata-eval [<=]10.2

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

      rational_best_45_simplify-71 [<=]10.2

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

      rational_best_45_simplify-91 [<=]10.2

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

      rational_best_45_simplify-91 [=>]10.2

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

      rational_best_45_simplify-71 [=>]10.2

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

      rational_best_45_simplify-91 [=>]10.2

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

      metadata-eval [=>]10.2

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

      rational_best_45_simplify-8 [=>]10.2

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

    if 4.40000000000000034e-148 < b

    1. Initial program 49.1

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

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

      [Start]49.1

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

      rational_best_45_simplify-25 [=>]49.1

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

      rational_best_45_simplify-91 [=>]49.1

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

      metadata-eval [<=]49.1

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

      metadata-eval [<=]49.1

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

      metadata-eval [<=]49.1

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

      rational_best_45_simplify-71 [<=]49.1

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

      rational_best_45_simplify-91 [<=]49.1

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

      rational_best_45_simplify-91 [=>]49.1

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

      rational_best_45_simplify-71 [=>]49.1

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

      rational_best_45_simplify-91 [=>]49.1

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

      metadata-eval [=>]49.1

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

      rational_best_45_simplify-8 [=>]49.1

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

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

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

      [Start]13.4

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

      rational_best_45_simplify-91 [=>]13.4

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

      rational_best_45_simplify-16 [=>]13.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.35 \cdot 10^{+154}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq 4.4 \cdot 10^{-148}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}{a + a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]

Alternatives

Alternative 1
Error10.8
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{+148}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq 1.4 \cdot 10^{-153}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a + a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
Alternative 2
Error14.3
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -1.55 \cdot 10^{-91}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 3.5 \cdot 10^{-148}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a + a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
Alternative 3
Error23.2
Cost580
\[\begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
Alternative 4
Error39.8
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq 5.8 \cdot 10^{+15}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b}\\ \end{array} \]
Alternative 5
Error23.1
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq 6 \cdot 10^{-260}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]
Alternative 6
Error56.4
Cost192
\[\frac{c}{b} \]

Error

Reproduce?

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