#C5.txt: Maple Code for Lecture 5 Help5:=proc(): print(`Redu(L), Expa(pi,S), PermuA(n),PermuI(n) `): end: #Redu(L): inputs a list L of numbers and outputs #The multi-set permuation of {1, ...,nops({op(L)}) where n is the number of #number of #distinct members of L and the smallest number in {op(L)} #replaced by 1, the second smallest by 2, etc. #For example #Redu([evalf(Pi),evalf(Pi),evalf(exp(1)),evalf(exp(1))] #should return #[2,2,1,1] ##Redu([evalf(Pi),evalf(exp(1)),evalf(exp(1)),5] #=[2,1,1,3] # Redu:=proc(L) local S,T,i: S:=sort(convert({op(L)},list)): for i from 1 to nops(S) do T[S[i]]:=i: od: [seq(T[L[i]],i=1..nops(L))]: end: #Expa(pi,S): inputs a permutation pi of 1,..., nops(pi) and #a sorted list of distinct numbers S, replaces 1 by #the smallest member of S, etc. #For example #Expa([2,1,3],[11,13,15])= [13,11,15] Expa:=proc(pi,S) local i: subs({seq(i=S[i],i=1..nops(S))},pi): end: #PermuA(n): inputs a non-neg. integer n and outputs the list of #all n! permutations of {1,...,n} in lex-order (same as permute(n) in combinat) PermuA:=proc(n) local S,L,j, J,pi: option remember: if n=0 then RETURN([[]]): fi: S:=PermuA(n-1): L:=[]: for j from 1 to n do #J:=1...j-1,j+1..n J:=[seq(1..j-1), seq(j+1..n)]: L:= [op(L),seq([ j, op(Expa(S[i],J)) ],i=1..nops(S))] : od: L: end: #PermuI(n): the list of all permutations of {1, ...,n} using inertion PermuI:=proc(n) local S,i,pi,pi1,L,j,i1: option remember: if n=0 then RETURN([[]]): fi: S:=PermuI(n-1): L:=[]: for i from 1 to nops(S) do pi:=S[i]: for j from 1 to n do pi1:=[op(1..j-1,pi),n,op(j..nops(pi),pi)]: L:=[op(L),pi1]: od: od: L: end: