#M4.txt: Maple Code for Lecture 4 of Math 454,Combinatorics, Rutgers University, taught by Dr. Z. (Doron Zeilberger) Help4:=proc():print(` Nynops(A), CheckAdd(A,B), CP(A,B), CheckMult(A,B), Words(A,n) `): end: with(combinat): #Mynops(A): Inputs a finite set A and outputs the number of elements using the #Fundamental Theorem of Enumeration (see http://sites.math.rutgers.edu/~zeilberg/mamarim/mamarimPDF/enu.pdf, p.1, bottom of column 1) #It does the same thing as the Maple command ` nops(A) ' Mynops:=proc(A) local a: if not type(A,set) then print(A, `is not a set `): RETURN(FAIL): fi: add(1, a in A): end: #CheckAdd(A,B): Empirically checks the trivial but EXTREMELY important fact #(see http://sites.math.rutgers.edu/~zeilberg/mamarim/mamarimPDF/enu.pdf, p.2, bottom of column 1) #that |A union B|=|A|+|B| CheckDecomp:=proc(A,B): if not type(A,set) then print(A, `is not a set `): RETURN(FAIL): fi: if not type(B,set) then print(B, `is not a set `): RETURN(FAIL): fi: if A intersect B<>{} then print(A,B, `have the following common elements `, A intersect B): RETURN(FAIL): fi: #This checks that if A and B are disjoint finite sets, then #|A U B|= |A| + |B| evalb(Mynops(A union B)=Mynops(A) + Mynops(B)): end: #CP(A,B): The Cartesian product of finite sets A and B CP:=proc(A,B) local a,b: {seq(seq([a,b],a in A),b in B)}: end: #CheckMult(A,B): Empirically checks the trivial but EXTREMELY important fact #(see http://sites.math.rutgers.edu/~zeilberg/mamarim/mamarimPDF/enu.pdf, p.2, bottom of column 1) #that |AxB|=|A|*|B| #Try:CheckMult({1,2,3},{a,b}) CheckMult:=proc(A,B) evalb(Mynops(CP(A,B))=Mynops(A)*Mynops(B)): end: #Words(A,n): inputs a finite set, the "alphabet" and outputs the set of n-letter words in A. #For example, to get the set of binary (i.e. 0-1) word of length 5 type: #Words({0,1},5); Words:=proc(A,n) local W1,w,a: option remember: if n=0 then RETURN({[]}): else W1:=Words(A,n-1): RETURN({seq(seq([op(w),a], a in A),w in W1)}): fi: end: