| Alternative 1 | |
|---|---|
| Error | 6.5 |
| Cost | 48068 |
(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 (fma a (* c -3.0) (* b b))) (t_1 (pow (* a c) 4.0)))
(if (<= (/ (- (sqrt (+ (* b b) (* c (* a -3.0)))) b) (* 3.0 a)) -2.5)
(*
(/
(/
(* (cbrt (* (* c c) (* a a))) (cbrt 9.0))
(/ (+ b (sqrt t_0)) (cbrt (- (* b b) t_0))))
a)
-0.3333333333333333)
(fma
-0.5625
(* (* c c) (* c (/ a (/ (pow b 5.0) a))))
(fma
-0.16666666666666666
(/ (+ (* t_1 1.265625) (* t_1 5.0625)) (* a (pow b 7.0)))
(fma -0.5 (/ c b) (/ (* -0.375 (* a (* c c))) (pow b 3.0))))))))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 = fma(a, (c * -3.0), (b * b));
double t_1 = pow((a * c), 4.0);
double tmp;
if (((sqrt(((b * b) + (c * (a * -3.0)))) - b) / (3.0 * a)) <= -2.5) {
tmp = (((cbrt(((c * c) * (a * a))) * cbrt(9.0)) / ((b + sqrt(t_0)) / cbrt(((b * b) - t_0)))) / a) * -0.3333333333333333;
} else {
tmp = fma(-0.5625, ((c * c) * (c * (a / (pow(b, 5.0) / a)))), fma(-0.16666666666666666, (((t_1 * 1.265625) + (t_1 * 5.0625)) / (a * pow(b, 7.0))), fma(-0.5, (c / b), ((-0.375 * (a * (c * c))) / pow(b, 3.0)))));
}
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 = fma(a, Float64(c * -3.0), Float64(b * b)) t_1 = Float64(a * c) ^ 4.0 tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -3.0)))) - b) / Float64(3.0 * a)) <= -2.5) tmp = Float64(Float64(Float64(Float64(cbrt(Float64(Float64(c * c) * Float64(a * a))) * cbrt(9.0)) / Float64(Float64(b + sqrt(t_0)) / cbrt(Float64(Float64(b * b) - t_0)))) / a) * -0.3333333333333333); else tmp = fma(-0.5625, Float64(Float64(c * c) * Float64(c * Float64(a / Float64((b ^ 5.0) / a)))), fma(-0.16666666666666666, Float64(Float64(Float64(t_1 * 1.265625) + Float64(t_1 * 5.0625)) / Float64(a * (b ^ 7.0))), fma(-0.5, Float64(c / b), Float64(Float64(-0.375 * Float64(a * Float64(c * c))) / (b ^ 3.0))))); 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[(a * N[(c * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[(a * c), $MachinePrecision], 4.0], $MachinePrecision]}, If[LessEqual[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], -2.5], N[(N[(N[(N[(N[Power[N[(N[(c * c), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[9.0, 1/3], $MachinePrecision]), $MachinePrecision] / N[(N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision] / N[Power[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision] * -0.3333333333333333), $MachinePrecision], N[(-0.5625 * N[(N[(c * c), $MachinePrecision] * N[(c * N[(a / N[(N[Power[b, 5.0], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.16666666666666666 * N[(N[(N[(t$95$1 * 1.265625), $MachinePrecision] + N[(t$95$1 * 5.0625), $MachinePrecision]), $MachinePrecision] / N[(a * N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.5 * N[(c / b), $MachinePrecision] + N[(N[(-0.375 * N[(a * N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 := \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\\
t_1 := {\left(a \cdot c\right)}^{4}\\
\mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -3\right)} - b}{3 \cdot a} \leq -2.5:\\
\;\;\;\;\frac{\frac{\sqrt[3]{\left(c \cdot c\right) \cdot \left(a \cdot a\right)} \cdot \sqrt[3]{9}}{\frac{b + \sqrt{t_0}}{\sqrt[3]{b \cdot b - t_0}}}}{a} \cdot -0.3333333333333333\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-0.5625, \left(c \cdot c\right) \cdot \left(c \cdot \frac{a}{\frac{{b}^{5}}{a}}\right), \mathsf{fma}\left(-0.16666666666666666, \frac{t_1 \cdot 1.265625 + t_1 \cdot 5.0625}{a \cdot {b}^{7}}, \mathsf{fma}\left(-0.5, \frac{c}{b}, \frac{-0.375 \cdot \left(a \cdot \left(c \cdot c\right)\right)}{{b}^{3}}\right)\right)\right)\\
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -2.5Initial program 10.0
Simplified10.0
[Start]10.0 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
*-lft-identity [<=]10.0 | \[ \color{blue}{1 \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
metadata-eval [<=]10.0 | \[ \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 [<=]10.0 | \[ \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 [<=]10.0 | \[ \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 [=>]10.0 | \[ \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 [=>]10.0 | \[ \color{blue}{\frac{-1}{3} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-a}}
\] |
*-commutative [=>]10.0 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-a} \cdot \frac{-1}{3}}
\] |
Applied egg-rr9.2
Taylor expanded in b around 0 8.1
Simplified8.0
[Start]8.1 | \[ \frac{\frac{{\left({c}^{2} \cdot \left(1 \cdot {a}^{2}\right)\right)}^{0.3333333333333333} \cdot \sqrt[3]{9}}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\sqrt[3]{b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}}{a} \cdot -0.3333333333333333
\] |
|---|---|
unpow1/3 [=>]8.0 | \[ \frac{\frac{\color{blue}{\sqrt[3]{{c}^{2} \cdot \left(1 \cdot {a}^{2}\right)}} \cdot \sqrt[3]{9}}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\sqrt[3]{b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}}{a} \cdot -0.3333333333333333
\] |
unpow2 [=>]8.0 | \[ \frac{\frac{\sqrt[3]{\color{blue}{\left(c \cdot c\right)} \cdot \left(1 \cdot {a}^{2}\right)} \cdot \sqrt[3]{9}}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\sqrt[3]{b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}}{a} \cdot -0.3333333333333333
\] |
*-lft-identity [=>]8.0 | \[ \frac{\frac{\sqrt[3]{\left(c \cdot c\right) \cdot \color{blue}{{a}^{2}}} \cdot \sqrt[3]{9}}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\sqrt[3]{b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}}{a} \cdot -0.3333333333333333
\] |
unpow2 [=>]8.0 | \[ \frac{\frac{\sqrt[3]{\left(c \cdot c\right) \cdot \color{blue}{\left(a \cdot a\right)}} \cdot \sqrt[3]{9}}{\frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}{\sqrt[3]{b \cdot b - \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}}}{a} \cdot -0.3333333333333333
\] |
if -2.5 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) Initial program 31.3
Simplified31.3
[Start]31.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]31.3 | \[ \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 [<=]31.3 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]31.8 | \[ \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 [=>]31.8 | \[ \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/ [<=]31.8 | \[ \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 [=>]31.8 | \[ \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 [=>]31.2 | \[ \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 [<=]31.2 | \[ \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 [<=]31.2 | \[ \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* [<=]31.2 | \[ \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 [<=]31.2 | \[ \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 [<=]31.2 | \[ \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 [<=]31.8 | \[ \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 [=>]31.8 | \[ \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 4.2
Simplified4.2
[Start]4.2 | \[ -0.5625 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}} + \left(-0.16666666666666666 \cdot \frac{{\left(-1.125 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 5.0625 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}} + \left(-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}\right)\right)
\] |
|---|---|
fma-def [=>]4.2 | \[ \color{blue}{\mathsf{fma}\left(-0.5625, \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}, -0.16666666666666666 \cdot \frac{{\left(-1.125 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 5.0625 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}} + \left(-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}\right)\right)}
\] |
associate-/l* [=>]4.2 | \[ \mathsf{fma}\left(-0.5625, \color{blue}{\frac{{c}^{3}}{\frac{{b}^{5}}{{a}^{2}}}}, -0.16666666666666666 \cdot \frac{{\left(-1.125 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 5.0625 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}} + \left(-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}\right)\right)
\] |
unpow2 [=>]4.2 | \[ \mathsf{fma}\left(-0.5625, \frac{{c}^{3}}{\frac{{b}^{5}}{\color{blue}{a \cdot a}}}, -0.16666666666666666 \cdot \frac{{\left(-1.125 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 5.0625 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}} + \left(-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}\right)\right)
\] |
fma-def [=>]4.2 | \[ \mathsf{fma}\left(-0.5625, \frac{{c}^{3}}{\frac{{b}^{5}}{a \cdot a}}, \color{blue}{\mathsf{fma}\left(-0.16666666666666666, \frac{{\left(-1.125 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 5.0625 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}}, -0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}\right)}\right)
\] |
Applied egg-rr4.7
Simplified4.2
[Start]4.7 | \[ \mathsf{fma}\left(-0.5625, \frac{{c}^{3}}{\frac{{b}^{5}}{a \cdot a}}, \mathsf{fma}\left(-0.16666666666666666, \frac{{\left(\left(\left(c \cdot c\right) \cdot \left(a \cdot a\right)\right) \cdot -1.125\right)}^{2} + 5.0625 \cdot \left(e^{\mathsf{log1p}\left({\left(c \cdot a\right)}^{4}\right)} - 1\right)}{a \cdot {b}^{7}}, \mathsf{fma}\left(-0.5, \frac{c}{b}, \frac{-0.375 \cdot \left(a \cdot \left(c \cdot c\right)\right)}{{b}^{3}}\right)\right)\right)
\] |
|---|---|
expm1-def [=>]4.2 | \[ \mathsf{fma}\left(-0.5625, \frac{{c}^{3}}{\frac{{b}^{5}}{a \cdot a}}, \mathsf{fma}\left(-0.16666666666666666, \frac{{\left(\left(\left(c \cdot c\right) \cdot \left(a \cdot a\right)\right) \cdot -1.125\right)}^{2} + 5.0625 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({\left(c \cdot a\right)}^{4}\right)\right)}}{a \cdot {b}^{7}}, \mathsf{fma}\left(-0.5, \frac{c}{b}, \frac{-0.375 \cdot \left(a \cdot \left(c \cdot c\right)\right)}{{b}^{3}}\right)\right)\right)
\] |
expm1-log1p [=>]4.2 | \[ \mathsf{fma}\left(-0.5625, \frac{{c}^{3}}{\frac{{b}^{5}}{a \cdot a}}, \mathsf{fma}\left(-0.16666666666666666, \frac{{\left(\left(\left(c \cdot c\right) \cdot \left(a \cdot a\right)\right) \cdot -1.125\right)}^{2} + 5.0625 \cdot \color{blue}{{\left(c \cdot a\right)}^{4}}}{a \cdot {b}^{7}}, \mathsf{fma}\left(-0.5, \frac{c}{b}, \frac{-0.375 \cdot \left(a \cdot \left(c \cdot c\right)\right)}{{b}^{3}}\right)\right)\right)
\] |
Applied egg-rr4.2
Applied egg-rr4.2
Final simplification4.6
| Alternative 1 | |
|---|---|
| Error | 6.5 |
| Cost | 48068 |
| Alternative 2 | |
|---|---|
| Error | 6.9 |
| Cost | 40964 |
| Alternative 3 | |
|---|---|
| Error | 9.0 |
| Cost | 28228 |
| Alternative 4 | |
|---|---|
| Error | 9.0 |
| Cost | 28228 |
| Alternative 5 | |
|---|---|
| Error | 9.2 |
| Cost | 21124 |
| Alternative 6 | |
|---|---|
| Error | 9.4 |
| Cost | 21060 |
| Alternative 7 | |
|---|---|
| Error | 9.4 |
| Cost | 15428 |
| Alternative 8 | |
|---|---|
| Error | 15.5 |
| Cost | 14788 |
| Alternative 9 | |
|---|---|
| Error | 16.7 |
| Cost | 7492 |
| Alternative 10 | |
|---|---|
| Error | 16.7 |
| Cost | 7492 |
| Alternative 11 | |
|---|---|
| Error | 22.5 |
| Cost | 320 |
herbie shell --seed 2023034
(FPCore (a b c)
:name "Cubic critical, narrow range"
:precision binary64
:pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))