?

Average Error: 34.3 → 12.1
Time: 20.0s
Precision: binary64
Cost: 13900

?

\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
\[\begin{array}{l} t_0 := \frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{if}\;b \leq -8 \cdot 10^{+143}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 1.9 \cdot 10^{-299}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 4.8 \cdot 10^{-116}:\\ \;\;\;\;\left(\sqrt{a \cdot -4} \cdot \sqrt{c} - b\right) \cdot \frac{0.5}{a}\\ \mathbf{elif}\;b \leq 6 \cdot 10^{-26}:\\ \;\;\;\;t_0\\ \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
 (let* ((t_0 (/ (- (sqrt (+ (* b b) (* c (* a -4.0)))) b) (* a 2.0))))
   (if (<= b -8e+143)
     (/ (- b) a)
     (if (<= b 1.9e-299)
       t_0
       (if (<= b 4.8e-116)
         (* (- (* (sqrt (* a -4.0)) (sqrt c)) b) (/ 0.5 a))
         (if (<= b 6e-26) t_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 t_0 = (sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0);
	double tmp;
	if (b <= -8e+143) {
		tmp = -b / a;
	} else if (b <= 1.9e-299) {
		tmp = t_0;
	} else if (b <= 4.8e-116) {
		tmp = ((sqrt((a * -4.0)) * sqrt(c)) - b) * (0.5 / a);
	} else if (b <= 6e-26) {
		tmp = t_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) :: t_0
    real(8) :: tmp
    t_0 = (sqrt(((b * b) + (c * (a * (-4.0d0))))) - b) / (a * 2.0d0)
    if (b <= (-8d+143)) then
        tmp = -b / a
    else if (b <= 1.9d-299) then
        tmp = t_0
    else if (b <= 4.8d-116) then
        tmp = ((sqrt((a * (-4.0d0))) * sqrt(c)) - b) * (0.5d0 / a)
    else if (b <= 6d-26) then
        tmp = t_0
    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 t_0 = (Math.sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0);
	double tmp;
	if (b <= -8e+143) {
		tmp = -b / a;
	} else if (b <= 1.9e-299) {
		tmp = t_0;
	} else if (b <= 4.8e-116) {
		tmp = ((Math.sqrt((a * -4.0)) * Math.sqrt(c)) - b) * (0.5 / a);
	} else if (b <= 6e-26) {
		tmp = t_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):
	t_0 = (math.sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0)
	tmp = 0
	if b <= -8e+143:
		tmp = -b / a
	elif b <= 1.9e-299:
		tmp = t_0
	elif b <= 4.8e-116:
		tmp = ((math.sqrt((a * -4.0)) * math.sqrt(c)) - b) * (0.5 / a)
	elif b <= 6e-26:
		tmp = t_0
	else:
		tmp = -c / b
	return tmp
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a))
end
function code(a, b, c)
	t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0))
	tmp = 0.0
	if (b <= -8e+143)
		tmp = Float64(Float64(-b) / a);
	elseif (b <= 1.9e-299)
		tmp = t_0;
	elseif (b <= 4.8e-116)
		tmp = Float64(Float64(Float64(sqrt(Float64(a * -4.0)) * sqrt(c)) - b) * Float64(0.5 / a));
	elseif (b <= 6e-26)
		tmp = t_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)
	t_0 = (sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0);
	tmp = 0.0;
	if (b <= -8e+143)
		tmp = -b / a;
	elseif (b <= 1.9e-299)
		tmp = t_0;
	elseif (b <= 4.8e-116)
		tmp = ((sqrt((a * -4.0)) * sqrt(c)) - b) * (0.5 / a);
	elseif (b <= 6e-26)
		tmp = t_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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -8e+143], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.9e-299], t$95$0, If[LessEqual[b, 4.8e-116], N[(N[(N[(N[Sqrt[N[(a * -4.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[c], $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 6e-26], t$95$0, N[((-c) / b), $MachinePrecision]]]]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{if}\;b \leq -8 \cdot 10^{+143}:\\
\;\;\;\;\frac{-b}{a}\\

\mathbf{elif}\;b \leq 1.9 \cdot 10^{-299}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;b \leq 4.8 \cdot 10^{-116}:\\
\;\;\;\;\left(\sqrt{a \cdot -4} \cdot \sqrt{c} - b\right) \cdot \frac{0.5}{a}\\

\mathbf{elif}\;b \leq 6 \cdot 10^{-26}:\\
\;\;\;\;t_0\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 4 regimes
  2. if b < -8.0000000000000002e143

    1. Initial program 60.3

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

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

      [Start]60.3

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

      /-rgt-identity [<=]60.3

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

      metadata-eval [<=]60.3

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

      *-commutative [=>]60.3

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

      associate-/l* [=>]60.3

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

      associate-/l* [<=]60.3

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

      associate-*r/ [<=]60.3

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

      /-rgt-identity [<=]60.3

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

      metadata-eval [<=]60.3

      \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{--1}} \cdot \frac{\frac{--1}{2}}{a} \]
    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} \]

      associate-*r/ [=>]3.0

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

      mul-1-neg [=>]3.0

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

    if -8.0000000000000002e143 < b < 1.9000000000000001e-299 or 4.79999999999999986e-116 < b < 6.00000000000000023e-26

    1. Initial program 13.2

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

    if 1.9000000000000001e-299 < b < 4.79999999999999986e-116

    1. Initial program 18.3

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

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

      [Start]18.3

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

      /-rgt-identity [<=]18.3

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

      metadata-eval [<=]18.3

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

      *-commutative [=>]18.3

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

      associate-/l* [=>]18.3

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

      associate-/l* [<=]18.3

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

      associate-*r/ [<=]18.3

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

      /-rgt-identity [<=]18.3

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

      metadata-eval [<=]18.3

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

      \[\leadsto \left(\color{blue}{{\left({\left(\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)\right)}^{0.25}\right)}^{2}} - b\right) \cdot \frac{0.5}{a} \]
    4. Taylor expanded in b around 0 18.8

      \[\leadsto \left({\color{blue}{\left({\left(-4 \cdot \left(c \cdot a\right)\right)}^{0.25}\right)}}^{2} - b\right) \cdot \frac{0.5}{a} \]
    5. Simplified18.8

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

      [Start]18.8

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

      associate-*r* [=>]18.8

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

      *-commutative [=>]18.8

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

      associate-*l* [=>]18.8

      \[ \left({\left({\color{blue}{\left(c \cdot \left(-4 \cdot a\right)\right)}}^{0.25}\right)}^{2} - b\right) \cdot \frac{0.5}{a} \]
    6. Applied egg-rr36.8

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

    if 6.00000000000000023e-26 < b

    1. Initial program 54.5

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

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

      [Start]54.5

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

      *-commutative [=>]54.5

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

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

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

      [Start]6.6

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

      mul-1-neg [=>]6.6

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

      distribute-neg-frac [=>]6.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -8 \cdot 10^{+143}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 1.9 \cdot 10^{-299}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 4.8 \cdot 10^{-116}:\\ \;\;\;\;\left(\sqrt{a \cdot -4} \cdot \sqrt{c} - b\right) \cdot \frac{0.5}{a}\\ \mathbf{elif}\;b \leq 6 \cdot 10^{-26}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]

Alternatives

Alternative 1
Error10.2
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -1.8 \cdot 10^{+149}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 7 \cdot 10^{-25}:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 2
Error10.2
Cost7624
\[\begin{array}{l} \mathbf{if}\;b \leq -1.25 \cdot 10^{+144}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq 4.1 \cdot 10^{-25}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 3
Error13.8
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -3.4 \cdot 10^{-9}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 1.05 \cdot 10^{-26}:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{c \cdot \left(a \cdot -4\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 4
Error13.8
Cost7368
\[\begin{array}{l} \mathbf{if}\;b \leq -4.8 \cdot 10^{-9}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 1.4 \cdot 10^{-25}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{\frac{a}{0.5}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 5
Error39.6
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq 6.8 \cdot 10^{+28}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b}\\ \end{array} \]
Alternative 6
Error22.3
Cost388
\[\begin{array}{l} \mathbf{if}\;b \leq 2.2 \cdot 10^{-289}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]
Alternative 7
Error56.7
Cost192
\[\frac{c}{b} \]

Error

Reproduce?

herbie shell --seed 2023056 
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))