File: functs.mac

package info (click to toggle)
maxima 5.21.1-2squeeze
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 94,928 kB
  • ctags: 43,849
  • sloc: lisp: 298,974; fortran: 14,666; perl: 14,325; tcl: 10,494; sh: 4,052; makefile: 2,975; ansic: 471; awk: 24; sed: 7
file content (88 lines) | stat: -rw-r--r-- 3,116 bytes parent folder | download
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
/* eval_when([translate,load,loadfile,batch,demo],
 matchdeclare(a,nonzeroandfreeof(x),[b,c],freeof(x)))$ */

define_variable(takegcd,true,boolean,"used in gcdivide to decide the
gcd choice");

rempart&&  rempart(exp,n):=
    ?append(rest(exp,  /* combine two parts of exp
	   first part is beginning to part to be removed
	   specify that the first l-1 parts are retained */
	(if listp(n) then n[1] else n)-1-length(exp)),
	block([t],  /* last part is from removed part to end */
	if atom(t:rest(exp,  /* last m-1 parts are retained */
	    if listp(n) then n[2] else n))
	then ?list(t) else ?cdr(t)))$

wronskian&&  wronskian(functlist,var):=block([end],
    end:length(functlist)-1,
    functlist:[functlist],
    thru end do functlist:endcons(map(lambda([x],diff(x,var)),
	last(functlist)),functlist),
    apply('matrix,functlist))$

tracematrix&&  tracematrix(m):=block([sum,len],sum:0,len:length(m),
for i:1 thru len do sum:sum+part(m,i,i),sum)$

rational&&  rational(z):=block([n,d,cd,ratfac],
    ratfac:false,
    n:ratdisrep(ratnumer(z)*(cd:conjugate(d:ratdenom(z)))),
    d:rat(n/ratdisrep(d*cd)),
    if ratp(z) then d else ratdisrep(d))$

logical&&  logand(x,y):=?boole(1,x,y)$
	logor(x,y):=?boole(7,x,y)$
	logxor(x,y):=?boole(6,x,y)$

nonzeroandfreeof&&  nonzeroandfreeof(x,e):=is(e#0 and freeof(x,e))$

/* linear&& matchdeclare(a,nonzeroandfreeof(x),[b,c],freeof(x))$
    defmatch(linearize,a*x+b,x)$
    defmatch(quadraticize,a*x^2+b*x+c,x)$
    linear(exp,x):=block([a,b],if linearize(exp,x)=false then exp else
	a*x+b)$
    quadratic(exp,x):=block([a,b,c],if quadraticize(exp,x)=false then
	exp else a*x^2+b*x+c)$ */

lcm&& lcm([list]):=block([listconstvars:false],if listofvars(list)=[] then
lcm1(list) else factor(lcm1(list)))$

lcm1(list):=if list=[] then 1 else block([rlist:rest(list),flist:first(list),
frlist,partswitch:true,inflag:true,piece], if rlist=[] then flist else
lcm1(cons(flist*(frlist:first(rlist))/gcd(flist,frlist),rest(rlist))))$

gcdivide&&  gcdivide(poly1,poly2):=block([gcdlist],
		gcdlist:if takegcd then ezgcd(poly1,poly2)
			else [1,poly1,poly2],
		gcdlist[2]/gcdlist[3])$

series&&  arithmetic(a,d,n):=a+(n-1)*d$
          geometric(a,r,n):=a*r^(n-1)$
          harmonic(a,b,c,n):=a/(b+(n-1)*c)$
          arithsum(a,d,n):=n*(a+(n-1)*d/2)$
          geosum(a,r,n):=block([],
            if r=1
                then if n='inf
                        then return(limit(i*a,i,'inf))
                        else return(n*a),
            if r=-1
                then error("The series is not convergent"),
            if n='inf 
                then if abs(r) < 1 
                        then a/(1-r)
                        else limit(a*(1-r^i)/(1-r),i,'inf)
                else a*(1-r^n)/(1-r)   )$

gauss&&  gaussprob(x):=1/sqrt(2*%pi)*%e^(-x^2/2)$

/* See, for example, http://en.wikipedia.org/wiki/Gudermannian_function */
gd&&  gd(x):=2*atan(%e^x)-%pi/2$
	agd(x):=log(tan(%pi/4+x/2))$

trig&&  vers(x):=1-cos(x)$
	covers(x):=1-sin(x)$
	exsec(x):=sec(x)-1$
	hav(x):=(1-cos(x))/2$

combination&&  combination(n,r):=binomial(n,r)$
	permutation(n,r):=binomial(n,r)*r!$