1 | initial version |
While manipulating the expression tree explicitly certainly solves your problem, it might be worthwhile seeing a solution that's a little more general (also: you might want to truncate throughout rather than only at the end, because a lot of time and memory might get devoted to computing the higher order terms that get discarded anyway).
You can get a result by turning the thing into a power series object over SR:
sage: e = x*dt + x*x0*9*dt^2 + x*100*dt^3
sage: R.<DT>=PowerSeriesRing(SR)
Ideally at this point you'd use e(dt=DT)
to turn the object into what you want. Unfortunately that doesn't work because of the ambiguity of whether R maps into SR or SR into R. It would be nice if coercion could figure out SR mapping into R here, but currently it doesn't. But we can do it manually without having to go all the way to expression tree manipulation:
sage: E=sum(c*DT^i for c,i in e.coefficients(dt)); E
x*DT + 9*x*x0*DT^2 + 100*x*DT^3
Now we have an object that understands big-Oh:
sage: E+O(DT^3)
x*DT + 9*x*x0*DT^2 + O(DT^3)