trunc and taylor



Richard Fateman wrote:
> Not a bug.
>
> take a 5 term taylor series and add/subtract a 7 term taylor series 
> and the computation is done to 5 terms only.
> This is right because expanding the 5 term taylor series to  
> +0*x^6+0*x^7  is unwarranted.
>
> If you do something that takes the expression out of the taylor series 
> representation, so you have a 5 term
> polynomial and a 7 term polynomial, then their difference can be 
> computed as a polynomial.  (or a number).
>
> It's a feature.
>
> RJF
>
>
> Sheldon Newhouse wrote:
>> Jer?nimo Alaminos Prats wrote:
>>   
>>> Hi all,
>>> I've using maxima for about a month in a calculus class. I'm writing  
>>> some notes to help the students and now I'm having some trouble with  
>>> the behavior of Taylor series.
>>> If I define a function and its Taylor polinomial, I have no problem  
>>> plotting both or calculating the difference
>>>
>>> (%i3) taylor(log(1+x),x,0,5);
>>> (%o3) x-x^2/2+x^3/3-x^4/4+x^5/5+...
>>> (%i5) define(g(x),taylor(f(x),x,0,5));
>>> (%o5) g(x):=x-x^2/2+x^3/3-x^4/4+x^5/5+...
>>> (%i6) g(2);
>>> (%o6) 76/15
>>> (%i8) f(2)-g(2);
>>> (%o8) (15*log(3)-76)/15
>>> but
>>>
>>> plot2d[f(x)-g(x),[x,0.1,5])
>>>
>>> plots the zero function. I can obtain the expected (at least for me)  
>>> behavior using
>>>
>>> plot2d(f(x)-trunc(g(x)),[x,0.1,5])
>>>
>>> Is this the right thing to do? I do not understand when it's mandatory  
>>> to use trunc with taylor and when it is optional? I mean, what's the  
>>> difference between taylor(...) and trunc(taylor(...))?
>>>
>>> If someone it's interested the notes (in spanish) are available as a  
>>> work in progress at
>>>
>>> http://www.ugr.es/~alaminos/docencia_2/calculo_telecomunicaciones/practicas_de_ordenador/
>>>
>>> Of course any comments are welcome.
>>>
>>> Thank you,
>>> Jer?nimo.
>>>
>>>
>>>
>>> _______________________________________________
>>> Maxima mailing list
>>> Maxima at math.utexas.edu
>>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>>
>>>   
>>>     
>> This looks like a bug to me. 
>> What do others think?
>>
>> For instance,
>> (%i37) display2d: false;
>>
>> (%o37) false
>> (%i38) f(x):= taylor(log(1+x),x,0,5);
>>
>> (%o38) f(x):=taylor(log(1+x),x,0,5)
>> (%i39) g(x):= taylor(log(1+x),x,0,7);
>>
>> (%o39) g(x):=taylor(log(1+x),x,0,7)
>> (%i40) f(x);
>>
>> (%o40) x-x^2/2+x^3/3-x^4/4+x^5/5
>> (%i41) g(x);
>>
>> (%o41) x-x^2/2+x^3/3-x^4/4+x^5/5-x^6/6+x^7/7
>> (%i42) g(x)-f(x);
>>
>> (%o42) +0
>> (%i43) ratexpand(g(x)) - ratexpand(f(x));
>>
>> (%o43) x^7/7-x^6/6
>>
>> Using 'ratexpand' seems to fix the problem, but I don't think that 
>> should be necessary.
>>
>> -sen
>>
>>
>>  
>> _______________________________________________
>> Maxima mailing list
>> Maxima at math.utexas.edu
>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>   
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>   
Then, why does 'trunc' behave differently?
(%o5) f(x):=taylor(log(1+x),x,0,5)
(%i6) g(x):= taylor(log(1+x),x,0,7);

(%o6) g(x):=taylor(log(1+x),x,0,7)
(%i7) f1(x):= trunc(taylor(log(1+x),x,0,5));

(%o7) f1(x):=trunc(taylor(log(1+x),x,0,5))
(%i8) g1(x):= trunc(taylor(log(1+x),x,0,7));

(%o8) g1(x):=trunc(taylor(log(1+x),x,0,7))
(%i9) g(x)-f(x);

(%o9) +0
(%i10) g1(x)-f1(x);

(%o10) x^7/7-x^6/6

-sen