Below is code that
1) Creates a function based on the solution to a recurrence. This function is the one I expect.
2) Prints, in order: the text $n$-kite for $n \in [4, \dots]$, two polynomials associated with the $n$-kite, and then the GCD of the two polynomials.
The polynomials associated with the $n$-kite are always correctly printed, but the GCD
of the polynomials expressed as functions is inconsistent with the GCD
I obtain by applying PolynomialGCD
to the explicit polynomials.
In other words, if $f(x) = x^2 + 3x + 2$ and $g(x) = x^4+3x$, then PolynomialGCD[f, g]
$\not =$ GCDPolynomial[x^2 + 3x + 2, x^4 + 3x]
. I see this inconsistency take place in my code, and I am not sure how to resolve it.
Clear[a, d, f, n]
f[d_, n_] =
Simplify[a[n] /.
RSolve[{(a[n + 1] - a[n] d + a[n - 1]) == 2 - d,
a[1] == d^3 - 2 d + 1, a[0] == d^2}, a[n], n][[1]]];
For[i=1, i < 50, i++,
Print[Evaluate[i + 3] - kite];
Print[FullSimplify[f[d, i]]];
Print[Together[(-1)*f[d, i - 1] + 1 - d]];
Print["GCD: ", PolynomialGCD[f[d, i], Together[(-1)(f[d, i - 1]) + 1 - d]]]
]
\\ Output below for some kites
Why does GCDPolynomial
give $\frac{1}{4}$ when applied to $1 + 3d - 4d^3 +d^5$ and $-1 -d +3d^2- d^4$. The result should really be $d^3 + d^2 - 2d - 1$.
PolynomialGCD
takes the input as it is provided, which in this case contains algebraic functions. To have it work on explicit polynomials, one could useExpand
e.g. like this:tt = Table[PolynomialGCD @@ Expand[{f[d, i], -f[d, i - 1] + 1 - d}], {i, 50}];
$\endgroup$