# ?

Average Error: 5.2 → 1.3
Time: 25.8s
Precision: binary64
Cost: 48072

# ?

$\left(\left(\left(-1000000000 \leq b \land b \leq 1000000000\right) \land \left(-1000000000 \leq a \land a \leq 1000000000\right)\right) \land \left(-1000000000 \leq c \land c \leq 1000000000\right)\right) \land \left(-100 \leq t \land t \leq 100\right)$
$\frac{\left(-b\right) + \sqrt{{b}^{2} - 4 \cdot \left(a \cdot \left(c - t\right)\right)}}{2} \cdot a$
$\begin{array}{l} t_1 := a \cdot \frac{\sqrt{{b}^{2} + 4 \cdot \left(a \cdot \left(t - c\right)\right)} - b}{2}\\ t_2 := a \cdot \left(4 \cdot \left(t - c\right)\right)\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{-322}:\\ \;\;\;\;\left(\sqrt{\mathsf{fma}\left(b, b, t_2\right)} - b\right) \cdot \frac{a}{2}\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;\frac{t - c}{\frac{b}{a \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;a \cdot \frac{\sqrt{b \cdot b + \mathsf{expm1}\left(\mathsf{log1p}\left(t_2\right)\right)} - b}{2}\\ \end{array}$
(FPCore (b a c t)
:precision binary64
(* (/ (+ (- b) (sqrt (- (pow b 2.0) (* 4.0 (* a (- c t)))))) 2.0) a))
(FPCore (b a c t)
:precision binary64
(let* ((t_1 (* a (/ (- (sqrt (+ (pow b 2.0) (* 4.0 (* a (- t c))))) b) 2.0)))
(t_2 (* a (* 4.0 (- t c)))))
(if (<= t_1 -2e-322)
(* (- (sqrt (fma b b t_2)) b) (/ a 2.0))
(if (<= t_1 0.0)
(/ (- t c) (/ b (* a a)))
(* a (/ (- (sqrt (+ (* b b) (expm1 (log1p t_2)))) b) 2.0))))))
double code(double b, double a, double c, double t) {
return ((-b + sqrt((pow(b, 2.0) - (4.0 * (a * (c - t)))))) / 2.0) * a;
}

double code(double b, double a, double c, double t) {
double t_1 = a * ((sqrt((pow(b, 2.0) + (4.0 * (a * (t - c))))) - b) / 2.0);
double t_2 = a * (4.0 * (t - c));
double tmp;
if (t_1 <= -2e-322) {
tmp = (sqrt(fma(b, b, t_2)) - b) * (a / 2.0);
} else if (t_1 <= 0.0) {
tmp = (t - c) / (b / (a * a));
} else {
tmp = a * ((sqrt(((b * b) + expm1(log1p(t_2)))) - b) / 2.0);
}
return tmp;
}

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

function code(b, a, c, t)
t_1 = Float64(a * Float64(Float64(sqrt(Float64((b ^ 2.0) + Float64(4.0 * Float64(a * Float64(t - c))))) - b) / 2.0))
t_2 = Float64(a * Float64(4.0 * Float64(t - c)))
tmp = 0.0
if (t_1 <= -2e-322)
tmp = Float64(Float64(sqrt(fma(b, b, t_2)) - b) * Float64(a / 2.0));
elseif (t_1 <= 0.0)
tmp = Float64(Float64(t - c) / Float64(b / Float64(a * a)));
else
tmp = Float64(a * Float64(Float64(sqrt(Float64(Float64(b * b) + expm1(log1p(t_2)))) - b) / 2.0));
end
return tmp
end

code[b_, a_, c_, t_] := N[(N[(N[((-b) + N[Sqrt[N[(N[Power[b, 2.0], $MachinePrecision] - N[(4.0 * N[(a * N[(c - t),$MachinePrecision]), $MachinePrecision]),$MachinePrecision]), $MachinePrecision]],$MachinePrecision]), $MachinePrecision] / 2.0),$MachinePrecision] * a), $MachinePrecision]  code[b_, a_, c_, t_] := Block[{t$95$1 = N[(a * N[(N[(N[Sqrt[N[(N[Power[b, 2.0],$MachinePrecision] + N[(4.0 * N[(a * N[(t - c), $MachinePrecision]),$MachinePrecision]), $MachinePrecision]),$MachinePrecision]], $MachinePrecision] - b),$MachinePrecision] / 2.0), $MachinePrecision]),$MachinePrecision]}, Block[{t$95$2 = N[(a * N[(4.0 * N[(t - c), $MachinePrecision]),$MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e-322], N[(N[(N[Sqrt[N[(b * b + t$95$2),$MachinePrecision]], $MachinePrecision] - b),$MachinePrecision] * N[(a / 2.0), $MachinePrecision]),$MachinePrecision], If[LessEqual[t$95$1, 0.0], N[(N[(t - c), $MachinePrecision] / N[(b / N[(a * a),$MachinePrecision]), $MachinePrecision]),$MachinePrecision], N[(a * N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(Exp[N[Log[1 + t$95$2],$MachinePrecision]] - 1), $MachinePrecision]),$MachinePrecision]], $MachinePrecision] - b),$MachinePrecision] / 2.0), $MachinePrecision]),$MachinePrecision]]]]]

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

\begin{array}{l}
t_1 := a \cdot \frac{\sqrt{{b}^{2} + 4 \cdot \left(a \cdot \left(t - c\right)\right)} - b}{2}\\
t_2 := a \cdot \left(4 \cdot \left(t - c\right)\right)\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{-322}:\\
\;\;\;\;\left(\sqrt{\mathsf{fma}\left(b, b, t_2\right)} - b\right) \cdot \frac{a}{2}\\

\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;\frac{t - c}{\frac{b}{a \cdot a}}\\

\mathbf{else}:\\
\;\;\;\;a \cdot \frac{\sqrt{b \cdot b + \mathsf{expm1}\left(\mathsf{log1p}\left(t_2\right)\right)} - b}{2}\\

\end{array}


# Derivation?

1. Split input into 3 regimes
2. ## if (*.f64 (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (pow.f64 b 2) (*.f64 4 (*.f64 a (-.f64 c t)))))) 2) a) < -1.97626e-322

1. Initial program 1.2

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

$\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(\left(c - t\right) \cdot -4\right)\right)} - b\right) \cdot \frac{a}{2}}$
Proof
[Start]1.2 $\frac{\left(-b\right) + \sqrt{{b}^{2} - 4 \cdot \left(a \cdot \left(c - t\right)\right)}}{2} \cdot a$ $\color{blue}{\frac{\left(\left(-b\right) + \sqrt{{b}^{2} - 4 \cdot \left(a \cdot \left(c - t\right)\right)}\right) \cdot a}{2}}$ $\color{blue}{\left(\left(-b\right) + \sqrt{{b}^{2} - 4 \cdot \left(a \cdot \left(c - t\right)\right)}\right) \cdot \frac{a}{2}}$ $\color{blue}{\left(\sqrt{{b}^{2} - 4 \cdot \left(a \cdot \left(c - t\right)\right)} + \left(-b\right)\right)} \cdot \frac{a}{2}$ $\color{blue}{\left(\sqrt{{b}^{2} - 4 \cdot \left(a \cdot \left(c - t\right)\right)} - b\right)} \cdot \frac{a}{2}$ $\left(\sqrt{\color{blue}{b \cdot b} - 4 \cdot \left(a \cdot \left(c - t\right)\right)} - b\right) \cdot \frac{a}{2}$ $\left(\sqrt{\color{blue}{\mathsf{fma}\left(b, b, -4 \cdot \left(a \cdot \left(c - t\right)\right)\right)}} - b\right) \cdot \frac{a}{2}$ $\left(\sqrt{\mathsf{fma}\left(b, b, \color{blue}{\left(-4\right) \cdot \left(a \cdot \left(c - t\right)\right)}\right)} - b\right) \cdot \frac{a}{2}$ $\left(\sqrt{\mathsf{fma}\left(b, b, \color{blue}{\left(a \cdot \left(c - t\right)\right) \cdot \left(-4\right)}\right)} - b\right) \cdot \frac{a}{2}$ $\left(\sqrt{\mathsf{fma}\left(b, b, \color{blue}{a \cdot \left(\left(c - t\right) \cdot \left(-4\right)\right)}\right)} - b\right) \cdot \frac{a}{2}$ $\left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(\left(c - t\right) \cdot \color{blue}{-4}\right)\right)} - b\right) \cdot \frac{a}{2}$

## if -1.97626e-322 < (*.f64 (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (pow.f64 b 2) (*.f64 4 (*.f64 a (-.f64 c t)))))) 2) a) < 0.0

1. Initial program 9.3

$\frac{\left(-b\right) + \sqrt{{b}^{2} - 4 \cdot \left(a \cdot \left(c - t\right)\right)}}{2} \cdot a$
2. Simplified9.3

$\leadsto \color{blue}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b + -4 \cdot \left(a \cdot \left(c - t\right)\right)}}{2}}$
Proof
[Start]9.3 $\frac{\left(-b\right) + \sqrt{{b}^{2} - 4 \cdot \left(a \cdot \left(c - t\right)\right)}}{2} \cdot a$ $\color{blue}{a \cdot \frac{\left(-b\right) + \sqrt{{b}^{2} - 4 \cdot \left(a \cdot \left(c - t\right)\right)}}{2}}$ $a \cdot \frac{\left(-b\right) + \sqrt{\color{blue}{{b}^{2} + \left(-4\right) \cdot \left(a \cdot \left(c - t\right)\right)}}}{2}$ $a \cdot \frac{\left(-b\right) + \sqrt{\color{blue}{b \cdot b} + \left(-4\right) \cdot \left(a \cdot \left(c - t\right)\right)}}{2}$ $a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b + \color{blue}{-4} \cdot \left(a \cdot \left(c - t\right)\right)}}{2}$
3. Taylor expanded in a around 0 3.1

$\leadsto \color{blue}{-1 \cdot \frac{\left(c - t\right) \cdot {a}^{2}}{b}}$
4. Simplified1.3

$\leadsto \color{blue}{\frac{-\left(c - t\right)}{\frac{b}{a \cdot a}}}$
Proof
[Start]3.1 $-1 \cdot \frac{\left(c - t\right) \cdot {a}^{2}}{b}$ $\color{blue}{-\frac{\left(c - t\right) \cdot {a}^{2}}{b}}$ $-\color{blue}{\frac{c - t}{\frac{b}{{a}^{2}}}}$ $\color{blue}{\frac{-\left(c - t\right)}{\frac{b}{{a}^{2}}}}$ $\frac{-\left(c - t\right)}{\frac{b}{\color{blue}{a \cdot a}}}$

## if 0.0 < (*.f64 (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (pow.f64 b 2) (*.f64 4 (*.f64 a (-.f64 c t)))))) 2) a)

1. Initial program 1.3

$\frac{\left(-b\right) + \sqrt{{b}^{2} - 4 \cdot \left(a \cdot \left(c - t\right)\right)}}{2} \cdot a$
2. Simplified1.3

$\leadsto \color{blue}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b + -4 \cdot \left(a \cdot \left(c - t\right)\right)}}{2}}$
Proof
[Start]1.3 $\frac{\left(-b\right) + \sqrt{{b}^{2} - 4 \cdot \left(a \cdot \left(c - t\right)\right)}}{2} \cdot a$ $\color{blue}{a \cdot \frac{\left(-b\right) + \sqrt{{b}^{2} - 4 \cdot \left(a \cdot \left(c - t\right)\right)}}{2}}$ $a \cdot \frac{\left(-b\right) + \sqrt{\color{blue}{{b}^{2} + \left(-4\right) \cdot \left(a \cdot \left(c - t\right)\right)}}}{2}$ $a \cdot \frac{\left(-b\right) + \sqrt{\color{blue}{b \cdot b} + \left(-4\right) \cdot \left(a \cdot \left(c - t\right)\right)}}{2}$ $a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b + \color{blue}{-4} \cdot \left(a \cdot \left(c - t\right)\right)}}{2}$
3. Applied egg-rr1.3

$\leadsto a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(-4 \cdot \left(c - t\right)\right) \cdot a\right)\right)}}}{2}$
3. Recombined 3 regimes into one program.
4. Final simplification1.3

$\leadsto \begin{array}{l} \mathbf{if}\;a \cdot \frac{\sqrt{{b}^{2} + 4 \cdot \left(a \cdot \left(t - c\right)\right)} - b}{2} \leq -2 \cdot 10^{-322}:\\ \;\;\;\;\left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(4 \cdot \left(t - c\right)\right)\right)} - b\right) \cdot \frac{a}{2}\\ \mathbf{elif}\;a \cdot \frac{\sqrt{{b}^{2} + 4 \cdot \left(a \cdot \left(t - c\right)\right)} - b}{2} \leq 0:\\ \;\;\;\;\frac{t - c}{\frac{b}{a \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;a \cdot \frac{\sqrt{b \cdot b + \mathsf{expm1}\left(\mathsf{log1p}\left(a \cdot \left(4 \cdot \left(t - c\right)\right)\right)\right)} - b}{2}\\ \end{array}$

# Alternatives

Alternative 1
Error1.3
Cost35272
$\begin{array}{l} t_1 := 4 \cdot \left(a \cdot \left(t - c\right)\right)\\ t_2 := a \cdot \frac{\sqrt{{b}^{2} + t_1} - b}{2}\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{-322}:\\ \;\;\;\;\left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(4 \cdot \left(t - c\right)\right)\right)} - b\right) \cdot \frac{a}{2}\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;\frac{t - c}{\frac{b}{a \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;a \cdot \frac{\sqrt{b \cdot b + t_1} - b}{2}\\ \end{array}$
Alternative 2
Error2.3
Cost7620
$\begin{array}{l} \mathbf{if}\;b \leq 3.5 \cdot 10^{-113}:\\ \;\;\;\;a \cdot \frac{\sqrt{b \cdot b + 4 \cdot \left(a \cdot \left(t - c\right)\right)} - b}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{2} \cdot \left(2 \cdot \frac{t - c}{\frac{b}{a}}\right)\\ \end{array}$
Alternative 3
Error12.5
Cost7500
$\begin{array}{l} \mathbf{if}\;b \leq -2.46 \cdot 10^{-113}:\\ \;\;\;\;\left(-b\right) \cdot a\\ \mathbf{elif}\;b \leq -6 \cdot 10^{-222}:\\ \;\;\;\;\frac{\sqrt{t \cdot \left(4 \cdot a\right)} - b}{\frac{2}{a}}\\ \mathbf{elif}\;b \leq 3.9 \cdot 10^{-159}:\\ \;\;\;\;\left(\sqrt{c \cdot \left(a \cdot -4\right)} - b\right) \cdot \left(a \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{2} \cdot \left(2 \cdot \frac{t - c}{\frac{b}{a}}\right)\\ \end{array}$
Alternative 4
Error5.4
Cost7496
$\begin{array}{l} \mathbf{if}\;b \leq -5.5 \cdot 10^{-110}:\\ \;\;\;\;\left(-b\right) \cdot a\\ \mathbf{elif}\;b \leq 4.5 \cdot 10^{-114}:\\ \;\;\;\;\frac{\sqrt{\left(c - t\right) \cdot \left(a \cdot -4\right)} - b}{\frac{2}{a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{2} \cdot \left(2 \cdot \frac{t - c}{\frac{b}{a}}\right)\\ \end{array}$
Alternative 5
Error4.6
Cost7496
$\begin{array}{l} \mathbf{if}\;b \leq -9.5 \cdot 10^{-112}:\\ \;\;\;\;\frac{a}{2} \cdot \left(\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b\right)\\ \mathbf{elif}\;b \leq 5.8 \cdot 10^{-115}:\\ \;\;\;\;\frac{\sqrt{\left(c - t\right) \cdot \left(a \cdot -4\right)} - b}{\frac{2}{a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{2} \cdot \left(2 \cdot \frac{t - c}{\frac{b}{a}}\right)\\ \end{array}$
Alternative 6
Error12.1
Cost7368
$\begin{array}{l} \mathbf{if}\;b \leq -2.2 \cdot 10^{-146}:\\ \;\;\;\;\left(-b\right) \cdot a\\ \mathbf{elif}\;b \leq 7.5 \cdot 10^{-159}:\\ \;\;\;\;\left(\sqrt{c \cdot \left(a \cdot -4\right)} - b\right) \cdot \left(a \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{2} \cdot \left(2 \cdot \frac{t - c}{\frac{b}{a}}\right)\\ \end{array}$
Alternative 7
Error17.9
Cost964
$\begin{array}{l} \mathbf{if}\;b \leq 4.5 \cdot 10^{-161}:\\ \;\;\;\;\left(-b\right) \cdot a\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{2} \cdot \left(2 \cdot \frac{t - c}{\frac{b}{a}}\right)\\ \end{array}$
Alternative 8
Error17.9
Cost772
$\begin{array}{l} \mathbf{if}\;b \leq 1.9 \cdot 10^{-160}:\\ \;\;\;\;\left(-b\right) \cdot a\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(a \cdot \frac{c - t}{-b}\right)\\ \end{array}$
Alternative 9
Error17.9
Cost708
$\begin{array}{l} \mathbf{if}\;b \leq 4.5 \cdot 10^{-161}:\\ \;\;\;\;\left(-b\right) \cdot a\\ \mathbf{else}:\\ \;\;\;\;\frac{t - c}{\frac{\frac{b}{a}}{a}}\\ \end{array}$
Alternative 10
Error20.5
Cost580
$\begin{array}{l} \mathbf{if}\;b \leq 5.8 \cdot 10^{-201}:\\ \;\;\;\;\left(-b\right) \cdot a\\ \mathbf{else}:\\ \;\;\;\;\frac{a \cdot a}{\frac{b}{t}}\\ \end{array}$
Alternative 11
Error29.6
Cost256
$\left(-b\right) \cdot a$

# Reproduce?

herbie shell --seed 1
(FPCore (b a c t)
:name "(-b+sqrt(b^2-4a*(c-t)))/2a"
:precision binary64
:pre (and (and (and (and (<= -1000000000.0 b) (<= b 1000000000.0)) (and (<= -1000000000.0 a) (<= a 1000000000.0))) (and (<= -1000000000.0 c) (<= c 1000000000.0))) (and (<= -100.0 t) (<= t 100.0)))
(* (/ (+ (- b) (sqrt (- (pow b 2.0) (* 4.0 (* a (- c t)))))) 2.0) a))