1% Author: Alan Barnes <barnesa@aston.ac.uk> 2 3psexplim 8; 4 5 66 7 8% expand as far as 8th power (default is 6) 9 10cos!-series:=ps(cos x,x,0); 11 12 13 1 2 1 4 1 6 1 8 9 14cos-series := 1 - ---*x + ----*x - -----*x + -------*x + O(x ) 15 2 24 720 40320 16 17sin!-series:=ps(sin x,x,0); 18 19 20 1 3 1 5 1 7 9 21sin-series := x - ---*x + -----*x - ------*x + O(x ) 22 6 120 5040 23 24atan!-series:=ps(atan x,x,0); 25 26 27 1 3 1 5 1 7 9 28atan-series := x - ---*x + ---*x - ---*x + O(x ) 29 3 5 7 30 31tan!-series:=ps(tan x,x,0); 32 33 34 1 3 2 5 17 7 9 35tan-series := x + ---*x + ----*x + -----*x + O(x ) 36 3 15 315 37 38 39cos!-series*tan!-series; 40 41 42 1 3 1 5 1 7 9 43x - ---*x + -----*x - ------*x + O(x ) 44 6 120 5040 45 % should series for sin(x) 46df(cos!-series,x); 47 48 49 1 3 1 5 1 7 9 50 - x + ---*x - -----*x + ------*x + O(x ) 51 6 120 5040 52 % series for sin(x) again 53 54cos!-series/atan!-series; 55 56 57 -1 1 77 3 313 5 104539 7 9 58x - ---*x - -----*x + ------*x - ---------*x + O(x ) 59 6 360 3024 1814400 60 % should be expanded 61 62 63tmp:=ps(1/(1+x^2),x,infinity); 64 65 66 1 1 1 1 1 67tmp := ---- - ---- + ---- - ---- + O(----) 68 2 4 6 8 9 69 x x x x x 70 71df(tmp,x); 72 73 74 1 1 1 1 75 - 2*---- + 4*---- - 6*---- + O(----) 76 3 5 7 9 77 x x x x 78 79ps(df(1/(1+x^2),x),x,infinity); 80 81 82 1 1 1 1 83 - 2*---- + 4*---- - 6*---- + O(----) 84 3 5 7 9 85 x x x x 86 87 88tmp*x; 89 90 91 1 1 1 1 1 92(---- - ---- + ---- - ---- + O(----))*x 93 2 4 6 8 9 94 x x x x x 95 % not expanded as a single power series 96ps(tmp*x,x,infinity); 97 98 99 1 1 1 1 1 100--- - ---- + ---- - ---- + O(----) 101 x 3 5 7 9 102 x x x x 103 % now expanded 104 105ps(1/(a*x-b*x^2),x,a/b); 106 107 108 2 3 4 109 1 a -1 b b a b a 2 b a 3 110 - ---*(x - ---) + ---- - ----*(x - ---) + ----*(x - ---) - ----*(x - ---) 111 a b 2 3 b 4 b 5 b 112 a a a a 113 114 5 6 7 8 115 b a 4 b a 5 b a 6 b a 7 116 + ----*(x - ---) - ----*(x - ---) + ----*(x - ---) - ----*(x - ---) 117 6 b 7 b 8 b 9 b 118 a a a a 119 120 9 121 b a 8 a 9 122 + -----*(x - ---) + O((x - ---) ) 123 10 b b 124 a 125 % pole at expansion point 126 127ps(cos!-series*x,x,2); 128 129 130 2 1312*cos(2) + (cos(2) - 2*sin(2))*(x - 2) - (cos(2) + sin(2))*(x - 2) 132 133 - 3*cos(2) + 2*sin(2) 3 cos(2) + 2*sin(2) 4 134 + ------------------------*(x - 2) + -------------------*(x - 2) 135 6 12 136 137 5*cos(2) - 2*sin(2) 5 - cos(2) - 3*sin(2) 6 138 + ---------------------*(x - 2) + ----------------------*(x - 2) 139 120 360 140 141 - 7*cos(2) + 2*sin(2) 7 cos(2) + 4*sin(2) 8 142 + ------------------------*(x - 2) + -------------------*(x - 2) 143 5040 20160 144 145 9 146 + O((x - 2) ) 147 148 149tmp:=ps(x/atan!-series,x,0); 150 151 152 1 2 4 4 44 6 428 8 9 153tmp := 1 + ---*x - ----*x + -----*x - -------*x + O(x ) 154 3 45 945 14175 155 156tmp1:=ps(atan!-series/x,x,0); 157 158 159 1 2 1 4 1 6 1 8 9 160tmp1 := 1 - ---*x + ---*x - ---*x + ---*x + O(x ) 161 3 5 7 9 162 163tmp*tmp1; 164 165 1661 167 % should be 1, of course 168 169 170cos!-sin!-series:=ps(cos sin!-series,x,0); 171 172 173 1 2 5 4 37 6 457 8 9 174cos-sin-series := 1 - ---*x + ----*x - -----*x + -------*x + O(x ) 175 2 24 720 40320 176 177% cos(sin(x)) 178tmp:=cos!-sin!-series^2; 179 180 181 2 2 4 14 6 37 8 9 182tmp := 1 - x + ---*x - ----*x + -----*x + O(x ) 183 3 45 315 184 185tmp1:=ps((sin(sin!-series))^2,x,0); 186 187 188 2 2 4 14 6 37 8 9 189tmp1 := x - ---*x + ----*x - -----*x + O(x ) 190 3 45 315 191 192tmp+tmp1; 193 194 195 9 1961 + O(x ) 197 % sin^2 + cos^2 198psfunction tmp1; 199 200 201 2 202sin(sin(x)) 203 204% function represented by power series tmp1 205 206tmp:=tan!-series^2; 207 208 209 2 2 4 17 6 62 8 9 210tmp := x + ---*x + ----*x + -----*x + O(x ) 211 3 45 315 212 213psdepvar tmp; 214 215 216x 217 218% in case we have forgotten the dependent variable 219psexpansionpt tmp; 220 221 2220 223 % .... or the expansion point 224psterm(tmp,6); 225 226 227 17 228---- 229 45 230 % select 6th term 231psterm(tmp,10); 232 233 234 1382 235------- 236 14175 237 % select 10th term (series extended automtically) 238 239tmp1:=ps(1/(cos x)^2,x,0); 240 241 242 2 2 4 17 6 62 8 9 243tmp1 := 1 + x + ---*x + ----*x + -----*x + O(x ) 244 3 45 315 245 246tmp1-tmp; 247 248 249 9 2501 + O(x ) 251 % sec^2-tan^2 252 253ps(int(e^(x^2),x),x,0); 254 255 256 1 3 1 5 1 7 9 257x + ---*x + ----*x + ----*x + O(x ) 258 3 10 42 259 % integrator not called 260tmp:=ps(1/(y+x),x,0); 261 262 263 1 1 1 2 1 3 1 4 1 5 1 6 1 7 264tmp := --- - ----*x + ----*x - ----*x + ----*x - ----*x + ----*x - ----*x 265 y 2 3 4 5 6 7 8 266 y y y y y y y 267 268 1 8 9 269 + ----*x + O(x ) 270 9 271 y 272 273ps(int(tmp,y),x,0); 274 275 276 1 1 2 1 3 1 4 1 5 1 6 277log(y) + ---*x - ------*x + ------*x - ------*x + ------*x - ------*x 278 y 2 3 4 5 6 279 2*y 3*y 4*y 5*y 6*y 280 281 1 7 1 8 9 282 + ------*x - ------*x + O(x ) 283 7 8 284 7*y 8*y 285 % integrator called on each coefficient 286 287pscompose(cos!-series,sin!-series); 288 289 290 1 2 5 4 37 6 457 8 9 2911 - ---*x + ----*x - -----*x + -------*x + O(x ) 292 2 24 720 40320 293 294% power series composition cos(sin(x)) again 295cos!-sin!-series; 296 297 298 1 2 5 4 37 6 457 8 9 2991 - ---*x + ----*x - -----*x + -------*x + O(x ) 300 2 24 720 40320 301 302% should be same as previous result 303psfunction cos!-sin!-series; 304 305 306cos(sin(x)) 307 308 309tmp:=ps(log x,x,1); 310 311 312 1 2 1 3 1 4 1 5 313tmp := x - 1 - ---*(x - 1) + ---*(x - 1) - ---*(x - 1) + ---*(x - 1) 314 2 3 4 5 315 316 1 6 1 7 1 8 9 317 - ---*(x - 1) + ---*(x - 1) - ---*(x - 1) + O((x - 1) ) 318 6 7 8 319 320tmp1:=pscompose(tmp, cos!-series); 321 322 323 1 2 1 4 1 6 17 8 9 324tmp1 := - ---*x - ----*x - ----*x - ------*x + O(x ) 325 2 12 45 2520 326 327% power series composition of log(cos(x)) 328df(tmp1,x); 329 330 331 1 3 2 5 17 7 9 332 - x - ---*x - ----*x - -----*x + O(x ) 333 3 15 315 334 % series for -tan x 335 336psreverse tan!-series; 337 338 339 1 3 1 5 1 7 9 340x - ---*x + ---*x - ---*x + O(x ) 341 3 5 7 342 343% should be series for atan x 344atan!-series; 345 346 347 1 3 1 5 1 7 9 348x - ---*x + ---*x - ---*x + O(x ) 349 3 5 7 350 351tmp:=ps(e^x,x,0); 352 353 354 1 2 1 3 1 4 1 5 1 6 1 7 355tmp := 1 + x + ---*x + ---*x + ----*x + -----*x + -----*x + ------*x 356 2 6 24 120 720 5040 357 358 1 8 9 359 + -------*x + O(x ) 360 40320 361 362psreverse tmp; 363 364 365 1 2 1 3 1 4 1 5 1 6 366x - 1 - ---*(x - 1) + ---*(x - 1) - ---*(x - 1) + ---*(x - 1) - ---*(x - 1) 367 2 3 4 5 6 368 369 1 7 1 8 9 370 + ---*(x - 1) - ---*(x - 1) + O((x - 1) ) 371 7 8 372 373% NB expansion of log x in powers of (x-1) 374 375pschangevar(tan!-series,y); 376 377 378 1 3 2 5 17 7 9 379y + ---*y + ----*y + -----*y + O(y ) 380 3 15 315 381 382 383end; 384 385Tested on x86_64-pc-windows CSL 386Time (counter 1): 16 ms 387 388End of Lisp run after 0.01+0.04 seconds 389real 0.20 390user 0.01 391sys 0.07 392