# ?

Average Error: 22.0 → 6.0
Time: 22.6s
Precision: binary64
Cost: 7624

# ?

$\left(\left(-1.78 \cdot 10^{+308} \leq b \land b \leq 1.79 \cdot 10^{+308}\right) \land \left(-1.78 \cdot 10^{+308} \leq a \land a \leq 1.79 \cdot 10^{+308}\right)\right) \land \left(-1.79 \cdot 10^{+308} \leq c \land c \leq 1.79 \cdot 10^{+308}\right)$
$\left(-b\right) + \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}$
$\begin{array}{l} \mathbf{if}\;b \leq -4.8 \cdot 10^{+50}:\\ \;\;\;\;\frac{b}{a} \cdot -0.5 - b\\ \mathbf{elif}\;b \leq 1.04 \cdot 10^{+111}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}}{a \cdot 2} - b\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{0.5}{a} - b\\ \end{array}$
(FPCore (b a c)
:precision binary64
(+ (- b) (/ (sqrt (- (* b b) (* (* 4.0 a) c))) (* 2.0 a))))
(FPCore (b a c)
:precision binary64
(if (<= b -4.8e+50)
(- (* (/ b a) -0.5) b)
(if (<= b 1.04e+111)
(- (/ (sqrt (+ (* b b) (* c (* a -4.0)))) (* a 2.0)) b)
(- (* b (/ 0.5 a)) b))))
double code(double b, double a, double c) {
return -b + (sqrt(((b * b) - ((4.0 * a) * c))) / (2.0 * a));
}

double code(double b, double a, double c) {
double tmp;
if (b <= -4.8e+50) {
tmp = ((b / a) * -0.5) - b;
} else if (b <= 1.04e+111) {
tmp = (sqrt(((b * b) + (c * (a * -4.0)))) / (a * 2.0)) - b;
} else {
tmp = (b * (0.5 / a)) - b;
}
return tmp;
}

real(8) function code(b, a, c)
real(8), intent (in) :: b
real(8), intent (in) :: a
real(8), intent (in) :: c
code = -b + (sqrt(((b * b) - ((4.0d0 * a) * c))) / (2.0d0 * a))
end function

real(8) function code(b, a, c)
real(8), intent (in) :: b
real(8), intent (in) :: a
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-4.8d+50)) then
tmp = ((b / a) * (-0.5d0)) - b
else if (b <= 1.04d+111) then
tmp = (sqrt(((b * b) + (c * (a * (-4.0d0))))) / (a * 2.0d0)) - b
else
tmp = (b * (0.5d0 / a)) - b
end if
code = tmp
end function

public static double code(double b, double a, double c) {
return -b + (Math.sqrt(((b * b) - ((4.0 * a) * c))) / (2.0 * a));
}

public static double code(double b, double a, double c) {
double tmp;
if (b <= -4.8e+50) {
tmp = ((b / a) * -0.5) - b;
} else if (b <= 1.04e+111) {
tmp = (Math.sqrt(((b * b) + (c * (a * -4.0)))) / (a * 2.0)) - b;
} else {
tmp = (b * (0.5 / a)) - b;
}
return tmp;
}

def code(b, a, c):
return -b + (math.sqrt(((b * b) - ((4.0 * a) * c))) / (2.0 * a))

def code(b, a, c):
tmp = 0
if b <= -4.8e+50:
tmp = ((b / a) * -0.5) - b
elif b <= 1.04e+111:
tmp = (math.sqrt(((b * b) + (c * (a * -4.0)))) / (a * 2.0)) - b
else:
tmp = (b * (0.5 / a)) - b
return tmp

function code(b, a, c)
return Float64(Float64(-b) + Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) / Float64(2.0 * a)))
end

function code(b, a, c)
tmp = 0.0
if (b <= -4.8e+50)
tmp = Float64(Float64(Float64(b / a) * -0.5) - b);
elseif (b <= 1.04e+111)
tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -4.0)))) / Float64(a * 2.0)) - b);
else
tmp = Float64(Float64(b * Float64(0.5 / a)) - b);
end
return tmp
end

function tmp = code(b, a, c)
tmp = -b + (sqrt(((b * b) - ((4.0 * a) * c))) / (2.0 * a));
end

function tmp_2 = code(b, a, c)
tmp = 0.0;
if (b <= -4.8e+50)
tmp = ((b / a) * -0.5) - b;
elseif (b <= 1.04e+111)
tmp = (sqrt(((b * b) + (c * (a * -4.0)))) / (a * 2.0)) - b;
else
tmp = (b * (0.5 / a)) - b;
end
tmp_2 = tmp;
end

code[b_, a_, c_] := N[((-b) + N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a),$MachinePrecision] * c), $MachinePrecision]),$MachinePrecision]], $MachinePrecision] / N[(2.0 * a),$MachinePrecision]), $MachinePrecision]),$MachinePrecision]

code[b_, a_, c_] := If[LessEqual[b, -4.8e+50], N[(N[(N[(b / a), $MachinePrecision] * -0.5),$MachinePrecision] - b), $MachinePrecision], If[LessEqual[b, 1.04e+111], N[(N[(N[Sqrt[N[(N[(b * b),$MachinePrecision] + N[(c * N[(a * -4.0), $MachinePrecision]),$MachinePrecision]), $MachinePrecision]],$MachinePrecision] / N[(a * 2.0), $MachinePrecision]),$MachinePrecision] - b), $MachinePrecision], N[(N[(b * N[(0.5 / a),$MachinePrecision]), $MachinePrecision] - b),$MachinePrecision]]]

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

\begin{array}{l}
\mathbf{if}\;b \leq -4.8 \cdot 10^{+50}:\\
\;\;\;\;\frac{b}{a} \cdot -0.5 - b\\

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

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

\end{array}


# Try it out?

Results

 In Out
Enter valid numbers for all inputs

# Derivation?

1. Split input into 3 regimes
2. ## if b < -4.8000000000000004e50

1. Initial program 37.9

$\left(-b\right) + \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}$
2. Simplified37.9

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

$\leadsto \left(-b\right) + \color{blue}{-0.5 \cdot \frac{b}{a}}$
4. Simplified0.9

$\leadsto \left(-b\right) + \color{blue}{\frac{b}{a} \cdot -0.5}$
Proof
[Start]0.9 $\left(-b\right) + -0.5 \cdot \frac{b}{a}$ $\left(-b\right) + \color{blue}{\frac{b}{a} \cdot -0.5}$

## if -4.8000000000000004e50 < b < 1.04e111

1. Initial program 9.3

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

## if 1.04e111 < b

1. Initial program 50.0

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

$\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\mathsf{fma}\left(b, b, \frac{c}{\frac{-0.25}{a}}\right)}, \frac{0.5}{a}, -b\right)}$
Proof
[Start]50.0 $\left(-b\right) + \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}$ $\left(-b\right) + \color{blue}{\left(-\left(-\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\right)\right)}$ $\color{blue}{\left(-\left(-\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\right)\right) + \left(-b\right)}$ $\color{blue}{-1 \cdot \left(-\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\right)} + \left(-b\right)$ $-1 \cdot \color{blue}{\frac{-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}} + \left(-b\right)$ $\color{blue}{\frac{-1 \cdot \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}{2 \cdot a}} + \left(-b\right)$ $\color{blue}{\frac{-1}{2 \cdot a} \cdot \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)} + \left(-b\right)$ $\frac{-1}{2 \cdot a} \cdot \color{blue}{\left(-1 \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)} + \left(-b\right)$ $\color{blue}{\left(\frac{-1}{2 \cdot a} \cdot -1\right) \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} + \left(-b\right)$ $\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \left(\frac{-1}{2 \cdot a} \cdot -1\right)} + \left(-b\right)$ $\color{blue}{\mathsf{fma}\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}, \frac{-1}{2 \cdot a} \cdot -1, -b\right)}$
3. Taylor expanded in b around inf 0.1

$\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{a} - 1\right) \cdot b}$
4. Simplified0.1

$\leadsto \color{blue}{b \cdot \frac{0.5}{a} - b}$
Proof
[Start]0.1 $\left(0.5 \cdot \frac{1}{a} - 1\right) \cdot b$ $\color{blue}{b \cdot \left(0.5 \cdot \frac{1}{a} - 1\right)}$ $b \cdot \left(\color{blue}{\frac{0.5 \cdot 1}{a}} - 1\right)$ $b \cdot \left(\frac{\color{blue}{0.5}}{a} - 1\right)$ $b \cdot \color{blue}{\left(\frac{0.5}{a} + \left(-1\right)\right)}$ $b \cdot \left(\frac{0.5}{a} + \color{blue}{-1}\right)$ $\color{blue}{\frac{0.5}{a} \cdot b + -1 \cdot b}$ $\color{blue}{\frac{0.5 \cdot b}{a}} + -1 \cdot b$ $\color{blue}{0.5 \cdot \frac{b}{a}} + -1 \cdot b$ $0.5 \cdot \frac{b}{a} + \color{blue}{\left(-b\right)}$ $\color{blue}{0.5 \cdot \frac{b}{a} - b}$ $\color{blue}{\frac{0.5 \cdot b}{a}} - b$ $\color{blue}{\frac{0.5}{a} \cdot b} - b$ $\color{blue}{b \cdot \frac{0.5}{a}} - b$
3. Recombined 3 regimes into one program.
4. Final simplification6.0

$\leadsto \begin{array}{l} \mathbf{if}\;b \leq -4.8 \cdot 10^{+50}:\\ \;\;\;\;\frac{b}{a} \cdot -0.5 - b\\ \mathbf{elif}\;b \leq 1.04 \cdot 10^{+111}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}}{a \cdot 2} - b\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{0.5}{a} - b\\ \end{array}$

# Alternatives

Alternative 1
Error10.2
Cost7368
$\begin{array}{l} \mathbf{if}\;b \leq -7.6 \cdot 10^{-89}:\\ \;\;\;\;\frac{b}{a} \cdot -0.5 - b\\ \mathbf{elif}\;b \leq 2.25 \cdot 10^{-98}:\\ \;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot 2} - b\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{0.5}{a} - b\\ \end{array}$
Alternative 2
Error16.1
Cost7048
$\begin{array}{l} \mathbf{if}\;b \leq -6.3 \cdot 10^{-80}:\\ \;\;\;\;\frac{b}{a} \cdot -0.5 - b\\ \mathbf{elif}\;b \leq 3.4 \cdot 10^{-146}:\\ \;\;\;\;\sqrt{\frac{-c}{a}} - b\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{0.5}{a} - b\\ \end{array}$
Alternative 3
Error29.4
Cost848
$\begin{array}{l} t_0 := \frac{b}{a} \cdot 0.5\\ \mathbf{if}\;a \leq -3.6 \cdot 10^{-10}:\\ \;\;\;\;-b\\ \mathbf{elif}\;a \leq -1.55 \cdot 10^{-75}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;a \leq -3.4 \cdot 10^{-249}:\\ \;\;\;\;\frac{b}{a} \cdot -0.5\\ \mathbf{elif}\;a \leq 0.5:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-b\\ \end{array}$
Alternative 4
Error29.0
Cost848
$\begin{array}{l} t_0 := \frac{b}{a} \cdot 0.5\\ \mathbf{if}\;a \leq -1.35 \cdot 10^{-12}:\\ \;\;\;\;b \cdot \left(\frac{-0.5}{a} + -1\right)\\ \mathbf{elif}\;a \leq -1.45 \cdot 10^{-74}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;a \leq -4.2 \cdot 10^{-249}:\\ \;\;\;\;\frac{b}{a} \cdot -0.5\\ \mathbf{elif}\;a \leq 0.48:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-b\\ \end{array}$
Alternative 5
Error29.1
Cost848
$\begin{array}{l} t_0 := \frac{b}{a} \cdot 0.5\\ \mathbf{if}\;a \leq -1.06 \cdot 10^{-13}:\\ \;\;\;\;b \cdot \frac{-0.5}{a} - b\\ \mathbf{elif}\;a \leq -8.3 \cdot 10^{-76}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;a \leq -7.5 \cdot 10^{-250}:\\ \;\;\;\;\frac{b}{a} \cdot -0.5\\ \mathbf{elif}\;a \leq 0.5:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-b\\ \end{array}$
Alternative 6
Error29.3
Cost584
$\begin{array}{l} \mathbf{if}\;a \leq -0.096:\\ \;\;\;\;-b\\ \mathbf{elif}\;a \leq 5.5 \cdot 10^{-21}:\\ \;\;\;\;\frac{b}{a} \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;-b\\ \end{array}$
Alternative 7
Error18.9
Cost580
$\begin{array}{l} \mathbf{if}\;b \leq -7 \cdot 10^{-300}:\\ \;\;\;\;b \cdot \frac{-0.5}{a} - b\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{0.5}{a} - b\\ \end{array}$
Alternative 8
Error18.9
Cost580
$\begin{array}{l} \mathbf{if}\;b \leq -7 \cdot 10^{-300}:\\ \;\;\;\;\frac{b}{a} \cdot -0.5 - b\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{0.5}{a} - b\\ \end{array}$
Alternative 9
Error37.7
Cost128
$-b$

# Reproduce?

herbie shell --seed 1
(FPCore (b a c)
:name "-b + sqrt(b*b - 4*a*c)/(2 * a)"
:precision binary64
:pre (and (and (and (<= -1.78e+308 b) (<= b 1.79e+308)) (and (<= -1.78e+308 a) (<= a 1.79e+308))) (and (<= -1.79e+308 c) (<= c 1.79e+308)))
(+ (- b) (/ (sqrt (- (* b b) (* (* 4.0 a) c))) (* 2.0 a))))