Conver taylor polynomial to prefix form

Help
UnTom
2011-08-19
2012-11-20
  • UnTom

    UnTom - 2011-08-19

    Hi there!
    I'd like to produce a polynomial from the return value of "taylor", but without the "O" at the end. Basically I'm looking for something like "taylortostandard" from the taylor package, except that I don't want to simplify/reevaluate the polynomial. What's the best way to approach this?

    cheers

    Thomas

     
  • Rainer Schöpf

    Rainer Schöpf - 2011-08-21

    Hello Thomas,

    within the Taylor package, the operator taylortostandard is the only way to convert back into polynomial form, I'm afraid.

    What is the problem with the simplification step?

    Rainer

     
  • Thomas Sturm

    Thomas Sturm - 2011-08-22

    With interactive use the normalization step ist probably quite tedious.

    Thomas: You probably want to define something like the following:

    algebraic procedure staylor(f,x,x0,n);
       taylortostandard taylor(f,x,x0,n);

    Then

    27: example := staylor(sin(x),x,0,13);

    29: example := staylor(sin(x),x,0,13);

    example := (x*(x**12 - 156*x**10 + 17160*x**8 - 1235520*x**6 + 51891840*x**4 - 1037836800*x**2 + 6227020800))/6227020800$

    Notice that by default Reduce factorizes to a certain extent, and computes the common denominator of the rational function obtained. This can be changed as follows:

    on rational;
    off allfac;

    One possible technique for seeing natural output but globally modifying the environment is the following:

    fluid '(!*rational !*allfac);  % necessary when creating a fasl file from this

    symbolic operator staylor;

    symbolic procedure staylor(f,x,x0,n);
       begin scalar !*rational,!*allfac,svrational,svallfac,res;
          svrational := !*rational;
          svallfac := !*allfac;
          on1 'rational;
          off1 'allfac;
          res := mkquote reval {'taylortostandard,{'taylor,f,x,x0,n}};
          onoff('rational,svrational);
          onoff('allfac,svallfac);
          return res
       end;

    Then:

    32: example := staylor(sin(x),x,0,13);
    example := 1/6227020800*x**13 - 1/39916800*x**11 + 1/362880*x**9 - 1/5040*x**7 + 1/120*x**5 - 1/6*x**3 + x$

    33: example;(x*(x**12 - 156*x**10 + 17160*x**8 - 1235520*x**6 + 51891840*x**4 - 1037836800*x**2 + 6227020800))/6227020800$

    Notice that with the first reevaluation of example, everything is converted according to the global switch settings, but implicitly!

    Hope this helps!

    Rainer: Maybe you want to add this as an option to the taylor package?

    Thomas

     
  • Arthur Norman

    Arthur Norman - 2011-08-22

    In your procedure staylor I do not think you want to put !*rational and !*allfac in trhe "begin scalar" list since that will rebind them both to nil and so svrational and svallfac will always be nil. For !*allfac actually you could probably not worry about onoff since it is a simple flag variable. Anyway your code will alwsys (I believe) exit having forced rational and allfac to the off state.

       symbolic procedure staylor(f,x,x0,n);
         begin
           scalar !*allfac, svrational, res; % allfac is a sikple flag so this lets it be nil
           svrational := !*rational;
           on1 'rational;     % rational changes domain mode so needs heavier treatment
           …
           onoff('rational, svrational);
           return res;
       end;

    For power series I also like the REVPRI switch that puts the lowest degree term first, and if I have power series where the coeffs are formulae not just numbers I mess with ORDER and so on…

    Arthur

     
  • Thomas Sturm

    Thomas Sturm - 2011-08-22

    Oops! Your are, of course, right Arthur. If anybody still points out interest, I will post a complete correct version.

    Thomas

     
  • Rainer Schöpf

    Rainer Schöpf - 2011-08-23

    A procedure/operator like staylor is a good idea: it can convert the taylor series to a polynomial without the overhead of
    taylortostandard (which converts everything to prefix form and simplies again).

    For a general expression that can contain an arbitrary number of taylor series, taylortostandard must be used. I've been thinking about how to avoid the overhead, by not converting the taylor coefficients from s.q. form to prefix form, but making sure that necessary simplifications are carried out. A bit tricky…

      Rainer

     
  • UnTom

    UnTom - 2011-08-24

    Thank you all for your contributions and suggestions.  Altough unfortunately I still didn't manage to achieve the result I wanted.

    for something like 'staylor(sin9x), x, 1, 2)', the Output I'd like to get would be 'sin(1)+cos(1)*(x-1)-(sin(1)*(x-1)^2)/2', however, I only manage to get  '(cos(1) (2x - 2) + sin(1) (-x² + 2x + 1)) / 2', i.e. there is still some simplification going on. Is there any way to turn this off, as well?

     
  • Rainer Schöpf

    Rainer Schöpf - 2011-08-24

    Yes, per default all expressions are fully expanded, ie. products of terms are multiplied out. You can switch this off with "off exp;". Try this:

    taylor(sin(x),x,1,2);
    off exp;
    taylortostandard ws;
    on div;
    ws;

      Rainer

     

Log in to post a comment.