| Alternative 1 | |
|---|---|
| Error | 0.7 |
| Cost | 34624 |
(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))))
(/
(fma 6.0 (* c (* a (* b b))) (* -9.0 (* a (* c (* c a)))))
(* (fma b b t_0) (* (* a -3.0) (+ b (sqrt t_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));
return fma(6.0, (c * (a * (b * b))), (-9.0 * (a * (c * (c * a))))) / (fma(b, b, t_0) * ((a * -3.0) * (b + sqrt(t_0))));
}
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)) return Float64(fma(6.0, Float64(c * Float64(a * Float64(b * b))), Float64(-9.0 * Float64(a * Float64(c * Float64(c * a))))) / Float64(fma(b, b, t_0) * Float64(Float64(a * -3.0) * Float64(b + sqrt(t_0))))) 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]}, N[(N[(6.0 * N[(c * N[(a * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-9.0 * N[(a * N[(c * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(b * b + t$95$0), $MachinePrecision] * N[(N[(a * -3.0), $MachinePrecision] * N[(b + N[Sqrt[t$95$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)\\
\frac{\mathsf{fma}\left(6, c \cdot \left(a \cdot \left(b \cdot b\right)\right), -9 \cdot \left(a \cdot \left(c \cdot \left(c \cdot a\right)\right)\right)\right)}{\mathsf{fma}\left(b, b, t_0\right) \cdot \left(\left(a \cdot -3\right) \cdot \left(b + \sqrt{t_0}\right)\right)}
\end{array}
Initial program 28.8
Simplified28.8
[Start]28.8 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
remove-double-neg [<=]28.8 | \[ \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 [<=]28.8 | \[ \frac{\color{blue}{\left(-b\right) - \left(-\sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a}
\] |
div-sub [=>]29.3 | \[ \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 [=>]29.3 | \[ \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/ [<=]29.3 | \[ \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 [=>]29.3 | \[ \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 [=>]28.8 | \[ \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 [<=]28.8 | \[ \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 [<=]28.8 | \[ \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* [<=]28.8 | \[ \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 [<=]28.8 | \[ \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 [<=]28.8 | \[ \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 [<=]29.3 | \[ \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 [=>]29.3 | \[ \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-rr27.9
Simplified27.9
[Start]27.9 | \[ \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-/r* [=>]27.9 | \[ \color{blue}{\frac{\frac{{b}^{4} - {\left(\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}^{2}}{\left(a \cdot -3\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}}{b \cdot b + \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}}
\] |
associate-*l* [=>]27.9 | \[ \frac{\frac{{b}^{4} - {\left(\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}^{2}}{\color{blue}{a \cdot \left(-3 \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)\right)}}}{b \cdot b + \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}
\] |
fma-def [=>]27.9 | \[ \frac{\frac{{b}^{4} - {\left(\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}^{2}}{a \cdot \left(-3 \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)\right)}}{\color{blue}{\mathsf{fma}\left(b, b, \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}}
\] |
Taylor expanded in b around 0 0.7
Simplified0.7
[Start]0.7 | \[ \frac{\frac{6 \cdot \left(c \cdot \left(a \cdot {b}^{2}\right)\right) + -9 \cdot \left({c}^{2} \cdot {a}^{2}\right)}{a \cdot \left(-3 \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)\right)}}{\mathsf{fma}\left(b, b, \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}
\] |
|---|---|
fma-def [=>]0.7 | \[ \frac{\frac{\color{blue}{\mathsf{fma}\left(6, c \cdot \left(a \cdot {b}^{2}\right), -9 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}}{a \cdot \left(-3 \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)\right)}}{\mathsf{fma}\left(b, b, \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}
\] |
unpow2 [=>]0.7 | \[ \frac{\frac{\mathsf{fma}\left(6, c \cdot \left(a \cdot \color{blue}{\left(b \cdot b\right)}\right), -9 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}{a \cdot \left(-3 \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)\right)}}{\mathsf{fma}\left(b, b, \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}
\] |
unpow2 [=>]0.7 | \[ \frac{\frac{\mathsf{fma}\left(6, c \cdot \left(a \cdot \left(b \cdot b\right)\right), -9 \cdot \left(\color{blue}{\left(c \cdot c\right)} \cdot {a}^{2}\right)\right)}{a \cdot \left(-3 \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)\right)}}{\mathsf{fma}\left(b, b, \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}
\] |
unpow2 [=>]0.7 | \[ \frac{\frac{\mathsf{fma}\left(6, c \cdot \left(a \cdot \left(b \cdot b\right)\right), -9 \cdot \left(\left(c \cdot c\right) \cdot \color{blue}{\left(a \cdot a\right)}\right)\right)}{a \cdot \left(-3 \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)\right)}}{\mathsf{fma}\left(b, b, \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right)}
\] |
Applied egg-rr24.4
Simplified0.7
[Start]24.4 | \[ e^{\mathsf{log1p}\left(\frac{\mathsf{fma}\left(6, \left(b \cdot b\right) \cdot \left(c \cdot a\right), -9 \cdot {\left(c \cdot a\right)}^{2}\right)}{\left(\mathsf{fma}\left(b, b, \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right) \cdot \left(a \cdot -3\right)\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}\right)} - 1
\] |
|---|---|
expm1-def [=>]9.5 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\mathsf{fma}\left(6, \left(b \cdot b\right) \cdot \left(c \cdot a\right), -9 \cdot {\left(c \cdot a\right)}^{2}\right)}{\left(\mathsf{fma}\left(b, b, \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right) \cdot \left(a \cdot -3\right)\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}\right)\right)}
\] |
expm1-log1p [=>]0.7 | \[ \color{blue}{\frac{\mathsf{fma}\left(6, \left(b \cdot b\right) \cdot \left(c \cdot a\right), -9 \cdot {\left(c \cdot a\right)}^{2}\right)}{\left(\mathsf{fma}\left(b, b, \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right) \cdot \left(a \cdot -3\right)\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}}
\] |
*-commutative [=>]0.7 | \[ \frac{\mathsf{fma}\left(6, \color{blue}{\left(c \cdot a\right) \cdot \left(b \cdot b\right)}, -9 \cdot {\left(c \cdot a\right)}^{2}\right)}{\left(\mathsf{fma}\left(b, b, \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right) \cdot \left(a \cdot -3\right)\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}
\] |
unpow2 [<=]0.7 | \[ \frac{\mathsf{fma}\left(6, \left(c \cdot a\right) \cdot \color{blue}{{b}^{2}}, -9 \cdot {\left(c \cdot a\right)}^{2}\right)}{\left(\mathsf{fma}\left(b, b, \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right) \cdot \left(a \cdot -3\right)\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}
\] |
associate-*r* [<=]0.7 | \[ \frac{\mathsf{fma}\left(6, \color{blue}{c \cdot \left(a \cdot {b}^{2}\right)}, -9 \cdot {\left(c \cdot a\right)}^{2}\right)}{\left(\mathsf{fma}\left(b, b, \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right) \cdot \left(a \cdot -3\right)\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}
\] |
unpow2 [=>]0.7 | \[ \frac{\mathsf{fma}\left(6, c \cdot \left(a \cdot \color{blue}{\left(b \cdot b\right)}\right), -9 \cdot {\left(c \cdot a\right)}^{2}\right)}{\left(\mathsf{fma}\left(b, b, \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right) \cdot \left(a \cdot -3\right)\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)}
\] |
associate-*l* [=>]0.7 | \[ \frac{\mathsf{fma}\left(6, c \cdot \left(a \cdot \left(b \cdot b\right)\right), -9 \cdot {\left(c \cdot a\right)}^{2}\right)}{\color{blue}{\mathsf{fma}\left(b, b, \mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)\right) \cdot \left(\left(a \cdot -3\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)}\right)\right)}}
\] |
Applied egg-rr0.7
Final simplification0.7
| Alternative 1 | |
|---|---|
| Error | 0.7 |
| Cost | 34624 |
| Alternative 2 | |
|---|---|
| Error | 6.4 |
| Cost | 21700 |
| Alternative 3 | |
|---|---|
| Error | 0.7 |
| Cost | 20736 |
| Alternative 4 | |
|---|---|
| Error | 9.4 |
| Cost | 13764 |
| Alternative 5 | |
|---|---|
| Error | 9.4 |
| Cost | 7620 |
| Alternative 6 | |
|---|---|
| Error | 9.5 |
| Cost | 7492 |
| Alternative 7 | |
|---|---|
| Error | 9.5 |
| Cost | 7492 |
| Alternative 8 | |
|---|---|
| Error | 11.6 |
| Cost | 7296 |
| Alternative 9 | |
|---|---|
| Error | 22.6 |
| Cost | 320 |
| Alternative 10 | |
|---|---|
| Error | 22.6 |
| Cost | 320 |
| Alternative 11 | |
|---|---|
| Error | 22.5 |
| Cost | 320 |
herbie shell --seed 2023012
(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)))