#Maple Code for Lecture 12 of Combinatorics , Math 454, taught by Dr. Z. Help12:=proc(): print(`RDB(N,K), ValuesT(L), valuesTclever(L) , Ave(L), kthMoment(L,k), AveClever, kthMomentClever `): print(`CP(L1,L2) `): end: #RDB(N,K): A random data base with N "people" with integer numerical attributes from 1 to K #Try: RDB(10,100); RDB:=proc(N,K) local ra,i: ra:=rand(1..K): [seq(ra(),i=1..N)]: end: #WtEn(L,x): inputs a list L desribing some numerical attribite for nops(L) people (e.g. age) #where the objects(people) are called 1,2,..., nops(L) (A very simple "database") outputs #the Weight-Enumerator in the variable x. WtEn:=proc(L,x) local i: add(x^L[i],i=1..nops(L)): end: #ValuesT(L): inputs a "database" L such that for i=1...nops(L), L[i] is the "age" of i #outputs the set of "ages", followed by the table T[age]:=Number of people with that age #and outputs the set of values taken ValuesT:=proc(L) local S,T,i,s: #S is the set of values taken S:=convert(L,set): #we now form a table T such that T[s]=Number of people of "age" s, by asking each of then #what is your age? #But we first must initialize the count to be 0 for s in S do T[s]:=0: od: for i from 1 to nops(L) do print(i, `What is your age?`): print(`My age is`, L[i]): print(``): #The age group L[i]-years old get credit 1 T[L[i]]:=T[L[i]]+1: print(`The number of people of age`, L[i], `has been incrased by 1 and is now`, T[L[i]]): print(``): od: print(`The set of ages in this population is`): print(S): print(``): S:=sort(convert(S,list)): for i from 1 to nops(S) do print(`The number of people with age`, S[i], `is `, T[S[i]]): od: S,op(T): end: #ValuesTclever(L): Like ValuesT(L) but using weight-enumerators #outputs the set of "ages", followed by the table T[age]:=Number of people with that age #and outputs the set of values taken ValuesTclever:=proc(L) local f,x,S,T,s: f:=WtEn(L,x): print(`The smallest age is`, ldegree(f,x)): print(`The largest age is`, degree(f,x)): S:=[]: for s from ldegree(f,x) to degree(f,x) do if coeff(f,x,s)<>0 then S:=[op(S),s]: T[s]:=coeff(f,x,s): print(`The number of people with age`, s, `is `, coeff(f,x,s)): fi: od: S,op(T): end: #Ave(L): The average age of the popolation L with nops(L) people Ave:=proc(L) local i: add(L[i],i=1..nops(L))/nops(L): end: #kthMoment(L,k): The k-th moment about the mean of the population L kthMoment:=proc(L,k) local mu,i: mu:=Ave(L): add((L[i]-mu)^k,i=1..nops(L))/nops(L): end: AveClever:=proc(L) local f,x: f:=WtEn(L,x): subs(x=1,diff(f,x))/subs(x=1,f): end: #kthMomentClever(L,k): The k-th moment about the mean of the population L kthMomentClever:=proc(L,k) local x,mu,f,f1,i: f:=WtEn(L,x): mu:=AveClever(L): f1:=f/x^mu/subs(x=1,f): for i from 1 to k do f1:=expand(x*diff(f1,x)): od: subs(x=1,f1): end: #CP(L1,L2): Given two data bases L1 and L2 where there are nops(L1) men with their ages #and nops(L2) women with their ages, constructs the database CP(L1,L2) with #nops(L1)*nops(L2) items where the attribute is "combined age" and #pairs [i,j] are in lexicographic order CP:=proc(L1,L2) local i,j,L: L:=[]: for i from 1 to nops(L1) do for j from 1 to nops(L2) do L:=[op(L),L1[i]+L2[j]]: od: od: L: end: