/usr/share/axiom-20170501/src/algebra/ISUPS.spad is in axiom-source 20170501-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 | )abbrev domain ISUPS InnerSparseUnivariatePowerSeries
++ Author: Clifton J. Williamson
++ Date Created: 28 October 1994
++ Date Last Updated: 9 March 1995
++ Description:
++ InnerSparseUnivariatePowerSeries is an internal domain
++ used for creating sparse Taylor and Laurent series.
InnerSparseUnivariatePowerSeries(Coef) : SIG == CODE where
Coef : Ring
B ==> Boolean
COM ==> OrderedCompletion Integer
I ==> Integer
L ==> List
NNI ==> NonNegativeInteger
OUT ==> OutputForm
PI ==> PositiveInteger
REF ==> Reference OrderedCompletion Integer
RN ==> Fraction Integer
Term ==> Record(k:Integer,c:Coef)
SG ==> String
ST ==> Stream Term
SIG ==> UnivariatePowerSeriesCategory(Coef,Integer) with
makeSeries: (REF,ST) -> %
++ makeSeries(refer,str) creates a power series from the reference
++ \spad{refer} and the stream \spad{str}.
getRef: % -> REF
++ getRef(f) returns a reference containing the order to which the
++ terms of f have been computed.
getStream: % -> ST
++ getStream(f) returns the stream of terms representing the series f.
series: ST -> %
++ series(st) creates a series from a stream of non-zero terms,
++ where a term is an exponent-coefficient pair. The terms in the
++ stream should be ordered by increasing order of exponents.
monomial?: % -> B
++ monomial?(f) tests if f is a single monomial.
multiplyCoefficients: (I -> Coef,%) -> %
++ multiplyCoefficients(fn,f) returns the series
++ \spad{sum(fn(n) * an * x^n,n = n0..)},
++ where f is the series \spad{sum(an * x^n,n = n0..)}.
iExquo: (%,%,B) -> Union(%,"failed")
++ iExquo(f,g,taylor?) is the quotient of the power series f and g.
++ If \spad{taylor?} is \spad{true}, then we must have
++ \spad{order(f) >= order(g)}.
taylorQuoByVar: % -> %
++ taylorQuoByVar(a0 + a1 x + a2 x**2 + ...)
++ returns \spad{a1 + a2 x + a3 x**2 + ...}
iCompose: (%,%) -> %
++ iCompose(f,g) returns \spad{f(g(x))}. This is an internal function
++ which should only be called for Taylor series \spad{f(x)} and
++ \spad{g(x)} such that the constant coefficient of \spad{g(x)} is zero.
seriesToOutputForm: (ST,REF,Symbol,Coef,RN) -> OutputForm
++ seriesToOutputForm(st,refer,var,cen,r) prints the series
++ \spad{f((var - cen)^r)}.
if Coef has Algebra Fraction Integer then
integrate : % -> %
++ integrate(f(x)) returns an anti-derivative of the power series
++ \spad{f(x)} with constant coefficient 0.
++ Warning: function does not check for a term of degree -1.
cPower : (%,Coef) -> %
++ cPower(f,r) computes \spad{f^r}, where f has constant coefficient 1.
++ For use when the coefficient ring is commutative.
cRationalPower : (%,RN) -> %
++ cRationalPower(f,r) computes \spad{f^r}.
++ For use when the coefficient ring is commutative.
cExp : % -> %
++ cExp(f) computes the exponential of the power series f.
++ For use when the coefficient ring is commutative.
cLog : % -> %
++ cLog(f) computes the logarithm of the power series f.
++ For use when the coefficient ring is commutative.
cSin : % -> %
++ cSin(f) computes the sine of the power series f.
++ For use when the coefficient ring is commutative.
cCos : % -> %
++ cCos(f) computes the cosine of the power series f.
++ For use when the coefficient ring is commutative.
cTan : % -> %
++ cTan(f) computes the tangent of the power series f.
++ For use when the coefficient ring is commutative.
cCot : % -> %
++ cCot(f) computes the cotangent of the power series f.
++ For use when the coefficient ring is commutative.
cSec : % -> %
++ cSec(f) computes the secant of the power series f.
++ For use when the coefficient ring is commutative.
cCsc : % -> %
++ cCsc(f) computes the cosecant of the power series f.
++ For use when the coefficient ring is commutative.
cAsin : % -> %
++ cAsin(f) computes the arcsine of the power series f.
++ For use when the coefficient ring is commutative.
cAcos : % -> %
++ cAcos(f) computes the arccosine of the power series f.
++ For use when the coefficient ring is commutative.
cAtan : % -> %
++ cAtan(f) computes the arctangent of the power series f.
++ For use when the coefficient ring is commutative.
cAcot : % -> %
++ cAcot(f) computes the arccotangent of the power series f.
++ For use when the coefficient ring is commutative.
cAsec : % -> %
++ cAsec(f) computes the arcsecant of the power series f.
++ For use when the coefficient ring is commutative.
cAcsc : % -> %
++ cAcsc(f) computes the arccosecant of the power series f.
++ For use when the coefficient ring is commutative.
cSinh : % -> %
++ cSinh(f) computes the hyperbolic sine of the power series f.
++ For use when the coefficient ring is commutative.
cCosh : % -> %
++ cCosh(f) computes the hyperbolic cosine of the power series f.
++ For use when the coefficient ring is commutative.
cTanh : % -> %
++ cTanh(f) computes the hyperbolic tangent of the power series f.
++ For use when the coefficient ring is commutative.
cCoth : % -> %
++ cCoth(f) computes the hyperbolic cotangent of the power series f.
++ For use when the coefficient ring is commutative.
cSech : % -> %
++ cSech(f) computes the hyperbolic secant of the power series f.
++ For use when the coefficient ring is commutative.
cCsch : % -> %
++ cCsch(f) computes the hyperbolic cosecant of the power series f.
++ For use when the coefficient ring is commutative.
cAsinh : % -> %
++ cAsinh(f) computes the inverse hyperbolic sine of the power
++ series f. For use when the coefficient ring is commutative.
cAcosh : % -> %
++ cAcosh(f) computes the inverse hyperbolic cosine of the power
++ series f. For use when the coefficient ring is commutative.
cAtanh : % -> %
++ cAtanh(f) computes the inverse hyperbolic tangent of the power
++ series f. For use when the coefficient ring is commutative.
cAcoth : % -> %
++ cAcoth(f) computes the inverse hyperbolic cotangent of the power
++ series f. For use when the coefficient ring is commutative.
cAsech : % -> %
++ cAsech(f) computes the inverse hyperbolic secant of the power
++ series f. For use when the coefficient ring is commutative.
cAcsch : % -> %
++ cAcsch(f) computes the inverse hyperbolic cosecant of the power
++ series f. For use when the coefficient ring is commutative.
CODE ==> add
import REF
Rep := Record(%ord: REF,%str: Stream Term)
-- when the value of 'ord' is n, this indicates that all non-zero
-- terms of order up to and including n have been computed;
-- when 'ord' is plusInfinity, all terms have been computed;
-- lazy evaluation of 'str' has the side-effect of modifying the value
-- of 'ord'
--% Local functions
makeTerm: (Integer,Coef) -> Term
getCoef: Term -> Coef
getExpon: Term -> Integer
iSeries: (ST,REF) -> ST
iExtend: (ST,COM,REF) -> ST
iTruncate0: (ST,REF,REF,COM,I,I) -> ST
iTruncate: (%,COM,I) -> %
iCoefficient: (ST,Integer) -> Coef
iOrder: (ST,COM,REF) -> I
iMap1: ((Coef,I) -> Coef,I -> I,B,ST,REF,REF,Integer) -> ST
iMap2: ((Coef,I) -> Coef,I -> I,B,%) -> %
iPlus1: ((Coef,Coef) -> Coef,ST,REF,ST,REF,REF,I) -> ST
iPlus2: ((Coef,Coef) -> Coef,%,%) -> %
productByTerm: (Coef,I,ST,REF,REF,I) -> ST
productLazyEval: (ST,REF,ST,REF,COM) -> Void
iTimes: (ST,REF,ST,REF,REF,I) -> ST
iDivide: (ST,REF,ST,REF,Coef,I,REF,I) -> ST
divide: (%,I,%,I,Coef) -> %
compose0: (ST,REF,ST,REF,I,%,%,I,REF,I) -> ST
factorials?: () -> Boolean
termOutput: (RN,Coef,OUT) -> OUT
showAll?: () -> Boolean
--% macros
makeTerm(exp,coef) == [exp,coef]
getCoef term == term.c
getExpon term == term.k
makeSeries(refer,x) == [refer,x]
getRef ups == ups.%ord
getStream ups == ups.%str
--% creation and destruction of series
monomial(coef,expon) ==
nix : ST := empty()
st :=
zero? coef => nix
concat(makeTerm(expon,coef),nix)
makeSeries(ref plusInfinity(),st)
monomial? ups == (not empty? getStream ups) and (empty? rst getStream ups)
coerce(n:I) == n :: Coef :: %
coerce(r:Coef) == monomial(r,0)
iSeries(x,refer) ==
empty? x => (setelt(refer,plusInfinity()); empty())
setelt(refer,(getExpon frst x) :: COM)
concat(frst x,iSeries(rst x,refer))
series(x:ST) ==
empty? x => 0
n := getExpon frst x; refer := ref(n :: COM)
makeSeries(refer,iSeries(x,refer))
--% values
characteristic() == characteristic()$Coef
0 == monomial(0,0)
1 == monomial(1,0)
iExtend(st,n,refer) ==
(elt refer) < n =>
explicitlyEmpty? st => (setelt(refer,plusInfinity()); st)
explicitEntries? st => iExtend(rst st,n,refer)
iExtend(lazyEvaluate st,n,refer)
st
extend(x,n) == (iExtend(getStream x,n :: COM,getRef x); x)
complete x == (iExtend(getStream x,plusInfinity(),getRef x); x)
iTruncate0(x,xRefer,refer,minExp,maxExp,n) == delay
explicitlyEmpty? x => (setelt(refer,plusInfinity()); empty())
nn := n :: COM
while (elt xRefer) < nn repeat lazyEvaluate x
explicitEntries? x =>
(nx := getExpon(xTerm := frst x)) > maxExp =>
(setelt(refer,plusInfinity()); empty())
setelt(refer,nx :: COM)
(nx :: COM) >= minExp =>
concat(makeTerm(nx,getCoef xTerm),_
iTruncate0(rst x,xRefer,refer,minExp,maxExp,nx + 1))
iTruncate0(rst x,xRefer,refer,minExp,maxExp,nx + 1)
-- can't have elt(xRefer) = infty unless all terms have been computed
degr := retract(elt xRefer)@I
setelt(refer,degr :: COM)
iTruncate0(x,xRefer,refer,minExp,maxExp,degr + 1)
iTruncate(ups,minExp,maxExp) ==
x := getStream ups; xRefer := getRef ups
explicitlyEmpty? x => 0
explicitEntries? x =>
deg := getExpon frst x
refer := ref((deg - 1) :: COM)
makeSeries(refer,iTruncate0(x,xRefer,refer,minExp,maxExp,deg))
-- can't have elt(xRefer) = infty unless all terms have been computed
degr := retract(elt xRefer)@I
refer := ref(degr :: COM)
makeSeries(refer,iTruncate0(x,xRefer,refer,minExp,maxExp,degr + 1))
truncate(ups,n) == iTruncate(ups,minusInfinity(),n)
truncate(ups,n1,n2) ==
if n1 > n2 then (n1,n2) := (n2,n1)
iTruncate(ups,n1 :: COM,n2)
iCoefficient(st,n) ==
explicitEntries? st =>
term := frst st
(expon := getExpon term) > n => 0
expon = n => getCoef term
iCoefficient(rst st,n)
0
coefficient(x,n) == (extend(x,n); iCoefficient(getStream x,n))
elt(x:%,n:Integer) == coefficient(x,n)
iOrder(st,n,refer) ==
explicitlyEmpty? st =>
finite?(n) => retract(n)@Integer
error "order: series has infinite order"
explicitEntries? st =>
((r := getExpon frst st) :: COM) >= n => retract(n)@Integer
r
-- can't have elt(xRefer) = infty unless all terms have been computed
degr := retract(elt refer)@I
(degr :: COM) >= n => retract(n)@Integer
iOrder(lazyEvaluate st,n,refer)
order x == iOrder(getStream x,plusInfinity(),getRef x)
order(x,n) == iOrder(getStream x,n :: COM,getRef x)
terms x == getStream x
--% predicates
zero? ups ==
x := getStream ups; ref := getRef ups
whatInfinity(n := elt ref) = 1 => explicitlyEmpty? x
count : NNI := _$streamCount$Lisp
for i in 1..count repeat
explicitlyEmpty? x => return true
explicitEntries? x => return false
lazyEvaluate x
false
ups1 = ups2 == zero?(ups1 - ups2)
--% arithmetic
iMap1(cFcn,eFcn,check?,x,xRefer,refer,n) == delay
-- when this function is called, all terms in 'x' of order < n have been
-- computed and we compute the eFcn(n)th order coefficient of the result
explicitlyEmpty? x => (setelt(refer,plusInfinity()); empty())
-- if terms in 'x' up to order n have not been computed,
-- apply lazy evaluation
nn := n :: COM
while (elt xRefer) < nn repeat lazyEvaluate x
-- 'x' may now be empty: retest
explicitlyEmpty? x => (setelt(refer,plusInfinity()); empty())
-- must have nx >= n
explicitEntries? x =>
xCoef := getCoef(xTerm := frst x); nx := getExpon xTerm
newCoef := cFcn(xCoef,nx); m := eFcn nx
setelt(refer,m :: COM)
not check? =>
concat(makeTerm(m,newCoef),_
iMap1(cFcn,eFcn,check?,rst x,xRefer,refer,nx + 1))
zero? newCoef => iMap1(cFcn,eFcn,check?,rst x,xRefer,refer,nx + 1)
concat(makeTerm(m,newCoef),_
iMap1(cFcn,eFcn,check?,rst x,xRefer,refer,nx + 1))
-- can't have elt(xRefer) = infty unless all terms have been computed
degr := retract(elt xRefer)@I
setelt(refer,eFcn(degr) :: COM)
iMap1(cFcn,eFcn,check?,x,xRefer,refer,degr + 1)
iMap2(cFcn,eFcn,check?,ups) ==
-- 'eFcn' must be a strictly increasing function,
-- i < j => eFcn(i) < eFcn(j)
xRefer := getRef ups; x := getStream ups
explicitlyEmpty? x => 0
explicitEntries? x =>
deg := getExpon frst x
refer := ref(eFcn(deg - 1) :: COM)
makeSeries(refer,iMap1(cFcn,eFcn,check?,x,xRefer,refer,deg))
-- can't have elt(xRefer) = infty unless all terms have been computed
degr := retract(elt xRefer)@I
refer := ref(eFcn(degr) :: COM)
makeSeries(refer,iMap1(cFcn,eFcn,check?,x,xRefer,refer,degr + 1))
map(fcn,x) == iMap2((y,n) +-> fcn(y), z +->z, true, x)
differentiate x == iMap2((y,n) +-> n*y, z +-> z - 1, true, x)
multiplyCoefficients(f,x) == iMap2((y,n) +-> f(n)*y, z +-> z, true, x)
multiplyExponents(x,n) == iMap2((y,m) +-> y, z +-> n*z, false, x)
iPlus1(op,x,xRefer,y,yRefer,refer,n) == delay
-- when this function is called, all terms in 'x' and 'y' of order < n
-- have been computed and we are computing the nth order coefficient of
-- the result; note the 'op' is either '+' or '-'
explicitlyEmpty? x =>
iMap1((x1,m) +-> op(0,x1), z +-> z, false, y, yRefer, refer, n)
explicitlyEmpty? y =>
iMap1((x1,m) +-> op(x1,0), z +-> z, false, x, xRefer, refer, n)
-- if terms up to order n have not been computed,
-- apply lazy evaluation
nn := n :: COM
while (elt xRefer) < nn repeat lazyEvaluate x
while (elt yRefer) < nn repeat lazyEvaluate y
-- 'x' or 'y' may now be empty: retest
explicitlyEmpty? x =>
iMap1((x1,m) +-> op(0,x1), z +-> z, false, y, yRefer, refer, n)
explicitlyEmpty? y =>
iMap1((x1,m) +-> op(x1,0), z +-> z, false, x, xRefer, refer, n)
-- must have nx >= n, ny >= n
-- both x and y have explicit terms
explicitEntries?(x) and explicitEntries?(y) =>
xCoef := getCoef(xTerm := frst x); nx := getExpon xTerm
yCoef := getCoef(yTerm := frst y); ny := getExpon yTerm
nx = ny =>
setelt(refer,nx :: COM)
zero? (coef := op(xCoef,yCoef)) =>
iPlus1(op,rst x,xRefer,rst y,yRefer,refer,nx + 1)
concat(makeTerm(nx,coef),_
iPlus1(op,rst x,xRefer,rst y,yRefer,refer,nx + 1))
nx < ny =>
setelt(refer,nx :: COM)
concat(makeTerm(nx,op(xCoef,0)),_
iPlus1(op,rst x,xRefer,y,yRefer,refer,nx + 1))
setelt(refer,ny :: COM)
concat(makeTerm(ny,op(0,yCoef)),_
iPlus1(op,x,xRefer,rst y,yRefer,refer,ny + 1))
-- y has no term of degree n
explicitEntries? x =>
xCoef := getCoef(xTerm := frst x); nx := getExpon xTerm
-- can't have elt(yRefer) = infty unless all terms have been computed
(degr := retract(elt yRefer)@I) < nx =>
setelt(refer,elt yRefer)
iPlus1(op,x,xRefer,y,yRefer,refer,degr + 1)
setelt(refer,nx :: COM)
concat(makeTerm(nx,op(xCoef,0)),_
iPlus1(op,rst x,xRefer,y,yRefer,refer,nx + 1))
-- x has no term of degree n
explicitEntries? y =>
yCoef := getCoef(yTerm := frst y); ny := getExpon yTerm
-- can't have elt(xRefer) = infty unless all terms have been computed
(degr := retract(elt xRefer)@I) < ny =>
setelt(refer,elt xRefer)
iPlus1(op,x,xRefer,y,yRefer,refer,degr + 1)
setelt(refer,ny :: COM)
concat(makeTerm(ny,op(0,yCoef)),_
iPlus1(op,x,xRefer,rst y,yRefer,refer,ny + 1))
-- neither x nor y has a term of degree n
setelt(refer,xyRef := min(elt xRefer,elt yRefer))
-- can't have xyRef = infty unless all terms have been computed
iPlus1(op,x,xRefer,y,yRefer,refer,retract(xyRef)@I + 1)
iPlus2(op,ups1,ups2) ==
xRefer := getRef ups1; x := getStream ups1
xDeg :=
explicitlyEmpty? x => return map(z +-> op(0$Coef,z),ups2)
explicitEntries? x => (getExpon frst x) - 1
-- can't have elt(xRefer) = infty unless all terms have been computed
retract(elt xRefer)@I
yRefer := getRef ups2; y := getStream ups2
yDeg :=
explicitlyEmpty? y => return map(z +-> op(z,0$Coef),ups1)
explicitEntries? y => (getExpon frst y) - 1
-- can't have elt(yRefer) = infty unless all terms have been computed
retract(elt yRefer)@I
deg := min(xDeg,yDeg); refer := ref(deg :: COM)
makeSeries(refer,iPlus1(op,x,xRefer,y,yRefer,refer,deg + 1))
x + y == iPlus2((xi,yi) +-> xi + yi, x, y)
x - y == iPlus2((xi,yi) +-> xi - yi, x, y)
- y == iMap2((x,n) +-> -x, z +-> z, false, y)
-- gives correct defaults for I, NNI and PI
n:I * x:% == (zero? n => 0; map(z +-> n*z, x))
n:NNI * x:% == (zero? n => 0; map(z +-> n*z, x))
n:PI * x:% == (zero? n => 0; map(z +-> n*z, x))
productByTerm(coef,expon,x,xRefer,refer,n) ==
iMap1((y,m) +-> coef*y, z +-> z+expon, true, x, xRefer, refer, n)
productLazyEval(x,xRefer,y,yRefer,nn) ==
explicitlyEmpty?(x) or explicitlyEmpty?(y) => void()
explicitEntries? x =>
explicitEntries? y => void()
xDeg := (getExpon frst x) :: COM
while (xDeg + elt(yRefer)) < nn repeat lazyEvaluate y
void()
explicitEntries? y =>
yDeg := (getExpon frst y) :: COM
while (yDeg + elt(xRefer)) < nn repeat lazyEvaluate x
void()
lazyEvaluate x
-- if x = y, then y may now have explicit entries
if lazy? y then lazyEvaluate y
productLazyEval(x,xRefer,y,yRefer,nn)
iTimes(x,xRefer,y,yRefer,refer,n) == delay
-- when this function is called, we are computing the nth order
-- coefficient of the product
productLazyEval(x,xRefer,y,yRefer,n :: COM)
explicitlyEmpty?(x) or explicitlyEmpty?(y) =>
(setelt(refer,plusInfinity()); empty())
-- must have nx + ny >= n
explicitEntries?(x) and explicitEntries?(y) =>
xCoef := getCoef(xTerm := frst x); xExpon := getExpon xTerm
yCoef := getCoef(yTerm := frst y); yExpon := getExpon yTerm
expon := xExpon + yExpon
setelt(refer,expon :: COM)
scRefer := ref(expon :: COM)
scMult := productByTerm(xCoef,xExpon,rst y,yRefer,scRefer,yExpon + 1)
prRefer := ref(expon :: COM)
pr := iTimes(rst x,xRefer,y,yRefer,prRefer,expon + 1)
sm := iPlus1((a,b) +-> a+b,scMult,scRefer,pr,prRefer,refer,expon + 1)
zero?(coef := xCoef * yCoef) => sm
concat(makeTerm(expon,coef),sm)
explicitEntries? x =>
xExpon := getExpon frst x
-- can't have elt(yRefer) = infty unless all terms have been computed
degr := retract(elt yRefer)@I
setelt(refer,(xExpon + degr) :: COM)
iTimes(x,xRefer,y,yRefer,refer,xExpon + degr + 1)
explicitEntries? y =>
yExpon := getExpon frst y
-- can't have elt(xRefer) = infty unless all terms have been computed
degr := retract(elt xRefer)@I
setelt(refer,(yExpon + degr) :: COM)
iTimes(x,xRefer,y,yRefer,refer,yExpon + degr + 1)
-- can't have elt(xRefer) = infty unless all terms have been computed
xDegr := retract(elt xRefer)@I
yDegr := retract(elt yRefer)@I
setelt(refer,(xDegr + yDegr) :: COM)
iTimes(x,xRefer,y,yRefer,refer,xDegr + yDegr + 1)
ups1:% * ups2:% ==
xRefer := getRef ups1; x := getStream ups1
xDeg :=
explicitlyEmpty? x => return 0
explicitEntries? x => (getExpon frst x) - 1
-- can't have elt(xRefer) = infty unless all terms have been computed
retract(elt xRefer)@I
yRefer := getRef ups2; y := getStream ups2
yDeg :=
explicitlyEmpty? y => return 0
explicitEntries? y => (getExpon frst y) - 1
-- can't have elt(yRefer) = infty unless all terms have been computed
retract(elt yRefer)@I
deg := xDeg + yDeg + 1; refer := ref(deg :: COM)
makeSeries(refer,iTimes(x,xRefer,y,yRefer,refer,deg + 1))
iDivide(x,xRefer,y,yRefer,rym,m,refer,n) == delay
-- when this function is called, we are computing the nth order
-- coefficient of the result
explicitlyEmpty? x => (setelt(refer,plusInfinity()); empty())
-- if terms up to order n - m have not been computed,
-- apply lazy evaluation
nm := (n + m) :: COM
while (elt xRefer) < nm repeat lazyEvaluate x
-- 'x' may now be empty: retest
explicitlyEmpty? x => (setelt(refer,plusInfinity()); empty())
-- must have nx >= n + m
explicitEntries? x =>
newCoef := getCoef(xTerm := frst x) * rym; nx := getExpon xTerm
prodRefer := ref(nx :: COM)
prod := productByTerm(-newCoef,nx - m,rst y,yRefer,prodRefer,1)
sumRefer := ref(nx :: COM)
sum := iPlus1((a,b)+->a+b,rst x,xRefer,prod,prodRefer,sumRefer,nx + 1)
setelt(refer,(nx - m) :: COM); term := makeTerm(nx - m,newCoef)
concat(term,iDivide(sum,sumRefer,y,yRefer,rym,m,refer,nx - m + 1))
-- can't have elt(xRefer) = infty unless all terms have been computed
degr := retract(elt xRefer)@I
setelt(refer,(degr - m) :: COM)
iDivide(x,xRefer,y,yRefer,rym,m,refer,degr - m + 1)
divide(ups1,deg1,ups2,deg2,r) ==
xRefer := getRef ups1; x := getStream ups1
yRefer := getRef ups2; y := getStream ups2
refer := ref((deg1 - deg2) :: COM)
makeSeries(refer,iDivide(x,xRefer,y,yRefer,r,deg2,refer,deg1 - deg2 + 1))
iExquo(ups1,ups2,taylor?) ==
xRefer := getRef ups1; x := getStream ups1
yRefer := getRef ups2; y := getStream ups2
n : I := 0
-- try to find first non-zero term in y
-- give up after 1000 lazy evaluations
while not explicitEntries? y repeat
explicitlyEmpty? y => return "failed"
lazyEvaluate y
(n := n + 1) > 1000 => return "failed"
yCoef := getCoef(yTerm := frst y); ny := getExpon yTerm
(ry := recip yCoef) case "failed" => "failed"
nn := ny :: COM
if taylor? then
while (elt(xRefer) < nn) repeat
explicitlyEmpty? x => return 0
explicitEntries? x => return "failed"
lazyEvaluate x
-- check if ups2 is a monomial
empty? rst y => iMap2((y1,m) +-> y1*(ry::Coef),z +->z-ny, false, ups1)
explicitlyEmpty? x => 0
nx :=
explicitEntries? x =>
((deg := getExpon frst x) < ny) and taylor? => return "failed"
deg - 1
-- can't have elt(xRefer) = infty unless all terms have been computed
retract(elt xRefer)@I
divide(ups1,nx,ups2,ny,ry :: Coef)
taylorQuoByVar ups ==
iMap2((y,n) +-> y, z +-> z-1,false,ups - monomial(coefficient(ups,0),0))
compose0(x,xRefer,y,yRefer,yOrd,y1,yn0,n0,refer,n) == delay
-- when this function is called, we are computing the nth order
-- coefficient of the composite
explicitlyEmpty? x => (setelt(refer,plusInfinity()); empty())
-- if terms in 'x' up to order n have not been computed,
-- apply lazy evaluation
nn := n :: COM; yyOrd := yOrd :: COM
while (yyOrd * elt(xRefer)) < nn repeat lazyEvaluate x
explicitEntries? x =>
xCoef := getCoef(xTerm := frst x); n1 := getExpon xTerm
zero? n1 =>
setelt(refer,n1 :: COM)
concat(makeTerm(n1,xCoef),_
compose0(rst x,xRefer,y,yRefer,yOrd,y1,yn0,n0,refer,n1 + 1))
yn1 := yn0 * y1 ** ((n1 - n0) :: NNI)
z := getStream yn1; zRefer := getRef yn1
degr := yOrd * n1; prodRefer := ref((degr - 1) :: COM)
prod := iMap1((s,k)+->xCoef*s,m+->m,true,z,zRefer,prodRefer,degr)
coRefer := ref((degr + yOrd - 1) :: COM)
co := compose0(rst x,xRefer,y,yRefer,yOrd,y1,yn1,n1,coRefer,degr+yOrd)
setelt(refer,(degr - 1) :: COM)
iPlus1((a,b)+->a+b,prod,prodRefer,co,coRefer,refer,degr)
-- can't have elt(xRefer) = infty unless all terms have been computed
degr := yOrd * (retract(elt xRefer)@I + 1)
setelt(refer,(degr - 1) :: COM)
compose0(x,xRefer,y,yRefer,yOrd,y1,yn0,n0,refer,degr)
iCompose(ups1,ups2) ==
x := getStream ups1; xRefer := getRef ups1
y := getStream ups2; yRefer := getRef ups2
-- try to compute the order of 'ups2'
n : I := _$streamCount$Lisp
for i in 1..n while not explicitEntries? y repeat
explicitlyEmpty? y => coefficient(ups1,0) :: %
lazyEvaluate y
explicitlyEmpty? y => coefficient(ups1,0) :: %
yOrd : I :=
explicitEntries? y => getExpon frst y
retract(elt yRefer)@I
compRefer := ref((-1) :: COM)
makeSeries(compRefer,_
compose0(x,xRefer,y,yRefer,yOrd,ups2,1,0,compRefer,0))
if Coef has Algebra Fraction Integer then
integrate x == iMap2((y,n) +-> 1/(n+1)*y, z +-> z+1, true, x)
--% Fixed point computations
Ys ==> Y$ParadoxicalCombinatorsForStreams(Term)
integ0: (ST,REF,REF,I) -> ST
integ0(x,intRef,ansRef,n) == delay
nLess1 := (n - 1) :: COM
while (elt intRef) < nLess1 repeat lazyEvaluate x
explicitlyEmpty? x => (setelt(ansRef,plusInfinity()); empty())
explicitEntries? x =>
xCoef := getCoef(xTerm := frst x); nx := getExpon xTerm
setelt(ansRef,(n1 := (nx + 1)) :: COM)
concat(makeTerm(n1,inv(n1 :: RN) * xCoef),_
integ0(rst x,intRef,ansRef,n1))
-- can't have elt(intRef) = infty unless all terms have been computed
degr := retract(elt intRef)@I; setelt(ansRef,(degr + 1) :: COM)
integ0(x,intRef,ansRef,degr + 2)
integ1: (ST,REF,REF) -> ST
integ1(x,intRef,ansRef) == integ0(x,intRef,ansRef,1)
lazyInteg: (Coef,() -> ST,REF,REF) -> ST
lazyInteg(a,xf,intRef,ansRef) ==
ansStr : ST := integ1(delay xf,intRef,ansRef)
concat(makeTerm(0,a),ansStr)
cPower(f,r) ==
-- computes f^r. f should have constant coefficient 1.
fp := differentiate f
fInv := iExquo(1,f,false) :: %; y := r * fp * fInv
yRef := getRef y; yStr := getStream y
intRef := ref((-1) :: COM); ansRef := ref(0 :: COM)
ansStr :=
Ys(s+->lazyInteg(1,iTimes(s,ansRef,yStr,yRef,intRef,0),intRef,ansRef))
makeSeries(ansRef,ansStr)
iExp: (%,Coef) -> %
iExp(f,cc) ==
-- computes exp(f). cc = exp coefficient(f,0)
fp := differentiate f
fpRef := getRef fp; fpStr := getStream fp
intRef := ref((-1) :: COM); ansRef := ref(0 :: COM)
ansStr :=
Ys(s+->lazyInteg(cc,
iTimes(s,ansRef,fpStr,fpRef,intRef,0),intRef,ansRef))
makeSeries(ansRef,ansStr)
sincos0: (Coef,Coef,L ST,REF,REF,ST,REF,ST,REF) -> L ST
sincos0(sinc,cosc,list,sinRef,cosRef,fpStr,fpRef,fpStr2,fpRef2) ==
sinStr := first list; cosStr := second list
prodRef1 := ref((-1) :: COM); prodRef2 := ref((-1) :: COM)
prodStr1 := iTimes(cosStr,cosRef,fpStr,fpRef,prodRef1,0)
prodStr2 := iTimes(sinStr,sinRef,fpStr2,fpRef2,prodRef2,0)
[lazyInteg(sinc,prodStr1,prodRef1,sinRef),_
lazyInteg(cosc,prodStr2,prodRef2,cosRef)]
iSincos: (%,Coef,Coef,I) -> Record(%sin: %, %cos: %)
iSincos(f,sinc,cosc,sign) ==
fp := differentiate f
fpRef := getRef fp; fpStr := getStream fp
fp2 := ((sign = 1) => fp; -fp)
fpRef2 := getRef fp2; fpStr2 := getStream fp2
sinRef := ref(0 :: COM); cosRef := ref(0 :: COM)
sincos :=
Ys(s+->sincos0(sinc,cosc,s,sinRef,cosRef,fpStr,fpRef,fpStr2,fpRef2),2)
sinStr := (zero? sinc => rst first sincos; first sincos)
cosStr := (zero? cosc => rst second sincos; second sincos)
[makeSeries(sinRef,sinStr),makeSeries(cosRef,cosStr)]
tan0: (Coef,ST,REF,ST,REF,I) -> ST
tan0(cc,ansStr,ansRef,fpStr,fpRef,sign) ==
sqRef := ref((-1) :: COM)
sqStr := iTimes(ansStr,ansRef,ansStr,ansRef,sqRef,0)
one : % := 1; oneStr := getStream one; oneRef := getRef one
yRef := ref((-1) :: COM)
yStr : ST :=
(sign = 1) => iPlus1((a,b)+->a+b,oneStr,oneRef,sqStr,sqRef,yRef,0)
iPlus1((a,b)+->a-b,oneStr,oneRef,sqStr,sqRef,yRef,0)
intRef := ref((-1) :: COM)
lazyInteg(cc,iTimes(yStr,yRef,fpStr,fpRef,intRef,0),intRef,ansRef)
iTan: (%,%,Coef,I) -> %
iTan(f,fp,cc,sign) ==
-- computes the tangent (and related functions) of f.
fpRef := getRef fp; fpStr := getStream fp
ansRef := ref(0 :: COM)
ansStr := Ys(s+->tan0(cc,s,ansRef,fpStr,fpRef,sign))
zero? cc => makeSeries(ansRef,rst ansStr)
makeSeries(ansRef,ansStr)
--% Error Reporting
TRCONST : SG := "series expansion involves transcendental constants"
NPOWERS : SG := "series expansion has terms of negative degree"
FPOWERS : SG := "series expansion has terms of fractional degree"
MAYFPOW : SG := "series expansion may have terms of fractional degree"
LOGS : SG := "series expansion has logarithmic term"
NPOWLOG : SG :=
"series expansion has terms of negative degree or logarithmic term"
NOTINV : SG := "leading coefficient not invertible"
--% Rational powers and transcendental functions
orderOrFailed : % -> Union(I,"failed")
orderOrFailed uts ==
-- returns the order of x or "failed"
-- if -1 is returned, the series is identically zero
x := getStream uts
for n in 0..1000 repeat
explicitlyEmpty? x => return -1
explicitEntries? x => return getExpon frst x
lazyEvaluate x
"failed"
RATPOWERS : Boolean := Coef has "**": (Coef,RN) -> Coef
TRANSFCN : Boolean := Coef has TranscendentalFunctionCategory
cRationalPower(uts,r) ==
(ord0 := orderOrFailed uts) case "failed" =>
error "**: series with many leading zero coefficients"
order := ord0 :: I
(n := order exquo denom(r)) case "failed" =>
error "**: rational power does not exist"
cc := coefficient(uts,order)
(ccInv := recip cc) case "failed" => error concat("**: ",NOTINV)
ccPow :=
(cc = 1) => cc
(denom r) = 1 =>
not negative?(num := numer r) => cc ** (num :: NNI)
(ccInv :: Coef) ** ((-num) :: NNI)
RATPOWERS => cc ** r
error "** rational power of coefficient undefined"
uts1 := (ccInv :: Coef) * uts
uts2 := uts1 * monomial(1,-order)
monomial(ccPow,(n :: I) * numer(r)) * cPower(uts2,r :: Coef)
cExp uts ==
zero?(cc := coefficient(uts,0)) => iExp(uts,1)
TRANSFCN => iExp(uts,exp cc)
error concat("exp: ",TRCONST)
cLog uts ==
zero?(cc := coefficient(uts,0)) =>
error "log: constant coefficient should not be 0"
(cc = 1) => integrate(differentiate(uts) * (iExquo(1,uts,true) :: %))
TRANSFCN =>
y := iExquo(1,uts,true) :: %
(log(cc) :: %) + integrate(y * differentiate(uts))
error concat("log: ",TRCONST)
sincos: % -> Record(%sin: %, %cos: %)
sincos uts ==
zero?(cc := coefficient(uts,0)) => iSincos(uts,0,1,-1)
TRANSFCN => iSincos(uts,sin cc,cos cc,-1)
error concat("sincos: ",TRCONST)
cSin uts == sincos(uts).%sin
cCos uts == sincos(uts).%cos
cTan uts ==
zero?(cc := coefficient(uts,0)) => iTan(uts,differentiate uts,0,1)
TRANSFCN => iTan(uts,differentiate uts,tan cc,1)
error concat("tan: ",TRCONST)
cCot uts ==
zero? uts => error "cot: cot(0) is undefined"
zero?(cc := coefficient(uts,0)) => error error concat("cot: ",NPOWERS)
TRANSFCN => iTan(uts,-differentiate uts,cot cc,1)
error concat("cot: ",TRCONST)
cSec uts ==
zero?(cc := coefficient(uts,0)) => iExquo(1,cCos uts,true) :: %
TRANSFCN =>
cosUts := cCos uts
zero? coefficient(cosUts,0) => error concat("sec: ",NPOWERS)
iExquo(1,cosUts,true) :: %
error concat("sec: ",TRCONST)
cCsc uts ==
zero? uts => error "csc: csc(0) is undefined"
TRANSFCN =>
sinUts := cSin uts
zero? coefficient(sinUts,0) => error concat("csc: ",NPOWERS)
iExquo(1,sinUts,true) :: %
error concat("csc: ",TRCONST)
cAsin uts ==
zero?(cc := coefficient(uts,0)) =>
integrate(cRationalPower(1 - uts*uts,-1/2) * differentiate(uts))
TRANSFCN =>
x := 1 - uts * uts
cc = 1 or cc = -1 =>
-- compute order of 'x'
(ord := orderOrFailed x) case "failed" =>
error concat("asin: ",MAYFPOW)
(order := ord :: I) = -1 => return asin(cc) :: %
odd? order => error concat("asin: ",FPOWERS)
c0 := asin(cc) :: %
c0 + integrate(cRationalPower(x,-1/2) * differentiate(uts))
c0 := asin(cc) :: %
c0 + integrate(cRationalPower(x,-1/2) * differentiate(uts))
error concat("asin: ",TRCONST)
cAcos uts ==
zero? uts =>
TRANSFCN => acos(0)$Coef :: %
error concat("acos: ",TRCONST)
TRANSFCN =>
x := 1 - uts * uts
cc := coefficient(uts,0)
cc = 1 or cc = -1 =>
-- compute order of 'x'
(ord := orderOrFailed x) case "failed" =>
error concat("acos: ",MAYFPOW)
(order := ord :: I) = -1 => return acos(cc) :: %
odd? order => error concat("acos: ",FPOWERS)
c0 := acos(cc) :: %
c0 + integrate(-cRationalPower(x,-1/2) * differentiate(uts))
c0 := acos(cc) :: %
c0 + integrate(-cRationalPower(x,-1/2) * differentiate(uts))
error concat("acos: ",TRCONST)
cAtan uts ==
zero?(cc := coefficient(uts,0)) =>
y := iExquo(1,(1 :: %) + uts*uts,true) :: %
integrate(y * (differentiate uts))
TRANSFCN =>
(y := iExquo(1,(1 :: %) + uts*uts,true)) case "failed" =>
error concat("atan: ",LOGS)
(atan(cc) :: %) + integrate((y :: %) * (differentiate uts))
error concat("atan: ",TRCONST)
cAcot uts ==
TRANSFCN =>
(y := iExquo(1,(1 :: %) + uts*uts,true)) case "failed" =>
error concat("acot: ",LOGS)
cc := coefficient(uts,0)
(acot(cc) :: %) + integrate(-(y :: %) * (differentiate uts))
error concat("acot: ",TRCONST)
cAsec uts ==
zero?(cc := coefficient(uts,0)) =>
error "asec: constant coefficient should not be 0"
TRANSFCN =>
x := uts * uts - 1
y :=
cc = 1 or cc = -1 =>
-- compute order of 'x'
(ord := orderOrFailed x) case "failed" =>
error concat("asec: ",MAYFPOW)
(order := ord :: I) = -1 => return asec(cc) :: %
odd? order => error concat("asec: ",FPOWERS)
cRationalPower(x,-1/2) * differentiate(uts)
cRationalPower(x,-1/2) * differentiate(uts)
(z := iExquo(y,uts,true)) case "failed" =>
error concat("asec: ",NOTINV)
(asec(cc) :: %) + integrate(z :: %)
error concat("asec: ",TRCONST)
cAcsc uts ==
zero?(cc := coefficient(uts,0)) =>
error "acsc: constant coefficient should not be 0"
TRANSFCN =>
x := uts * uts - 1
y :=
cc = 1 or cc = -1 =>
-- compute order of 'x'
(ord := orderOrFailed x) case "failed" =>
error concat("acsc: ",MAYFPOW)
(order := ord :: I) = -1 => return acsc(cc) :: %
odd? order => error concat("acsc: ",FPOWERS)
-cRationalPower(x,-1/2) * differentiate(uts)
-cRationalPower(x,-1/2) * differentiate(uts)
(z := iExquo(y,uts,true)) case "failed" =>
error concat("asec: ",NOTINV)
(acsc(cc) :: %) + integrate(z :: %)
error concat("acsc: ",TRCONST)
sinhcosh: % -> Record(%sinh: %, %cosh: %)
sinhcosh uts ==
zero?(cc := coefficient(uts,0)) =>
tmp := iSincos(uts,0,1,1)
[tmp.%sin,tmp.%cos]
TRANSFCN =>
tmp := iSincos(uts,sinh cc,cosh cc,1)
[tmp.%sin,tmp.%cos]
error concat("sinhcosh: ",TRCONST)
cSinh uts == sinhcosh(uts).%sinh
cCosh uts == sinhcosh(uts).%cosh
cTanh uts ==
zero?(cc := coefficient(uts,0)) => iTan(uts,differentiate uts,0,-1)
TRANSFCN => iTan(uts,differentiate uts,tanh cc,-1)
error concat("tanh: ",TRCONST)
cCoth uts ==
tanhUts := cTanh uts
zero? tanhUts => error "coth: coth(0) is undefined"
zero? coefficient(tanhUts,0) => error concat("coth: ",NPOWERS)
iExquo(1,tanhUts,true) :: %
cSech uts ==
coshUts := cCosh uts
zero? coefficient(coshUts,0) => error concat("sech: ",NPOWERS)
iExquo(1,coshUts,true) :: %
cCsch uts ==
sinhUts := cSinh uts
zero? coefficient(sinhUts,0) => error concat("csch: ",NPOWERS)
iExquo(1,sinhUts,true) :: %
cAsinh uts ==
x := 1 + uts * uts
zero?(cc := coefficient(uts,0)) => cLog(uts + cRationalPower(x,1/2))
TRANSFCN =>
(ord := orderOrFailed x) case "failed" =>
error concat("asinh: ",MAYFPOW)
(order := ord :: I) = -1 => return asinh(cc) :: %
odd? order => error concat("asinh: ",FPOWERS)
-- the argument to 'log' must have a non-zero constant term
cLog(uts + cRationalPower(x,1/2))
error concat("asinh: ",TRCONST)
cAcosh uts ==
zero? uts =>
TRANSFCN => acosh(0)$Coef :: %
error concat("acosh: ",TRCONST)
TRANSFCN =>
cc := coefficient(uts,0); x := uts*uts - 1
cc = 1 or cc = -1 =>
-- compute order of 'x'
(ord := orderOrFailed x) case "failed" =>
error concat("acosh: ",MAYFPOW)
(order := ord :: I) = -1 => return acosh(cc) :: %
odd? order => error concat("acosh: ",FPOWERS)
-- the argument to 'log' must have a non-zero constant term
cLog(uts + cRationalPower(x,1/2))
cLog(uts + cRationalPower(x,1/2))
error concat("acosh: ",TRCONST)
cAtanh uts ==
half := inv(2 :: RN) :: Coef
zero?(cc := coefficient(uts,0)) =>
half * (cLog(1 + uts) - cLog(1 - uts))
TRANSFCN =>
cc = 1 or cc = -1 => error concat("atanh: ",LOGS)
half * (cLog(1 + uts) - cLog(1 - uts))
error concat("atanh: ",TRCONST)
cAcoth uts ==
zero? uts =>
TRANSFCN => acoth(0)$Coef :: %
error concat("acoth: ",TRCONST)
TRANSFCN =>
cc := coefficient(uts,0); half := inv(2 :: RN) :: Coef
cc = 1 or cc = -1 => error concat("acoth: ",LOGS)
half * (cLog(uts + 1) - cLog(uts - 1))
error concat("acoth: ",TRCONST)
cAsech uts ==
zero? uts => error "asech: asech(0) is undefined"
TRANSFCN =>
zero?(cc := coefficient(uts,0)) =>
error concat("asech: ",NPOWLOG)
x := 1 - uts * uts
cc = 1 or cc = -1 =>
-- compute order of 'x'
(ord := orderOrFailed x) case "failed" =>
error concat("asech: ",MAYFPOW)
(order := ord :: I) = -1 => return asech(cc) :: %
odd? order => error concat("asech: ",FPOWERS)
(utsInv := iExquo(1,uts,true)) case "failed" =>
error concat("asech: ",NOTINV)
cLog((1 + cRationalPower(x,1/2)) * (utsInv :: %))
(utsInv := iExquo(1,uts,true)) case "failed" =>
error concat("asech: ",NOTINV)
cLog((1 + cRationalPower(x,1/2)) * (utsInv :: %))
error concat("asech: ",TRCONST)
cAcsch uts ==
zero? uts => error "acsch: acsch(0) is undefined"
TRANSFCN =>
zero?(cc := coefficient(uts,0)) => error concat("acsch: ",NPOWLOG)
x := uts * uts + 1
-- compute order of 'x'
(ord := orderOrFailed x) case "failed" =>
error concat("acsc: ",MAYFPOW)
(order := ord :: I) = -1 => return acsch(cc) :: %
odd? order => error concat("acsch: ",FPOWERS)
(utsInv := iExquo(1,uts,true)) case "failed" =>
error concat("acsch: ",NOTINV)
cLog((1 + cRationalPower(x,1/2)) * (utsInv :: %))
error concat("acsch: ",TRCONST)
--% Output forms
-- check a global Lisp variable
factorials?() == false
termOutput(k,c,vv) ==
-- creates a term c * vv ** k
k = 0 => c :: OUT
mon := (k = 1 => vv; vv ** (k :: OUT))
c = 1 => mon
c = -1 => -mon
(c :: OUT) * mon
-- check a global Lisp variable
showAll?() == true
seriesToOutputForm(st,refer,var,cen,r) ==
vv :=
zero? cen => var :: OUT
paren(var :: OUT - cen :: OUT)
l : L OUT := empty()
while explicitEntries? st repeat
term := frst st
l := concat(termOutput(getExpon(term) * r,getCoef term,vv),l)
st := rst st
l :=
explicitlyEmpty? st => l
(deg := retractIfCan(elt refer)@Union(I,"failed")) case I =>
concat(prefix("O" :: OUT,[vv ** ((((deg :: I) + 1) * r) :: OUT)]),l)
l
empty? l => (0$Coef) :: OUT
reduce("+",reverse_! l)
|