| Alternative 1 | |
|---|---|
| Error | 14.8 |
| Cost | 7368 |
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c)
:precision binary64
(if (<= b -5.5e+126)
(/ (* b -2.0) (* 3.0 a))
(if (<= b 3e-134)
(/ (- (sqrt (+ (* b b) (* c (* a -3.0)))) 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 tmp;
if (b <= -5.5e+126) {
tmp = (b * -2.0) / (3.0 * a);
} else if (b <= 3e-134) {
tmp = (sqrt(((b * b) + (c * (a * -3.0)))) - 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) :: tmp
if (b <= (-5.5d+126)) then
tmp = (b * (-2.0d0)) / (3.0d0 * a)
else if (b <= 3d-134) then
tmp = (sqrt(((b * b) + (c * (a * (-3.0d0))))) - 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 tmp;
if (b <= -5.5e+126) {
tmp = (b * -2.0) / (3.0 * a);
} else if (b <= 3e-134) {
tmp = (Math.sqrt(((b * b) + (c * (a * -3.0)))) - 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): tmp = 0 if b <= -5.5e+126: tmp = (b * -2.0) / (3.0 * a) elif b <= 3e-134: tmp = (math.sqrt(((b * b) + (c * (a * -3.0)))) - 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) tmp = 0.0 if (b <= -5.5e+126) tmp = Float64(Float64(b * -2.0) / Float64(3.0 * a)); elseif (b <= 3e-134) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -3.0)))) - 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) tmp = 0.0; if (b <= -5.5e+126) tmp = (b * -2.0) / (3.0 * a); elseif (b <= 3e-134) tmp = (sqrt(((b * b) + (c * (a * -3.0)))) - 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_] := If[LessEqual[b, -5.5e+126], N[(N[(b * -2.0), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3e-134], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(c * N[(a * -3.0), $MachinePrecision]), $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}
\mathbf{if}\;b \leq -5.5 \cdot 10^{+126}:\\
\;\;\;\;\frac{b \cdot -2}{3 \cdot a}\\
\mathbf{elif}\;b \leq 3 \cdot 10^{-134}:\\
\;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{3 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b}\\
\end{array}
Results
if b < -5.5000000000000004e126Initial program 54.9
Simplified54.9
[Start]54.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
rational_best-simplify-62 [=>]54.9 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \left(-\left(-b\right)\right)}}{3 \cdot a}
\] |
rational_best-simplify-51 [=>]54.9 | \[ \frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \color{blue}{b}}{3 \cdot a}
\] |
rational_best-simplify-61 [=>]54.9 | \[ \frac{\sqrt{\color{blue}{b \cdot b + \left(-\left(3 \cdot a\right) \cdot c\right)}} - b}{3 \cdot a}
\] |
rational_best-simplify-52 [=>]54.9 | \[ \frac{\sqrt{b \cdot b + \color{blue}{c \cdot \left(-3 \cdot a\right)}} - b}{3 \cdot a}
\] |
rational_best-simplify-52 [=>]54.9 | \[ \frac{\sqrt{b \cdot b + c \cdot \color{blue}{\left(a \cdot \left(-3\right)\right)}} - b}{3 \cdot a}
\] |
metadata-eval [=>]54.9 | \[ \frac{\sqrt{b \cdot b + c \cdot \left(a \cdot \color{blue}{-3}\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-simplify-3 [=>]3.4 | \[ \frac{\color{blue}{b \cdot -2}}{3 \cdot a}
\] |
if -5.5000000000000004e126 < b < 3e-134Initial program 10.7
Simplified10.7
[Start]10.7 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
rational_best-simplify-62 [=>]10.7 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \left(-\left(-b\right)\right)}}{3 \cdot a}
\] |
rational_best-simplify-51 [=>]10.7 | \[ \frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \color{blue}{b}}{3 \cdot a}
\] |
rational_best-simplify-61 [=>]10.7 | \[ \frac{\sqrt{\color{blue}{b \cdot b + \left(-\left(3 \cdot a\right) \cdot c\right)}} - b}{3 \cdot a}
\] |
rational_best-simplify-52 [=>]10.7 | \[ \frac{\sqrt{b \cdot b + \color{blue}{c \cdot \left(-3 \cdot a\right)}} - b}{3 \cdot a}
\] |
rational_best-simplify-52 [=>]10.7 | \[ \frac{\sqrt{b \cdot b + c \cdot \color{blue}{\left(a \cdot \left(-3\right)\right)}} - b}{3 \cdot a}
\] |
metadata-eval [=>]10.7 | \[ \frac{\sqrt{b \cdot b + c \cdot \left(a \cdot \color{blue}{-3}\right)} - b}{3 \cdot a}
\] |
if 3e-134 < b Initial program 50.1
Simplified50.1
[Start]50.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
rational_best-simplify-62 [=>]50.1 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \left(-\left(-b\right)\right)}}{3 \cdot a}
\] |
rational_best-simplify-51 [=>]50.1 | \[ \frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - \color{blue}{b}}{3 \cdot a}
\] |
rational_best-simplify-61 [=>]50.1 | \[ \frac{\sqrt{\color{blue}{b \cdot b + \left(-\left(3 \cdot a\right) \cdot c\right)}} - b}{3 \cdot a}
\] |
rational_best-simplify-52 [=>]50.1 | \[ \frac{\sqrt{b \cdot b + \color{blue}{c \cdot \left(-3 \cdot a\right)}} - b}{3 \cdot a}
\] |
rational_best-simplify-52 [=>]50.1 | \[ \frac{\sqrt{b \cdot b + c \cdot \color{blue}{\left(a \cdot \left(-3\right)\right)}} - b}{3 \cdot a}
\] |
metadata-eval [=>]50.1 | \[ \frac{\sqrt{b \cdot b + c \cdot \left(a \cdot \color{blue}{-3}\right)} - b}{3 \cdot a}
\] |
Taylor expanded in b around inf 12.9
Final simplification10.7
| Alternative 1 | |
|---|---|
| Error | 14.8 |
| Cost | 7368 |
| Alternative 2 | |
|---|---|
| Error | 14.8 |
| Cost | 7368 |
| Alternative 3 | |
|---|---|
| Error | 15.0 |
| Cost | 7240 |
| Alternative 4 | |
|---|---|
| Error | 14.9 |
| Cost | 7240 |
| Alternative 5 | |
|---|---|
| Error | 20.2 |
| Cost | 7112 |
| Alternative 6 | |
|---|---|
| Error | 22.9 |
| Cost | 580 |
| Alternative 7 | |
|---|---|
| Error | 37.0 |
| Cost | 452 |
| Alternative 8 | |
|---|---|
| Error | 22.9 |
| Cost | 452 |
| Alternative 9 | |
|---|---|
| Error | 40.3 |
| Cost | 320 |
herbie shell --seed 2023104
(FPCore (a b c)
:name "Cubic critical"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))