A fix to your code: Each coefficient is a single number, even though the rational number Rational[-1, 5] is written 1/5 as if it were the division of two numbers.â€
expr = -t - t^2/2 - t^3/3 - t^4/4 - t^5/5 - t^6/6 - t^7/7;
expr /. c_*t^n_ /; n >= 2 :> Numerator[c]/2*t^n
Other, algebraic methods†for an algebraic object that strictly adhere to “replace the denominators by 2” (whatever be the numerator):
FromCoefficientRules[
CoefficientRules[expr, t] /.
HoldPattern[{n_} -> c_] /; n >= 2 :> {n} -> Numerator[c]/2,
t]
Expand@FromDigits[
Reverse@MapAt[
Numerator[#]/2 &,
CoefficientList[expr, t],
3 ;;],
t]
MonomialList[expr, t] /. c_Rational*t^n_ :> Numerator[c]/2*t^n // Total
Other text-replacement methods:
expr /. c_Rational*t^n_ :> Numerator[c]/2*t^n
(* minimal, tailored to expr:
no need for n>=2 -- all exponents are >=2
no need to check c has Rational as its head *)
expr /. c_*t^n_ :> -1/2*t^n
†Usually, but not universally, I prefer algebraic methods to text-pattern replacements, when making algebraic operations. Here the operation is only quasi-algebraic, but one thing stands out about the question. The way the code-text appears in the input and in the output is not how it actually is as an expression. All subtractions and divisions (Rational[a, b] is not a division) are internally coded in terms of Plus[] and Times[]. Use FullForm[expr] to see the actual code for an expression expr. I’ve learned to be careful with patterns with a division slash like a_ / b_, which is really Times[a_, Power[b_, -1]], and a_ / 2, which is really Times[Rational[1, 2], a_]. Another tricky thing is that Plus and Times have the attributes Flat, Orderless, and OneIdentity, which affect how they match patterns. For instance, consider all the factors that the single instance of c_ matches here: -7 t^4/E^t/Sqrt[2] /. c_*t^n_ :> {c, n}.