| Alternative 1 | |
|---|---|
| Error | 10.3 |
| 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 (sqrt (fma a (* c -3.0) (* b b)))))
(if (<= b -3e+140)
(/ b (* a -1.5))
(if (<= b 1.22e-26)
(*
(+ (fma (/ -1.0 a) t_0 (/ t_0 a)) (/ (- b t_0) a))
-0.3333333333333333)
(/ (* c -0.5) 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 = sqrt(fma(a, (c * -3.0), (b * b)));
double tmp;
if (b <= -3e+140) {
tmp = b / (a * -1.5);
} else if (b <= 1.22e-26) {
tmp = (fma((-1.0 / a), t_0, (t_0 / a)) + ((b - t_0) / a)) * -0.3333333333333333;
} else {
tmp = (c * -0.5) / 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 = sqrt(fma(a, Float64(c * -3.0), Float64(b * b))) tmp = 0.0 if (b <= -3e+140) tmp = Float64(b / Float64(a * -1.5)); elseif (b <= 1.22e-26) tmp = Float64(Float64(fma(Float64(-1.0 / a), t_0, Float64(t_0 / a)) + Float64(Float64(b - t_0) / a)) * -0.3333333333333333); else tmp = Float64(Float64(c * -0.5) / b); end return 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[Sqrt[N[(a * N[(c * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -3e+140], N[(b / N[(a * -1.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.22e-26], N[(N[(N[(N[(-1.0 / a), $MachinePrecision] * t$95$0 + N[(t$95$0 / a), $MachinePrecision]), $MachinePrecision] + N[(N[(b - t$95$0), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] * -0.3333333333333333), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b), $MachinePrecision]]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\\
\mathbf{if}\;b \leq -3 \cdot 10^{+140}:\\
\;\;\;\;\frac{b}{a \cdot -1.5}\\
\mathbf{elif}\;b \leq 1.22 \cdot 10^{-26}:\\
\;\;\;\;\left(\mathsf{fma}\left(\frac{-1}{a}, t_0, \frac{t_0}{a}\right) + \frac{b - t_0}{a}\right) \cdot -0.3333333333333333\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b}\\
\end{array}
if b < -2.99999999999999997e140Initial program 59.1
Simplified59.1
[Start]59.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]59.1 | \[ \frac{\left(-b\right) + \color{blue}{\left(-\left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)\right)}}{3 \cdot a}
\] |
sub-neg [<=]59.1 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]59.1 | \[ \color{blue}{\frac{-b}{3 \cdot a} - \frac{-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
neg-mul-1 [=>]59.1 | \[ \frac{\color{blue}{-1 \cdot b}}{3 \cdot a} - \frac{-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
associate-*l/ [<=]59.1 | \[ \color{blue}{\frac{-1}{3 \cdot a} \cdot b} - \frac{-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
distribute-frac-neg [=>]59.1 | \[ \frac{-1}{3 \cdot a} \cdot b - \color{blue}{\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)}
\] |
fma-neg [=>]59.1 | \[ \color{blue}{\mathsf{fma}\left(\frac{-1}{3 \cdot a}, b, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)}
\] |
/-rgt-identity [<=]59.1 | \[ \mathsf{fma}\left(\frac{-1}{3 \cdot a}, \color{blue}{\frac{b}{1}}, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)
\] |
metadata-eval [<=]59.1 | \[ \mathsf{fma}\left(\frac{-1}{3 \cdot a}, \frac{b}{\color{blue}{\frac{-1}{-1}}}, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)
\] |
associate-/l* [<=]59.1 | \[ \mathsf{fma}\left(\frac{-1}{3 \cdot a}, \color{blue}{\frac{b \cdot -1}{-1}}, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)
\] |
*-commutative [<=]59.1 | \[ \mathsf{fma}\left(\frac{-1}{3 \cdot a}, \frac{\color{blue}{-1 \cdot b}}{-1}, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)
\] |
neg-mul-1 [<=]59.1 | \[ \mathsf{fma}\left(\frac{-1}{3 \cdot a}, \frac{\color{blue}{-b}}{-1}, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)
\] |
fma-neg [<=]59.1 | \[ \color{blue}{\frac{-1}{3 \cdot a} \cdot \frac{-b}{-1} - \left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)}
\] |
neg-mul-1 [=>]59.1 | \[ \frac{-1}{3 \cdot a} \cdot \frac{-b}{-1} - \color{blue}{-1 \cdot \frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
Taylor expanded in b around -inf 3.3
Simplified3.3
[Start]3.3 | \[ -0.6666666666666666 \cdot \frac{b}{a}
\] |
|---|---|
*-commutative [=>]3.3 | \[ \color{blue}{\frac{b}{a} \cdot -0.6666666666666666}
\] |
Taylor expanded in b around 0 3.3
Simplified3.3
[Start]3.3 | \[ -0.6666666666666666 \cdot \frac{b}{a}
\] |
|---|---|
*-commutative [<=]3.3 | \[ \color{blue}{\frac{b}{a} \cdot -0.6666666666666666}
\] |
/-rgt-identity [<=]3.3 | \[ \color{blue}{\frac{\frac{b}{a} \cdot -0.6666666666666666}{1}}
\] |
associate-/l* [=>]3.2 | \[ \color{blue}{\frac{\frac{b}{a}}{\frac{1}{-0.6666666666666666}}}
\] |
associate-/r* [<=]3.3 | \[ \color{blue}{\frac{b}{a \cdot \frac{1}{-0.6666666666666666}}}
\] |
metadata-eval [=>]3.3 | \[ \frac{b}{a \cdot \color{blue}{-1.5}}
\] |
if -2.99999999999999997e140 < b < 1.22e-26Initial program 14.4
Simplified14.5
[Start]14.4 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
*-lft-identity [<=]14.4 | \[ \color{blue}{1 \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
metadata-eval [<=]14.4 | \[ \color{blue}{\frac{-1}{-1}} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
times-frac [<=]14.4 | \[ \color{blue}{\frac{-1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{-1 \cdot \left(3 \cdot a\right)}}
\] |
neg-mul-1 [<=]14.4 | \[ \frac{-1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{\color{blue}{-3 \cdot a}}
\] |
distribute-rgt-neg-in [=>]14.4 | \[ \frac{-1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{\color{blue}{3 \cdot \left(-a\right)}}
\] |
times-frac [=>]14.5 | \[ \color{blue}{\frac{-1}{3} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-a}}
\] |
*-commutative [=>]14.5 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-a} \cdot \frac{-1}{3}}
\] |
Applied egg-rr14.5
Applied egg-rr14.6
if 1.22e-26 < 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}
\] |
|---|---|
remove-double-neg [<=]54.4 | \[ \frac{\left(-b\right) + \color{blue}{\left(-\left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)\right)}}{3 \cdot a}
\] |
sub-neg [<=]54.4 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]55.4 | \[ \color{blue}{\frac{-b}{3 \cdot a} - \frac{-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
neg-mul-1 [=>]55.4 | \[ \frac{\color{blue}{-1 \cdot b}}{3 \cdot a} - \frac{-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
associate-*l/ [<=]56.4 | \[ \color{blue}{\frac{-1}{3 \cdot a} \cdot b} - \frac{-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
distribute-frac-neg [=>]56.4 | \[ \frac{-1}{3 \cdot a} \cdot b - \color{blue}{\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)}
\] |
fma-neg [=>]59.1 | \[ \color{blue}{\mathsf{fma}\left(\frac{-1}{3 \cdot a}, b, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)}
\] |
/-rgt-identity [<=]59.1 | \[ \mathsf{fma}\left(\frac{-1}{3 \cdot a}, \color{blue}{\frac{b}{1}}, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)
\] |
metadata-eval [<=]59.1 | \[ \mathsf{fma}\left(\frac{-1}{3 \cdot a}, \frac{b}{\color{blue}{\frac{-1}{-1}}}, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)
\] |
associate-/l* [<=]59.1 | \[ \mathsf{fma}\left(\frac{-1}{3 \cdot a}, \color{blue}{\frac{b \cdot -1}{-1}}, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)
\] |
*-commutative [<=]59.1 | \[ \mathsf{fma}\left(\frac{-1}{3 \cdot a}, \frac{\color{blue}{-1 \cdot b}}{-1}, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)
\] |
neg-mul-1 [<=]59.1 | \[ \mathsf{fma}\left(\frac{-1}{3 \cdot a}, \frac{\color{blue}{-b}}{-1}, -\left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)\right)
\] |
fma-neg [<=]56.4 | \[ \color{blue}{\frac{-1}{3 \cdot a} \cdot \frac{-b}{-1} - \left(-\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}\right)}
\] |
neg-mul-1 [=>]56.4 | \[ \frac{-1}{3 \cdot a} \cdot \frac{-b}{-1} - \color{blue}{-1 \cdot \frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
Taylor expanded in b around inf 6.7
Applied egg-rr6.7
Final simplification10.3
| Alternative 1 | |
|---|---|
| Error | 10.3 |
| Cost | 7624 |
| Alternative 2 | |
|---|---|
| Error | 10.2 |
| Cost | 7624 |
| Alternative 3 | |
|---|---|
| Error | 13.9 |
| Cost | 7368 |
| Alternative 4 | |
|---|---|
| Error | 13.9 |
| Cost | 7368 |
| Alternative 5 | |
|---|---|
| Error | 13.9 |
| Cost | 7368 |
| Alternative 6 | |
|---|---|
| Error | 36.4 |
| Cost | 452 |
| Alternative 7 | |
|---|---|
| Error | 22.4 |
| Cost | 452 |
| Alternative 8 | |
|---|---|
| Error | 22.4 |
| Cost | 452 |
| Alternative 9 | |
|---|---|
| Error | 22.4 |
| Cost | 452 |
| Alternative 10 | |
|---|---|
| Error | 22.4 |
| Cost | 452 |
| Alternative 11 | |
|---|---|
| Error | 39.7 |
| Cost | 320 |
herbie shell --seed 2023056
(FPCore (a b c)
:name "Cubic critical"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))