| Alternative 1 | |
|---|---|
| Error | 4.8 |
| Cost | 48772 |
(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))))
(if (<= (/ (- (sqrt (- (* b b) (* (* 3.0 a) c))) b) (* 3.0 a)) -19.5)
(/
(/ (- (pow b 4.0) (pow t_0 2.0)) (* a -3.0))
(* (+ b (sqrt t_0)) (fma b b t_0)))
(/
1.0
(fma
-2.0
(/ b c)
(fma
1.125
(* c (/ (* a a) (pow b 3.0)))
(fma
1.5
(/ a b)
(*
(/ 3.0 (pow b 5.0))
(*
a
(*
(+
(* 0.2222222222222222 (* (/ (pow a 4.0) a) (/ 6.328125 a)))
(* (* a a) -0.84375))
(* c c)))))))))))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 tmp;
if (((sqrt(((b * b) - ((3.0 * a) * c))) - b) / (3.0 * a)) <= -19.5) {
tmp = ((pow(b, 4.0) - pow(t_0, 2.0)) / (a * -3.0)) / ((b + sqrt(t_0)) * fma(b, b, t_0));
} else {
tmp = 1.0 / fma(-2.0, (b / c), fma(1.125, (c * ((a * a) / pow(b, 3.0))), fma(1.5, (a / b), ((3.0 / pow(b, 5.0)) * (a * (((0.2222222222222222 * ((pow(a, 4.0) / a) * (6.328125 / a))) + ((a * a) * -0.84375)) * (c * c)))))));
}
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)) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c))) - b) / Float64(3.0 * a)) <= -19.5) tmp = Float64(Float64(Float64((b ^ 4.0) - (t_0 ^ 2.0)) / Float64(a * -3.0)) / Float64(Float64(b + sqrt(t_0)) * fma(b, b, t_0))); else tmp = Float64(1.0 / fma(-2.0, Float64(b / c), fma(1.125, Float64(c * Float64(Float64(a * a) / (b ^ 3.0))), fma(1.5, Float64(a / b), Float64(Float64(3.0 / (b ^ 5.0)) * Float64(a * Float64(Float64(Float64(0.2222222222222222 * Float64(Float64((a ^ 4.0) / a) * Float64(6.328125 / a))) + Float64(Float64(a * a) * -0.84375)) * Float64(c * c)))))))); 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]}, If[LessEqual[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], -19.5], N[(N[(N[(N[Power[b, 4.0], $MachinePrecision] - N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision] / N[(a * -3.0), $MachinePrecision]), $MachinePrecision] / N[(N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision] * N[(b * b + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(-2.0 * N[(b / c), $MachinePrecision] + N[(1.125 * N[(c * N[(N[(a * a), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(1.5 * N[(a / b), $MachinePrecision] + N[(N[(3.0 / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision] * N[(a * N[(N[(N[(0.2222222222222222 * N[(N[(N[Power[a, 4.0], $MachinePrecision] / a), $MachinePrecision] * N[(6.328125 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(a * a), $MachinePrecision] * -0.84375), $MachinePrecision]), $MachinePrecision] * N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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)\\
\mathbf{if}\;\frac{\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c} - b}{3 \cdot a} \leq -19.5:\\
\;\;\;\;\frac{\frac{{b}^{4} - {t_0}^{2}}{a \cdot -3}}{\left(b + \sqrt{t_0}\right) \cdot \mathsf{fma}\left(b, b, t_0\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(-2, \frac{b}{c}, \mathsf{fma}\left(1.125, c \cdot \frac{a \cdot a}{{b}^{3}}, \mathsf{fma}\left(1.5, \frac{a}{b}, \frac{3}{{b}^{5}} \cdot \left(a \cdot \left(\left(0.2222222222222222 \cdot \left(\frac{{a}^{4}}{a} \cdot \frac{6.328125}{a}\right) + \left(a \cdot a\right) \cdot -0.84375\right) \cdot \left(c \cdot c\right)\right)\right)\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)) < -19.5Initial program 8.9
Simplified8.9
[Start]8.9 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]8.9 | \[ \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 [<=]8.9 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]9.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 [=>]9.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/ [<=]9.6 | \[ \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 [=>]9.6 | \[ \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 [=>]9.4 | \[ \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 [<=]9.4 | \[ \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 [<=]9.4 | \[ \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* [<=]9.4 | \[ \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 [<=]9.4 | \[ \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 [<=]9.4 | \[ \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 [<=]9.6 | \[ \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 [=>]9.6 | \[ \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}}
\] |
Applied egg-rr8.4
Simplified8.4
[Start]8.4 | \[ \frac{{b}^{4} - {\left(\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}^{2}}{\left(\left(a \cdot -3\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)\right) \cdot \left(b \cdot b + \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}
\] |
|---|---|
associate-*l* [=>]8.4 | \[ \frac{{b}^{4} - {\left(\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}^{2}}{\color{blue}{\left(a \cdot -3\right) \cdot \left(\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \left(b \cdot b + \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)\right)}}
\] |
associate-/r* [=>]8.4 | \[ \color{blue}{\frac{\frac{{b}^{4} - {\left(\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}^{2}}{a \cdot -3}}{\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \left(b \cdot b + \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}}
\] |
fma-def [=>]8.4 | \[ \frac{\frac{{b}^{4} - {\left(\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}^{2}}{a \cdot -3}}{\left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right) \cdot \color{blue}{\mathsf{fma}\left(b, b, \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}}
\] |
if -19.5 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) Initial program 30.6
Simplified30.6
[Start]30.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]30.6 | \[ \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 [<=]30.6 | \[ \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.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 [=>]31.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/ [<=]31.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 [=>]31.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 [=>]30.5 | \[ \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 [<=]30.5 | \[ \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 [<=]30.5 | \[ \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* [<=]30.5 | \[ \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 [<=]30.5 | \[ \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 [<=]30.5 | \[ \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.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 [=>]31.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}}
\] |
Applied egg-rr30.6
Taylor expanded in b around inf 4.7
Simplified4.7
[Start]4.7 | \[ \frac{1}{\left(a \cdot -3\right) \cdot \left(\left(-1 \cdot \frac{-0.5625 \cdot \left({c}^{2} \cdot {a}^{2}\right) + \left(0.2222222222222222 \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)}{{c}^{2} \cdot {a}^{2}} + -0.75 \cdot \left(c \cdot \left(\left(-0.375 \cdot \left(c \cdot a\right) + 0.75 \cdot \left(c \cdot a\right)\right) \cdot a\right)\right)\right)}{{b}^{5}} + \left(-1 \cdot \frac{-0.375 \cdot \left(c \cdot a\right) + 0.75 \cdot \left(c \cdot a\right)}{{b}^{3}} + 0.6666666666666666 \cdot \frac{b}{c \cdot a}\right)\right) - 0.5 \cdot \frac{1}{b}\right)}
\] |
|---|
Taylor expanded in c around 0 4.5
Simplified4.5
[Start]4.5 | \[ \frac{1}{-2 \cdot \frac{b}{c} + \left(1.5 \cdot \frac{a}{b} + \left(3 \cdot \frac{{c}^{2} \cdot \left(a \cdot \left(-0.28125 \cdot {a}^{2} + \left(0.2222222222222222 \cdot \frac{1.265625 \cdot {a}^{4} + 5.0625 \cdot {a}^{4}}{{a}^{2}} + -0.5625 \cdot {a}^{2}\right)\right)\right)}{{b}^{5}} + 1.125 \cdot \frac{c \cdot {a}^{2}}{{b}^{3}}\right)\right)}
\] |
|---|---|
fma-def [=>]4.5 | \[ \frac{1}{\color{blue}{\mathsf{fma}\left(-2, \frac{b}{c}, 1.5 \cdot \frac{a}{b} + \left(3 \cdot \frac{{c}^{2} \cdot \left(a \cdot \left(-0.28125 \cdot {a}^{2} + \left(0.2222222222222222 \cdot \frac{1.265625 \cdot {a}^{4} + 5.0625 \cdot {a}^{4}}{{a}^{2}} + -0.5625 \cdot {a}^{2}\right)\right)\right)}{{b}^{5}} + 1.125 \cdot \frac{c \cdot {a}^{2}}{{b}^{3}}\right)\right)}}
\] |
associate-+r+ [=>]4.5 | \[ \frac{1}{\mathsf{fma}\left(-2, \frac{b}{c}, \color{blue}{\left(1.5 \cdot \frac{a}{b} + 3 \cdot \frac{{c}^{2} \cdot \left(a \cdot \left(-0.28125 \cdot {a}^{2} + \left(0.2222222222222222 \cdot \frac{1.265625 \cdot {a}^{4} + 5.0625 \cdot {a}^{4}}{{a}^{2}} + -0.5625 \cdot {a}^{2}\right)\right)\right)}{{b}^{5}}\right) + 1.125 \cdot \frac{c \cdot {a}^{2}}{{b}^{3}}}\right)}
\] |
+-commutative [<=]4.5 | \[ \frac{1}{\mathsf{fma}\left(-2, \frac{b}{c}, \color{blue}{1.125 \cdot \frac{c \cdot {a}^{2}}{{b}^{3}} + \left(1.5 \cdot \frac{a}{b} + 3 \cdot \frac{{c}^{2} \cdot \left(a \cdot \left(-0.28125 \cdot {a}^{2} + \left(0.2222222222222222 \cdot \frac{1.265625 \cdot {a}^{4} + 5.0625 \cdot {a}^{4}}{{a}^{2}} + -0.5625 \cdot {a}^{2}\right)\right)\right)}{{b}^{5}}\right)}\right)}
\] |
fma-def [=>]4.5 | \[ \frac{1}{\mathsf{fma}\left(-2, \frac{b}{c}, \color{blue}{\mathsf{fma}\left(1.125, \frac{c \cdot {a}^{2}}{{b}^{3}}, 1.5 \cdot \frac{a}{b} + 3 \cdot \frac{{c}^{2} \cdot \left(a \cdot \left(-0.28125 \cdot {a}^{2} + \left(0.2222222222222222 \cdot \frac{1.265625 \cdot {a}^{4} + 5.0625 \cdot {a}^{4}}{{a}^{2}} + -0.5625 \cdot {a}^{2}\right)\right)\right)}{{b}^{5}}\right)}\right)}
\] |
Final simplification4.8
| Alternative 1 | |
|---|---|
| Error | 4.8 |
| Cost | 48772 |
| Alternative 2 | |
|---|---|
| Error | 6.3 |
| Cost | 48452 |
| Alternative 3 | |
|---|---|
| Error | 6.2 |
| Cost | 28484 |
| Alternative 4 | |
|---|---|
| Error | 6.2 |
| Cost | 28228 |
| Alternative 5 | |
|---|---|
| Error | 6.2 |
| Cost | 28228 |
| Alternative 6 | |
|---|---|
| Error | 6.2 |
| Cost | 28228 |
| Alternative 7 | |
|---|---|
| Error | 6.3 |
| Cost | 21700 |
| Alternative 8 | |
|---|---|
| Error | 6.5 |
| Cost | 21060 |
| Alternative 9 | |
|---|---|
| Error | 6.5 |
| Cost | 21060 |
| Alternative 10 | |
|---|---|
| Error | 6.5 |
| Cost | 16004 |
| Alternative 11 | |
|---|---|
| Error | 9.0 |
| Cost | 14788 |
| Alternative 12 | |
|---|---|
| Error | 9.2 |
| Cost | 7492 |
| Alternative 13 | |
|---|---|
| Error | 9.3 |
| Cost | 7492 |
| Alternative 14 | |
|---|---|
| Error | 11.3 |
| Cost | 832 |
| Alternative 15 | |
|---|---|
| Error | 22.7 |
| Cost | 320 |
herbie shell --seed 2023053
(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)))