| Alternative 1 | |
|---|---|
| Error | 10.1 |
| Cost | 7624 |
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (* b -2.0) (* 3.0 a))))
(if (<= b -6e+152)
(* t_0 (* t_0 (/ 1.0 t_0)))
(if (<= b 9.2e-51)
(/ (- (sqrt (- (* b b) (* (* 3.0 a) c))) b) (* 3.0 a))
(* -0.5 (/ c b))))))double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
double code(double a, double b, double c) {
double t_0 = (b * -2.0) / (3.0 * a);
double tmp;
if (b <= -6e+152) {
tmp = t_0 * (t_0 * (1.0 / t_0));
} else if (b <= 9.2e-51) {
tmp = (sqrt(((b * b) - ((3.0 * a) * c))) - b) / (3.0 * a);
} else {
tmp = -0.5 * (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) - ((3.0d0 * a) * c)))) / (3.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 = (b * (-2.0d0)) / (3.0d0 * a)
if (b <= (-6d+152)) then
tmp = t_0 * (t_0 * (1.0d0 / t_0))
else if (b <= 9.2d-51) then
tmp = (sqrt(((b * b) - ((3.0d0 * a) * c))) - b) / (3.0d0 * a)
else
tmp = (-0.5d0) * (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
public static double code(double a, double b, double c) {
double t_0 = (b * -2.0) / (3.0 * a);
double tmp;
if (b <= -6e+152) {
tmp = t_0 * (t_0 * (1.0 / t_0));
} else if (b <= 9.2e-51) {
tmp = (Math.sqrt(((b * b) - ((3.0 * a) * c))) - b) / (3.0 * a);
} else {
tmp = -0.5 * (c / b);
}
return tmp;
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
def code(a, b, c): t_0 = (b * -2.0) / (3.0 * a) tmp = 0 if b <= -6e+152: tmp = t_0 * (t_0 * (1.0 / t_0)) elif b <= 9.2e-51: tmp = (math.sqrt(((b * b) - ((3.0 * a) * c))) - b) / (3.0 * a) else: tmp = -0.5 * (c / b) return tmp
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a)) end
function code(a, b, c) t_0 = Float64(Float64(b * -2.0) / Float64(3.0 * a)) tmp = 0.0 if (b <= -6e+152) tmp = Float64(t_0 * Float64(t_0 * Float64(1.0 / t_0))); elseif (b <= 9.2e-51) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c))) - b) / Float64(3.0 * a)); else tmp = Float64(-0.5 * Float64(c / b)); end return tmp end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a); end
function tmp_2 = code(a, b, c) t_0 = (b * -2.0) / (3.0 * a); tmp = 0.0; if (b <= -6e+152) tmp = t_0 * (t_0 * (1.0 / t_0)); elseif (b <= 9.2e-51) tmp = (sqrt(((b * b) - ((3.0 * a) * c))) - b) / (3.0 * a); else tmp = -0.5 * (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(b * -2.0), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -6e+152], N[(t$95$0 * N[(t$95$0 * N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 9.2e-51], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision]]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\begin{array}{l}
t_0 := \frac{b \cdot -2}{3 \cdot a}\\
\mathbf{if}\;b \leq -6 \cdot 10^{+152}:\\
\;\;\;\;t_0 \cdot \left(t_0 \cdot \frac{1}{t_0}\right)\\
\mathbf{elif}\;b \leq 9.2 \cdot 10^{-51}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b}\\
\end{array}
Results
if b < -5.99999999999999981e152Initial program 63.2
Simplified63.2
[Start]63.2 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-35 [=>]63.2 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + \left(-b\right)}}{3 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-97 [=>]63.2 | \[ \frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + \color{blue}{\left(0 - b\right)}}{3 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-108 [=>]63.2 | \[ \frac{\color{blue}{\left(0 + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) - b}}{3 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-35 [=>]63.2 | \[ \frac{\color{blue}{\left(\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + 0\right)} - b}{3 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-85 [=>]63.2 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}} - b}{3 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]63.2 | \[ \frac{\sqrt{b \cdot b - \color{blue}{c \cdot \left(3 \cdot a\right)}} - b}{3 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-7 [=>]63.2 | \[ \frac{\sqrt{b \cdot b - \color{blue}{3 \cdot \left(c \cdot a\right)}} - b}{3 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]63.2 | \[ \frac{\sqrt{b \cdot b - 3 \cdot \color{blue}{\left(a \cdot c\right)}} - b}{3 \cdot a}
\] |
Taylor expanded in b around -inf 3.4
Simplified3.4
[Start]3.4 | \[ \frac{-2 \cdot b}{3 \cdot a}
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-74 [=>]3.4 | \[ \frac{\color{blue}{b \cdot -2}}{3 \cdot a}
\] |
Applied egg-rr3.5
if -5.99999999999999981e152 < b < 9.20000000000000007e-51Initial program 13.1
Simplified13.1
[Start]13.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-35 [=>]13.1 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + \left(-b\right)}}{3 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-97 [=>]13.1 | \[ \frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + \color{blue}{\left(0 - b\right)}}{3 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-108 [=>]13.1 | \[ \frac{\color{blue}{\left(0 + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) - b}}{3 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-35 [=>]13.1 | \[ \frac{\color{blue}{\left(\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + 0\right)} - b}{3 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-85 [=>]13.1 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}} - b}{3 \cdot a}
\] |
if 9.20000000000000007e-51 < b Initial program 54.4
Simplified54.4
[Start]54.4 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-35 [=>]54.4 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + \left(-b\right)}}{3 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-97 [=>]54.4 | \[ \frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + \color{blue}{\left(0 - b\right)}}{3 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-108 [=>]54.4 | \[ \frac{\color{blue}{\left(0 + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) - b}}{3 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-35 [=>]54.4 | \[ \frac{\color{blue}{\left(\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} + 0\right)} - b}{3 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-85 [=>]54.4 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}} - b}{3 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]54.4 | \[ \frac{\sqrt{b \cdot b - \color{blue}{c \cdot \left(3 \cdot a\right)}} - b}{3 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-7 [=>]54.4 | \[ \frac{\sqrt{b \cdot b - \color{blue}{3 \cdot \left(c \cdot a\right)}} - b}{3 \cdot a}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]54.4 | \[ \frac{\sqrt{b \cdot b - 3 \cdot \color{blue}{\left(a \cdot c\right)}} - b}{3 \cdot a}
\] |
Taylor expanded in b around inf 8.0
Final simplification10.1
| Alternative 1 | |
|---|---|
| Error | 10.1 |
| Cost | 7624 |
| Alternative 2 | |
|---|---|
| Error | 13.8 |
| Cost | 7368 |
| Alternative 3 | |
|---|---|
| Error | 13.7 |
| Cost | 7368 |
| Alternative 4 | |
|---|---|
| Error | 13.7 |
| Cost | 7368 |
| Alternative 5 | |
|---|---|
| Error | 23.0 |
| Cost | 580 |
| Alternative 6 | |
|---|---|
| Error | 36.9 |
| Cost | 452 |
| Alternative 7 | |
|---|---|
| Error | 23.0 |
| Cost | 452 |
| Alternative 8 | |
|---|---|
| Error | 40.0 |
| Cost | 320 |
herbie shell --seed 2023090
(FPCore (a b c)
:name "Cubic critical"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))