| Alternative 1 | |
|---|---|
| Error | 9.5 |
| Cost | 8520 |
(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) (* 4.0 (* a c))))))
(if (<= b -8.5e+85)
(+ (/ c b) (/ (- b) a))
(if (<= b 5.5e-36)
(- (/ t_0 (* 4.0 a)) (/ (+ b (- b t_0)) (* 4.0 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 t_0 = sqrt(((b * b) - (4.0 * (a * c))));
double tmp;
if (b <= -8.5e+85) {
tmp = (c / b) + (-b / a);
} else if (b <= 5.5e-36) {
tmp = (t_0 / (4.0 * a)) - ((b + (b - t_0)) / (4.0 * 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) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - (4.0d0 * (a * c))))
if (b <= (-8.5d+85)) then
tmp = (c / b) + (-b / a)
else if (b <= 5.5d-36) then
tmp = (t_0 / (4.0d0 * a)) - ((b + (b - t_0)) / (4.0d0 * 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 t_0 = Math.sqrt(((b * b) - (4.0 * (a * c))));
double tmp;
if (b <= -8.5e+85) {
tmp = (c / b) + (-b / a);
} else if (b <= 5.5e-36) {
tmp = (t_0 / (4.0 * a)) - ((b + (b - t_0)) / (4.0 * 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): t_0 = math.sqrt(((b * b) - (4.0 * (a * c)))) tmp = 0 if b <= -8.5e+85: tmp = (c / b) + (-b / a) elif b <= 5.5e-36: tmp = (t_0 / (4.0 * a)) - ((b + (b - t_0)) / (4.0 * a)) 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 = sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) tmp = 0.0 if (b <= -8.5e+85) tmp = Float64(Float64(c / b) + Float64(Float64(-b) / a)); elseif (b <= 5.5e-36) tmp = Float64(Float64(t_0 / Float64(4.0 * a)) - Float64(Float64(b + Float64(b - t_0)) / Float64(4.0 * 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) t_0 = sqrt(((b * b) - (4.0 * (a * c)))); tmp = 0.0; if (b <= -8.5e+85) tmp = (c / b) + (-b / a); elseif (b <= 5.5e-36) tmp = (t_0 / (4.0 * a)) - ((b + (b - t_0)) / (4.0 * 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[(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[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -8.5e+85], N[(N[(c / b), $MachinePrecision] + N[((-b) / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.5e-36], N[(N[(t$95$0 / N[(4.0 * a), $MachinePrecision]), $MachinePrecision] - N[(N[(b + N[(b - t$95$0), $MachinePrecision]), $MachinePrecision] / N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-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 := \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\
\mathbf{if}\;b \leq -8.5 \cdot 10^{+85}:\\
\;\;\;\;\frac{c}{b} + \frac{-b}{a}\\
\mathbf{elif}\;b \leq 5.5 \cdot 10^{-36}:\\
\;\;\;\;\frac{t_0}{4 \cdot a} - \frac{b + \left(b - t_0\right)}{4 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\
\end{array}
Results
if b < -8.4999999999999994e85Initial program 43.9
Simplified43.9
[Start]43.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
rational_best-simplify-3 [=>]43.9 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}}{2 \cdot a}
\] |
rational_best-simplify-9 [<=]43.9 | \[ \frac{\color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - 0\right)} + \left(-b\right)}{2 \cdot a}
\] |
rational_best-simplify-56 [=>]43.9 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \left(0 + b\right)}}{2 \cdot a}
\] |
rational_best-simplify-6 [=>]43.9 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \color{blue}{b}}{2 \cdot a}
\] |
rational_best-simplify-1 [=>]43.9 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{\color{blue}{a \cdot 2}}
\] |
Taylor expanded in b around -inf 4.1
Simplified4.1
[Start]4.1 | \[ \frac{c}{b} + -1 \cdot \frac{b}{a}
\] |
|---|---|
rational_best-simplify-1 [=>]4.1 | \[ \frac{c}{b} + \color{blue}{\frac{b}{a} \cdot -1}
\] |
rational_best-simplify-10 [=>]4.1 | \[ \frac{c}{b} + \color{blue}{\left(-\frac{b}{a}\right)}
\] |
rational_best-simplify-12 [<=]4.1 | \[ \frac{c}{b} + \color{blue}{\frac{\frac{b}{a}}{-1}}
\] |
rational_best-simplify-49 [<=]4.1 | \[ \frac{c}{b} + \color{blue}{\frac{\frac{b}{-1}}{a}}
\] |
rational_best-simplify-13 [<=]4.1 | \[ \frac{c}{b} + \frac{\color{blue}{-b}}{a}
\] |
if -8.4999999999999994e85 < b < 5.49999999999999984e-36Initial program 14.1
Simplified14.1
[Start]14.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
rational_best-simplify-3 [=>]14.1 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}}{2 \cdot a}
\] |
rational_best-simplify-9 [<=]14.1 | \[ \frac{\color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - 0\right)} + \left(-b\right)}{2 \cdot a}
\] |
rational_best-simplify-56 [=>]14.1 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \left(0 + b\right)}}{2 \cdot a}
\] |
rational_best-simplify-6 [=>]14.1 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \color{blue}{b}}{2 \cdot a}
\] |
rational_best-simplify-1 [=>]14.1 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{\color{blue}{a \cdot 2}}
\] |
Applied egg-rr14.1
if 5.49999999999999984e-36 < b Initial program 55.1
Simplified55.1
[Start]55.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
rational_best-simplify-3 [=>]55.1 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}}{2 \cdot a}
\] |
rational_best-simplify-9 [<=]55.1 | \[ \frac{\color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - 0\right)} + \left(-b\right)}{2 \cdot a}
\] |
rational_best-simplify-56 [=>]55.1 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \left(0 + b\right)}}{2 \cdot a}
\] |
rational_best-simplify-6 [=>]55.1 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \color{blue}{b}}{2 \cdot a}
\] |
rational_best-simplify-1 [=>]55.1 | \[ \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{\color{blue}{a \cdot 2}}
\] |
Taylor expanded in b around inf 6.3
Simplified6.3
[Start]6.3 | \[ -1 \cdot \frac{c}{b}
\] |
|---|---|
rational_best-simplify-1 [=>]6.3 | \[ \color{blue}{\frac{c}{b} \cdot -1}
\] |
rational_best-simplify-10 [=>]6.3 | \[ \color{blue}{-\frac{c}{b}}
\] |
Final simplification9.6
| Alternative 1 | |
|---|---|
| Error | 9.5 |
| Cost | 8520 |
| Alternative 2 | |
|---|---|
| Error | 9.5 |
| Cost | 7752 |
| Alternative 3 | |
|---|---|
| Error | 9.6 |
| Cost | 7624 |
| Alternative 4 | |
|---|---|
| Error | 9.4 |
| Cost | 7624 |
| Alternative 5 | |
|---|---|
| Error | 12.9 |
| Cost | 7368 |
| Alternative 6 | |
|---|---|
| Error | 13.1 |
| Cost | 7240 |
| Alternative 7 | |
|---|---|
| Error | 19.5 |
| Cost | 7112 |
| Alternative 8 | |
|---|---|
| Error | 22.4 |
| Cost | 644 |
| Alternative 9 | |
|---|---|
| Error | 22.4 |
| Cost | 388 |
| Alternative 10 | |
|---|---|
| Error | 40.0 |
| Cost | 256 |
| Alternative 11 | |
|---|---|
| Error | 56.4 |
| Cost | 64 |
herbie shell --seed 2023099
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))