| Alternative 1 | |
|---|---|
| Error | 10.9 |
| Cost | 7889 |
(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 -2e+149)
(/ (- b) a)
(if (<= b 6.4e-176)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(if (or (<= b 4.5e-143) (not (<= b 1.65e-79)))
(/ (- c) b)
(* (- (sqrt (+ (* b b) (* a (* c -4.0)))) b) (/ 0.5 a))))))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 <= -2e+149) {
tmp = -b / a;
} else if (b <= 6.4e-176) {
tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else if ((b <= 4.5e-143) || !(b <= 1.65e-79)) {
tmp = -c / b;
} else {
tmp = (sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a);
}
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 <= (-2d+149)) then
tmp = -b / a
else if (b <= 6.4d-176) then
tmp = (sqrt(((b * b) - ((a * 4.0d0) * c))) - b) / (a * 2.0d0)
else if ((b <= 4.5d-143) .or. (.not. (b <= 1.65d-79))) then
tmp = -c / b
else
tmp = (sqrt(((b * b) + (a * (c * (-4.0d0))))) - b) * (0.5d0 / a)
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 <= -2e+149) {
tmp = -b / a;
} else if (b <= 6.4e-176) {
tmp = (Math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else if ((b <= 4.5e-143) || !(b <= 1.65e-79)) {
tmp = -c / b;
} else {
tmp = (Math.sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a);
}
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 <= -2e+149: tmp = -b / a elif b <= 6.4e-176: tmp = (math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0) elif (b <= 4.5e-143) or not (b <= 1.65e-79): tmp = -c / b else: tmp = (math.sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a) 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) tmp = 0.0 if (b <= -2e+149) tmp = Float64(Float64(-b) / a); elseif (b <= 6.4e-176) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - b) / Float64(a * 2.0)); elseif ((b <= 4.5e-143) || !(b <= 1.65e-79)) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(a * Float64(c * -4.0)))) - b) * Float64(0.5 / a)); 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 <= -2e+149) tmp = -b / a; elseif (b <= 6.4e-176) tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0); elseif ((b <= 4.5e-143) || ~((b <= 1.65e-79))) tmp = -c / b; else tmp = (sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a); 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_] := If[LessEqual[b, -2e+149], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 6.4e-176], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[b, 4.5e-143], N[Not[LessEqual[b, 1.65e-79]], $MachinePrecision]], N[((-c) / b), $MachinePrecision], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision]]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{+149}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 6.4 \cdot 10^{-176}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 4.5 \cdot 10^{-143} \lor \neg \left(b \leq 1.65 \cdot 10^{-79}\right):\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\left(\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b\right) \cdot \frac{0.5}{a}\\
\end{array}
Results
if b < -2.0000000000000001e149Initial program 62.1
Simplified62.1
[Start]62.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]62.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{2 \cdot a}{1}}}
\] |
metadata-eval [<=]62.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{2 \cdot a}{\color{blue}{--1}}}
\] |
*-commutative [=>]62.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{\color{blue}{a \cdot 2}}{--1}}
\] |
associate-/l* [=>]62.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{a}{\frac{--1}{2}}}}
\] |
associate-/l* [<=]62.1 | \[ \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/ [<=]62.1 | \[ \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 [<=]62.1 | \[ \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 [<=]62.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{--1}} \cdot \frac{\frac{--1}{2}}{a}
\] |
Taylor expanded in b around -inf 3.0
Simplified3.0
[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 -2.0000000000000001e149 < b < 6.39999999999999969e-176Initial program 11.0
if 6.39999999999999969e-176 < b < 4.5e-143 or 1.6499999999999999e-79 < b Initial program 51.0
Simplified51.0
[Start]51.0 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
*-commutative [=>]51.0 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}}
\] |
Taylor expanded in b around inf 11.4
Simplified11.4
[Start]11.4 | \[ -1 \cdot \frac{c}{b}
\] |
|---|---|
mul-1-neg [=>]11.4 | \[ \color{blue}{-\frac{c}{b}}
\] |
distribute-neg-frac [=>]11.4 | \[ \color{blue}{\frac{-c}{b}}
\] |
if 4.5e-143 < b < 1.6499999999999999e-79Initial program 25.1
Simplified25.1
[Start]25.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]25.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{2 \cdot a}{1}}}
\] |
metadata-eval [<=]25.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{2 \cdot a}{\color{blue}{--1}}}
\] |
*-commutative [=>]25.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\frac{\color{blue}{a \cdot 2}}{--1}}
\] |
associate-/l* [=>]25.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{\frac{a}{\frac{--1}{2}}}}
\] |
associate-/l* [<=]25.1 | \[ \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/ [<=]25.1 | \[ \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 [<=]25.1 | \[ \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 [<=]25.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{--1}} \cdot \frac{\frac{--1}{2}}{a}
\] |
Applied egg-rr25.1
Final simplification10.9
| Alternative 1 | |
|---|---|
| Error | 10.9 |
| Cost | 7889 |
| Alternative 2 | |
|---|---|
| Error | 14.6 |
| Cost | 7633 |
| Alternative 3 | |
|---|---|
| Error | 14.5 |
| Cost | 7633 |
| Alternative 4 | |
|---|---|
| Error | 40.0 |
| Cost | 388 |
| Alternative 5 | |
|---|---|
| Error | 22.8 |
| Cost | 388 |
| Alternative 6 | |
|---|---|
| Error | 56.9 |
| Cost | 192 |
herbie shell --seed 2023088
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))