Last update: Dec. 14, 2020.
It should be sent to the email address
ShaloshBEkhad at gmail dot com
Subject: HomeWork#X#Y
and then attach a .txt file(s) called
hwXFirstLast.txt (e.g. hw1DoronZeilberger.txt )
where X is the number of the assignment
Except for the first assignment, you should have two attached .txt files.
For example, when Paul Erdos submits homework assignments 1 and 2, (due Sept. 13, 2020) he should email ShaloshBEkhad at gmail dot com, with
Subject: HomeWork#1#2
and attach the text files (the source code plus human comments (such lines must start with #)
hw1PaulErdos.txt and hw2PaulErdos.txt
#Please do not post homework
or
#OK to post homework
Followed by
#Your Name, Date, Assignment X
hw1FirstLast.txt
Print out (into a .txt file, by copying-and-pasting) some random lines, e.g.
diff(x^3,x);
What is NuF(1000)? Why would Maple complain if you tried to do nops(F(1000))?
Added Sept. 14, 2020: The solutions of the students who kindly agreed to have them posted are in this directory
hw2FirstLast.txt
Indicate whether it is OK to post
(a+b+c)!/(a!*b!*c!)
Walks(m,n)
from the Maple Code for Lecture 1 to write a procedure
RestrictedWalks(m,n,S)
that inputs non-negative integers, m and n, as before, but also a finite set of lattice points S, and outputs the SET of walks from [0,0] to [m,n] (with the same fundamental steps as before, i.e. [1,0] (E) and [0,1] (N)) that NEVER visit the members of S.
For example
RestrictedWalks(2,2,{[1,1]});
should output {[E,E,N,N],[N,N,E,E]}
NuWalks(m,n)
from the Maple Code for Lecture 1 to write a procedure
RestrictedNuWalks(m,n,S)
that inputs non-negative integers, m and n, as before, but also a finite set of lattice points S, and outputs the NUMBER of walks from [0,0] to [m,n] (with the same fundamental steps as before, i.e. [1,0] (E) and [0,1] (N)) that NEVER visit the members of S.
For example
RestrictedNuWalks(2,2,{[1,1]});
should output 2.
What is
RestrictedNuWalks(50,50,{seq([i,i],i=1..50)}); ?
Added Sept. 14, 2020: The solutions of the students who kindly agreed to have them posted are in this directory
hw3FirstLast.txt
Indicate whether it is OK to post
write a procedure
NuFP(pi)
That inputs a permutation pi of [1,...,n] and outputs the NUMBER of Fixed points of pi. For example
NuFP([1,2,3,4])=4 (Since pi[1]=1, pi[2]=2, pi[3]=3, pi[4]=4,) NuFP([2,1,3,4])=2 (since pi[3]=3, pi[4]=4, but pi[1] != 1, pi[2]!=2) NuFP([3,4,1,2])=0
Der(n)
That inputs a non-negative integer n and outputs the SET of derangements of length n.
For example, Der(2)={[2,1]}, Der(3)={[2,3,1], [3,1,2]}
Can you find it in the OEIS?
[seq(nops(Comps(i)),i=1..8)]?
Can you conjecture a formula for the number of compositions of n?
Added Sept. 21, 2020: The solutions of the students who kindly agreed to have them posted are in this directory
hw4FirstLast.txt
Indicate whether it is OK to post
Find the smallest positive integer n such that
1, 2, 3, ....., n (in Maple: seq(i,i=1..n) ) only returns ONE hit, namely A27 [Typo corrected thanks to Tifany Tong]
|Comp(U,A1) intersect Comp(U,A2)|= |U|- |A1|-|A2|+ |A1 intersect A2|
Do the following
PIE2(U,A1,A2)
that inputs three sets U, A1, A2. After checking that U, A1,A2, are indeed sets (return FAIL if they are not) AND that A1 or A2 are NOT subsets of U (return FAIL if they are not), computes it in two ways. The first way by directly finding |Comp(U,A1) intersect Comp(U,A2)| and the second way by using the above formula, namely
|U|- |A1|-|A2|+ |A1 intersect A2|
For example the output of
PIE2({1,2,3,4,5},{1,2,3},{2,3,5})
should be [1,1]
PIE3(U,A1,A2,A3)
PIE4(U,A1,A2,A3,A4)
Added Sept. 21, 2020: The solutions of the students who kindly agreed to have them posted are in this directory
hw5FirstLast.txt
Indicate whether it is OK to post
then p(n)=n*p(n-1)
(and hence p(n)=n!)
It used the decomposition of P(n) into subsets according to the LOCATION of n.
Find a new proof, explaining everything, of the same fact but breaking-up P(n) into the sets
P_j(n)={All permutations pi in P(n) such that pi[1]=j, j=1..n
Let a1,a2,a3, be distinct positive integers, and let P(n;a1,a2,a3) be the set of words in the alphabet {a1,a2,a3},
of ANY length that add-up to n.
For example P(3; 1,2,3)={111,12,21,3}
Decompose P(n;a1,a2,a3) into smaller sets, and deduce a recurrence relation for
p(n)=p(n;a1,a2,a3):= |P(n;a1,a2,a3)|
SEQP(a1,a2,a3,N)
That inputs a1,a2,a3, as above, and a positive integer N, and outputs the first N+1 terms, starting at n=0 of
p(n,a1,a2,a3), n=1..N
What are
|C union S union L union K|=
|C| + |S|+ |L| + |K|
-( |C intersect S| + |C intersect L| + |C intersect K| + |S intersect L| + |S intersect K| + +|L intersect K| )
+( |C intersect S intersect L| +|C intersect S intersect K| +|C intersect K intersect L| +|S intersect K intersect L| )
-|C intersect S intersect L intersect K|
Do the analogous thing for a lucky person who is lucky to be clever AND strong AND good-looking AND kind-hearted.
Added Sept. 29, 2020: The solutions of the students who kindly agreed to have them posted are in this directory
hw6FirstLast.txt
Indicate whether it is OK to post
Also read and understand procedures Pnx(n,x) and PnxF(n,x). Test whether
[seq(Pnx(n,x),n=1..7)]
and
[seq(PnxF(n,x),n=1..7)]
give you the same output.
Now try to do
time([seq(Pnx(n,x),n=1..8)]);
and
time([seq(PnxF(n,x),n=1..8)]);
What takes longer? What is
time([seq(PnxF(n,x),n=1..30)]);
Estimate roughly (but don't run it!)
time([seq(Pnx(n,x),n=1..30)]);
D(n)=add(binomial(n,k)*(-1)^k*(n-k)!,k=0..n)
for the number of derangement of n objects, called D(n). Explain why this is the constant term (the coefficient of x^0) in PnxF(n,x)
[seq(coeff(PnxF(n,x),x,i),n=0..12)] for i=0,1,2,3, ...
List their A numbers (if they exist). What is the largest i for which there is a sequence in the OEIS?
One of them can be gotten from (Do it!)
SumTools[Hypergeometric][ZeilbergerRecurrence](binomial(n,k)*(-1)^k*(n-k)!,n,k,d,0..n);
which tells you that
d(n)=n*d(n-1)+(-1)^n
The OEIS gives another recurrence relating d(n) to d(n-1) and d(n-2). Use the above recurrence to find this other recurrence.
A. Prove by induction on n, that if x[1], ..., x[n] are any numbers (or symbols)
product(1-x[i], i=1..n)= Sum ((-1)^|S|*x[S],S subset of {1, ...,n})
where x[S]=Product (x[s], s in S). For example x[{3,6,7}]=x[3]*x[6]*x[7]
B. Let Chi(statement)=1 if it is true and 0 if it is false. Explain why the left side of PIE (of the new version that finds the number of elements in U that does not belong to any of A[1], ..., A[k]) can be written as
Sum ( Product( 1-Chi( u in A[i])),i=1..k), u in U)
Use the above identity to give a new proof of the PIE, by showing that it equals to the right side.
Added Sept. 29, 2020: The solutions of the students who kindly agreed to have them posted are in this directory
hw7FirstLast.txt
Indicate whether it is OK to post
especially the last procedures that I did not have a chance to discuss,
GFseq(f,x,N)
What are
GFseq(1/(1-x-x^2-x^3),x,30);
GFseq(1/(1-x+x^2-x^3),x,30);
GFseq(exp(-x)/(1-x),x,30);
Sum(a(n)*x^n, n=0..infinity) ,
as a certain rational function whose denominator ONLY depends on the coefficients of the recurrence (c1,c2,..., ck) and whose numerator also depends on the initial conditions. Show how to go the other way.
Sum(a(n)*x^n, n=0..infinity) = 1/(1-3*x+5*x^2)
In other words a(n) is the coefficient of x^n in the Taylor expansion (around x=0) of 1/(1-3*x+5*x^2)
[In Maple, you can do coeff(taylor(1/(1-3*x+5*x^2),x=0,n+1),x,n) to compute it.]
Prove that the sequence a(n) satisfies the linear recurrence
a(n)=3*a(n-1)-5*a(n-2)
[Typo corrected Oct. 2, 2020, spotted by Tifany Tong who won a dollar.]
More generally, prove that for any numbers c1, c2, ..., ck, if you define a(n) In terms of the generating function
Sum(a(n)*x^n, n=0..infinity) = 1/(1-c1*x-... -ck*x^k)
In other words a(n) is the coefficient of x^n in the Taylor expansion (around x=0) of 1/(1-c1*x-...-ck*x^k)
Prove that the sequence a(n) satisfies the linear recurrence
a(n)=c1*a(n-1)+c2*a(n-2)+ ... + ck*a(n-k)
d(n)=n*d(n-1)+(-1)^(n-1), with initial condition d(0)=1 ,
first proved by Lehonard Euler. This is different than what we did in class, since first it is not constant coefficients (the coefficient of d(n-1) in the right side is n, that is NOT a constant, and also there is an extra term that does not have d(..) in front, namely (-1)^(n-1).
By dividing the equation by n!, and using the same technique of generating functions described in Lecture 7, find an explicit expression for the EXPONENTIAL GENERATING FUNCTION
f(x)=Sum( ( d(n)/n! ) *x^n , n=0..infinity)
[Hint{ recall from calc2 the Taylor expansion of exp(x), or more relevantly, that of exp(-x)]
Added Oct. 5, 2020: The solutions of the students who kindly agreed to have them posted are in this directory
hw8FirstLast.txt
Indicate whether it is OK to post
Use them to get the following numbers
(i) The number of 10-letter words in the alphabet {1,4,6} that add-up to 201
(ii) The number of words in the alphabet {2,3,7} of ANY length, that add-up to 411
(iii) The number of sequences of any length whose entries are either 1 (mod 5) or 4 (mod 5) and that add up to 341
In a
composition the order matters. For example the set of compositions of 3 is {111,12,21,3}.
In a
partition the order does not matter, hence we agree to list it in weakly-decreasing order.
For example, the set of partitions of 3 is {3,21, 111} (since 12 is the same as 21).
Using the convention of representing partitions as weakly-decreasing sequences, write a procedure, call it Pnk(n,k) that inputs non-negative integers n and k and outputs the SET of all partitions of n whose LARGEST part is k. For example,
[Added Oct. 1, 2020: example corrected thanks to Kent Mey, before it was according to the number of parts]
Pnk(5,1)={[1,1,1,1,1]} , Pnk(5,2)={[2,2,1], [2,1,1,1]} , Pnk(5,3)={[3,1,1], [3,2]} , Pnk(5,4)={[4,1]]}, Pnk(5,5)={[5]}
REMEMBER to use "option remember"
Hint: When you take a partition [a1,a2,, .., ar] whose largest part is k (i.e.) a1=k and remove the first component (that is k), you get the partition [a2,.., ar] of n-k whose largest part a2, is <=k , so it is in natural bijection with
Pnk(n-k,k) Union Pnk(n-k,k-1) Union ... Union Pnk(n-k,1)
Another hint: Pnk(n,k) is the Empty Set if k>n
pnk(5,1)=1 , pnk(5,2)=2 , pnk(5,3)=2 , Pnk(5,4)=1, Pnk(5,5)=1
REMEMBER to use "option remember"
What is the OEIS A number of the integer sequence
seq(pn(n),n=0...30);
Hint: The set of partitions of n is Pnk(n,1) Union Pnk(n,2) Union ... Union Pnk(n,n)
What are
[seq(pn(5*n+4) mod 5, n=1..50)]
[seq(pn(7*n+5) mod 7, n=1..50)]
[seq(pn(11*n+6) mod 11, n=1..50)]
Added Oct. 5, 2020: The solutions of the students who kindly agreed to have them posted are in this directory
hw9FirstLast.txt
Indicate whether it is OK to post
DiagSeq2(f,x,y,N), DiagWalks2D(S,N), DiagSeq3(f,x,y,z,N), DiagWalks3D(S,N)
Using these procedures answer the following questions. Let a[i] be the i-th digit of your RUID. If it is zero, make it 1.
1/(1-a[1]*x-a[2]*y+a[5]*x*y-a[6]*x^3+a[7]*y^3)
What is the number of ways of walking from 0 to 100 where all positive steps are allowed except multiples of 5?
Using this, find the exact value of the number of walks from 0 to 300 where every step-size is permitted except 2 and 3
gfun[listtorec](L,f(n))
to guess a linear recurrence equation with POLYNOMIAL coefficients for the sequences DiagWalks2D(S,40) where
gfun[listtorec](L,f(n))
to guess a linear recurrence equation with POLYNOMIAL coefficients.
DiagSeqk(k,x,f,N) and DiagWalkskD(k,S,N)
that inputs a positive integer k, a symbol x, and a rational function f of x[1], ..., x[k], as well as a positive integer N for DiagSeqk and a pos. integer k, a set of lists of length k of positive integers S (where [0, ..., 0] is not allowed) and a positive integer N for DiagWalkskD.
What is
DiagWalkskD(5,{[0,0,0,0,1],[0,0,0,1,0],[0,0,1,0,0],[0,1,0,0,0],[1,0,0,0,0]},30)?
Is it is in the OEIS? What about
DiagWalkskD(5,{[0,0,0,0,1],[0,0,0,1,0],[0,0,1,0,0],[0,1,0,0,0],[1,0,0,0,0],[1,1,1,1,1]},30)?
Added Oct. 12, 2020: The solutions of the students who kindly agreed to have them posted AND were perfect (or almost perfect) are in this directory
Lecture 10: Due Oct. 11, 9:00pm. Email ShaloshBEKhad@gmail.com an attachment
hw10FirstLast.txt
Indicate whether it is OK to post
MulPers(P1,P2) , InvPer(P) , GrabCycle(P,i), PtoC(P), CtoP(C), FunT(pi), GG(S) , inv(pi), maj(pi) , FunT(pi)
By doing the following computations, both by hand and by computer as follows
"Number of abc-avoiding permutations of length n"
and check whether it is in the OEIS.
Hint: First write a procedure IsBad(P) that returns true as soon as you found an abc-pattern by doing a triple do-loop similar to the double do-loop in inv(P). Then write another procedure that goes over all the n! permutations and counts the ones that are not bad.
S:=permute(7): {seq(evalb(InvFunT(FunT(pi))=pi), pi in S)};{evalb(FunT(InvFunT(pi))=pi), pi in S)};
getting {true} and {true}
[Hint: Look at the structure of the output of FunT(P) and try "undo" it (or "parse" it), getting a list of cycles, and then use procedure CtoP]
Added Oct. 12, 2020: The solutions of the students who kindly agreed to have them posted AND were perfect (or almost perfect) are in this directory
Lecture 11: Due Oct. 18, 9:00pm. Email ShaloshBEKhad@gmail.com an attachment
hw11FirstLast.txt
Indicate whether it is OK to post
Sum(Snk(n,k)*xn(x,k),k=0..n)
[Don't forget to use the Maple command "expand" so that you get the expanded form]
What are Axn(x,i) for i=1..20? Can you get the formula for Axn(x,n) for any non-negative integer n?
c(n,k)=c(n-1,k-1)+ (n-1)*c(n-1,k)
Sum(c(n,k)*x^k,k=1..n) ?
[Hint: don't forget to factor it at the end]
Added Oct. 19, 2020: The solutions of the students who kindly agreed to have them posted AND were perfect (or almost perfect) are in this directory
Lecture 12: Due Oct. 18, 9:00pm. Email ShaloshBEKhad@gmail.com an attachment
hw12FirstLast.txt
Indicate whether it is OK to post
write a procedure
CPg(L)
that inputs a list of lists L=[L1,L2, ...,Lk] of "databases" (represented as lists L1, L2, ..., Lk) and outputs
CP(L1,L2, ..., Lk)
In particular, CPg([L1,L2]) should output the same as CP(L1,L2) for any two lists of integers L1 and L2
AveGF(f,x) and kthMomentGF(f,x,k)
that do the same things if you already have the weight-enumerator f (in terms of x).
In particular, for any "data-base" L, check that
AveGF(WtEn(L,x),x)= AveClever(L)
and
kthMomentGF(WtEn(L,x),x,k)= kthMomentClever(L,k)
m_k(X)/m_2(X)^(k/2)
, where m_k(X) is the k-th moment about the mean.
Write a procedure
ScaledMomentGF(f,x,k)
that compute it, given the weight-enumerator (alias generating-function)
Leaving n as a symbol, use Maple to find explicit expressions for
ScaledMomentGF(((1+x)/2)^n,x,k), k=2,3,4,5,6,7,8,9,10
Then take limits as n goes to infinity (using the Maple command lim( ..., n=infinity)) Get a sequence of numbers. What is it?
Is it in the OEIS?
Added Oct. 19, 2020: The solutions of the students who kindly agreed to have them posted AND were perfect (or almost perfect) are in this directory
Lecture 13: Due Oct. 25, 9:00pm. Email ShaloshBEKhad@gmail.com an attachment
hw13FirstLast.txt
Indicate whether it is OK to post
f(t)=Sum(a(n)*t^n,n=0..infinity)
Find f(t) explicitly.
A farmer, a wolf, a sheep, and a (very big) cabbage have to cross a river using a row boat that can only have the farmer and one of the other animals/vegetable. The wolf and the sheep can't be left unsupervised, and neither can the sheep and the cabbage (but the wolf and the cabbage can be left safely alone). How can this be done?
3 Missionaries and 3 Cannibals have to cross a river using a row boat that can have at most two passengers (and at least one, it is not a self-driving boat). At no time can the cannibals outnumber the missionaries on either river-bank (unless there are no missionaries, of course). How to do it?
Added Oct. 26, 2020: The solutions of the students who kindly agreed to have them posted AND were perfect (or almost perfect) are in this directory
Lecture 14: Due Oct. 25, 9:00pm. Email ShaloshBEKhad@gmail.com an attachment
hw14FirstLast.txt
Indicate whether it is OK to post
CountRuns(L,k)
that inputs a list L of numbers (or for that matter, any objects) and outputs the number of "runs" of length k in L
[A run of length k is a string L is an occurrence of an i such that L[i]=L[i+1]=...=L[i+k-1]
For example
CountRuns([1,2,2,2,1,1,1,1,2,2,2],3)
is 4 for the runs starting at i=2, i=5, i=6, i=9. Note that it can be part of a longer run.
[Hint: a quick way to find whether location i is the beginning of a run of length k (where i is between 1 and nops(L)-k+1, is to see if nope({op(i..i+k-1,L)})=1]
AvePathRuns(m,n,k,N)
That inputs positive integers m,n,k, and a LARGE positive integer N, generated N random paths, for each of them records the number of runs, and finds the sample average and standard-deviation (the square-root of the variance)
Run
AvePathRuns(200,200,5,3000)
ten times and see what you get. Are they close to each other?
AveGPathRuns(m,n,k,N)
[Hint: you only have to change one word in the code]
Run
AvePathGRuns(200,200,5,3000)
ten times. How does it compare with the previous output for all paths?
[Hint: a quick way to find whether location i is the beginning of a MAXIMAL run of length k (where i is between 1 and nops(L)-k+1, is to see if nope({op(i..i+k-1,L)})=1 and L[i-1]<>L[i] and L[i+k]<>L[i]]
Write procedures
CountMaximalRuns(L,k), AvePathMaximalRuns(m,n,k,N), and AveGPathMaximalRuns(m,n,k,N)
and do the analogous thing for the above two problems, (that you did for Runs) for Maximal Runs.
GoodBrother(L)
that inputs an arbitrary list of ODD length that adds up to 1 (so if the length is 2*n+1 it must have n+1 1's and n -1's), and outputs the UNIQUE cyclic shift that is a so-called Dyck path of length 2*n with 1 appended at the end.
For example
GoodBrother([[1,-1,-1,1,1,1,1,-1,-1,-1,1]=[1,1,1,-1,-1,-1,1,1,-1,-1,1]
[Hint: if two cyclic shifts of such an L are identical, it means that there is some word w such that L is w repeated k times. The sum of L is k times the sum of w. Show that this can only happen if k=1]
RandSetPartition(n)
That inputs a positive integer n and outputs a set-partition of {1, ..., n} where each of them has the same probability of being picked.
Hint: One way of doing it is first write a preliminary procedure
RandSetPartition1(n,k)
that inputs positive integers n and k (k between 1 and n) and outputs a random set-partition with exactly k parts, using Snk(n,k) of M11.txt doing a LDie([Snk(n-1,k-1), k*Snk(n-1,k)]) and if the die lands on Snk(n-1,k-1) recursively generate a set partitions of {1, ..., n-1} with k-1 members [calling RandSetPartition1(n-1,k-1) ] and adjoin {n} to it, and in the latter case generate a random set partition of {1, ..., n-1} with k members, [calling RandSetPartition1(n-1,k) ] and then rand(1..k) to decide which of the k sets should invite n to join.
Having done that RandSetPartition(n) would use
LDie([seq(Snk(n,k),k=1..n)])
To pick a k, then use the above procedure RandSetPartition1(n,k) with that k
Added Oct. 26, 2020: The solutions of the students who kindly agreed to have them posted AND were perfect (or almost perfect) are in this directory
Lecture 15: Due Nov. 1, 9:00pm. Email ShaloshBEKhad@gmail.com an attachment
hw15FirstLast.txt
Indicate whether it is OK to post
How many of these never go above x=y?
Start exploring ComboProj3.txt, and use it to find the first 20 terms of of the sequence enumerating walks from [0,0,0] to [n,n,n] with atomic steps {[1,0,0],[0,1,0],[0,0,1],[1,1,1]}. What is the corresponding sequence for those walks that stay in x ≥ y ≥ z ?
Added Nov. 2, 2020: The solutions of the students who kindly agreed to have them posted AND were perfect (or almost perfect) are in this directory
Lecture 16: Due Nov. 1, 9:00pm. Email ShaloshBEKhad@gmail.com an attachment
hw16FirstLast.txt
Indicate whether it is OK to post
Using procedure Findrec in ComboProject4.txt find a linear recurrence operator annihilating it (equivalently a recurrence) and the initial condition, and write procedure S6seqClever(N) that uses procedure SeqFromRec from the same Maple package to do the same thing as S6seq(N).
What are
time(S6seq(1000));
and
time(S6seqClever(1000)); ?
Added Nov. 2, 2020: The solutions of the students who kindly agreed to have them posted AND were perfect (or almost perfect) are in this directory
Lecture 17: Due Nov. 8, 9:00pm. Email ShaloshBEKhad@gmail.com an attachment
hw17FirstLast.txt
Indicate whether it is OK to post
Don't do it directly! Use Findrec followed by SeqFromRec.
Don't do it directly! Use Findrec followed by SeqFromRec.
Sum(binomial(3000,k)^2*binomial(3000+k,k)^2,k=0..3000)
Don't do it directly! Use Z and then use SeqFromRec.
1/(1-4*x-5*y+11*x*y)
Don't do it directly!
Added Nov. 9, 2020: The solutions of the students who kindly agreed to have them posted AND were perfect (or almost perfect) are in this directory
Lecture 17a: Due Nov. 8, 9:00pm. Email ShaloshBEKhad@gmail.com an attachment
hw17aFirstLast.txt
Indicate whether it is OK to post
Use Wikipedia (or otherwise) to find the final outcome of the electoral votes for the presidential elections for 2000, 2004, 2008, 2012, and 2016, and find the number of ways in which it could have been counted to lead to the final outcome, by using the appropriate procedures in ComboProject8.txt.
Added Nov. 9, 2020: The solutions of the students who kindly agreed to have them posted AND were perfect (or almost perfect) are in this directory
Lecture 18: Due Nov. 15, 9:00pm. Email ShaloshBEKhad@gmail.com an attachment
hw18FirstLast.txt
Indicate whether it is OK to post
Generalize procedure NuConG(N) of M18.txt to write a procedure
NuKcomponentsGraphs(N,K)
that inputs a positive integer N and another positive integer K and outputs the first N terms of the sequence
enumerating the number of labeled graphs on n vertices with Exactly K componets. Make sure that
NuKComponentsGraphs(N,1) equals NuConG(N) for N ≤ 6
Hint: Of course, you first need to write a procedure AllKcomponentsGraphs(n,K) by tweaking procedure AllConGraphs(n)
and change the line nops(CCs(s))=1 to nops(CCs(s))=k
Are the following sequences in the OEIS? If yes, what are the A-numbers
NuConGgen(5,2), NuConGgen(5,3)
Using procedures RandGr(n,K) and CCs(G), in M18.txt
write a procedure
AveNuCC(n,K,M)
that generates M random graphs on n vertices with K edges, and for each of them finds the number of components and take the average over these M random graphs. Run it several times with n=30 and M=1000 to check that you get close answers. If not what M would give such agreement?
EstimateCutOff(n,M)
that inputs a positive integer n and outputs an estimate for the "threshold" for K, when most graphs with K edges start to be connected (say when the average number of connected componets is less than 1.05)
Lecture 19: Due Nov. 15, 9:00pm. Email ShaloshBEKhad@gmail.com an attachment
hw19FirstLast.txt
Indicate whether it is OK to post
a(n)=n*(n-1)*(n-2) (n ≥ 0)
(ii) How many sets {SP1,SP2} where SP1 and SP2 are set-partitions of different sets whose total numbers is 100 and the labels are {1, ..., 100} ?
[Reminder the egf of set-partitions is exp(exp(x)-1) ]
Lecture 20: Due Nov. 22, 9:00pm. Email ShaloshBEKhad@gmail.com an attachment
hw20FirstLast.txt
Indicate whether it is OK to post
(i) There are exactly 7 components, and each component has odd size
(ii) There are exactly an odd number of components, but the sizes of the components can be any strictly positive integer
(iii) There are exactly an odd number of components, but the sizes of the components can be any strictly positive integer except that we do not allow componets of size 2 and 5
(i) There are exactly 7 cycles, and each cycle has odd size
(ii) There are exactly an odd number of cycles, but the length of the cycles can be any strictly positive integer
(iii) There are exactly an odd number of cycles, but the lengths of the cycles can be any strictly positive integer except that we do not allow cycles of length 2 and 5
How many labeled connected graphs are there with 100 vertices? How many are there with exactly 2 components? With exactly 100 components?
Lecture 21: Due Nov. 22, 9:00pm. Email ShaloshBEKhad@gmail.com an attachment
hw21FirstLast.txt
Indicate whether it is OK to post
EstimateCutOff(n,M)
by simulating it M times, and using as cutoff 1.05. Procedure FindCutOff(n,co) in
does it EXACTLY, for an arbitrary parameter co (formerly I asked you to take 1.05).
Comparee the output of the simulated procedure with the exact one, i.e. compare your EstimateCutOff(30,1000) with my exact FindCutOff(30,1.05)
EstProbConn(n,m,N):
and write a procedure
EstProbKcomps(n,m,k,N):
that estimates the probability that a random graph with n vertices and m edges has exactly k components, by sampling N such random graphs.
Note that EstProbKcomps(n,m,1,N) is exactly the same as EstProbConn(n,m,N) (except, since we are doing simulations, you get different answers each time)
ProbConn(n,m):
To write a procedure
ProbKcomponents(n,m,k)
that uses the method of exponential generating functions to find the EXACT probability that a random graph with n vertices and m edges has k components. Note that ProbKcomponents(n,m,1) is EXACTLY the same as ProbConn(m,m,1)
[Hints: (i) you may need to write another procedure generalizing one of those that I wrote and that was used in ProbConn(n,m). (ii) the egf of labeled graphs with n vertices and k components with keeping track of the number of edges (i.e. the weight-enumerator according to the weight anumber of edges) is
(log(Sum((1+a)^(n*(n-1)/2)*x^n/n!,n=0..infinity))^k/k!
How does ProbKcomponents(40,50,2) differ from EstProbKcomps(40,50,2,300)?
Lecture 22: Due Dec.6, 9:00pm. Email ShaloshBEKhad@gmail.com an attachment
hw22FirstLast.txt
Indicate whether it is OK to post
[Added Nov. 30, 2020: The procedure TreeSeqL(N,t) counts ROOTED labelled trees, according to the number of leaves, and not as (possibly) stated erroneously in the lecture, unrooted trees].
Output SeqRTchild(S,30) for the following sets S if it is in the OEIS, state the A-number. If it is not, say so.
(i) S={1,2}
(ii) S={1,2,3}
(iii) S={1,2,3,4}
(iv) S={1,3,4}
(v) S={2,3,4}
Output SeqRTchildNone(S,30) for the following sets S if it is in the OEIS, state the A-number. If it is not, say so.
(i) S={1,2}
(ii) S={1,2,3}
(iii) S={1,2,3,4}
(iv) S={1,3,4}
(v) S={2,3,4}
(i) Estimate the limit of the average number of leaves in a labelled tree with vertex n divided by n
(ii) Estimate the limit of the standard-deviation of the number of the random variable ` number of leaves in a labelled tree with vertex n', divided by n
The third, fourth, fifth, and sixth scaled moments
Lecture 23: Due Dec.6, 9:00pm. Email ShaloshBEKhad@gmail.com an attachment
hw23FirstLast.txt
Indicate whether it is OK to post
By typing
time(RandTree(2000));
several times, and your own
time(RandTree1(2000));
the same number of times, find out
who is faster. Can you explain why?
[Hint: use RandTree(T), K times, finding the number of leaves (using nops(Leaves(T))]
Run EstAveLeaves(100,1000) several times. How close is it to 99/exp(1)? (that we got exactly in Lecture 22)
[Hint: First write a function Path(T,i,j) that inputs a tree T (given as a set of edges) and two vertices i and j, and outputs the unique path that joins i and j. For example, Path({{1,2},{1,3},{1,3}},2,4); should output [2,1,4] and Path({{1,2},{1,3},{1,3}},2,2); should output [2]. Then the skeleton of the doubly rooted tree T,[a,b] (the output of Joyal(f)) is Path(T,a,b). Then use CtoL to get a collection of cycles, that would give you how f acts on members of the cycles. Then restore the edges that are not part of the skeleton, but now they have directions, and this would give you the rest of the function f].
Lecture 24: Due Dec.13, 9:00pm. Email ShaloshBEKhad@gmail.com an attachment
hw24FirstLast.txt
Indicate whether it is OK to post
(ii) How many (integer) partitions are there of 97 where the the difference between consecutive parts is at least 3?
pnDC(n,d,C,m)
that inputs a positive integer n, a non-negative integer d, a set C that is a subset of {0,..., m-1} and a positive integer m and outputs the NUMBER of partitions of n such that the difference of two consecutive entries is at least d, and each entry mod m belongs to C.
(i) Check that pnDC(n,0,C,m) gives the same output as pnC(n,C,m) and pnDC(n,d,{0},1) give the same output as pnD(n,d)
(ii) Use it to find the first 40 terms of the sequence enumerating partitions that are both odd and distinct. Is it in the OEIS? If it is, What is the A-number?
(iii) Use it to find the first 40 terms of the sequence enumerating partitions such that the difference between consecutive entries is at least 2, and each entry gives remainder 1 or 4 when divided by 5. Is it in the OEIS? If it is, What is the A-number?
1/((1-q)*(1-q^2)*(1-q^3)*....)
To prove that the generating function of the sequence enumerating distinct partitions is
(1+q)*(1+q^2)*(1+q^3)*... =Product(1+q^i,i=1..infinity)
1/((1-q)*(1-q^3)*(1-q^5)*....)=Product(1/(1-q^(2*i+1),i=0..infinity)
By combining the above two problems, prove Euler's theorem that for every n, the number of partitions of n into odd parts, equals the number of partitions of n into distinct parts.
Added Dec. 14, 2020: The solutions of the students who kindly agreed to have them posted AND were perfect (or almost perfect) are in this directory
Lecture 25: Due Dec.13, 9:00pm. Email ShaloshBEKhad@gmail.com an attachment
hw25FirstLast.txt
[[6,5,3,1,1,1,1,1],-1]
Check it against BZ([[6,5,3,1,1,1,1,1],-1])
pnFast(10000);
You would get an error message. Why?
But if you do
[seq(PnFast(i),i=1..10000)][10000];
you would get the answer. Why?
Use this way to find the number of partitions of 20000. How far can you get?
pnFastMod(n,m)
that outputs p(n) mod m. What is
pnFast(10^5,101)?
Write a procedure, InvGlashier(M) that inputs a partition into odd parts and outputs a partition into distinct parts such that
InvGlashier(Glashier(L))=L
For each partition L into distinct parts and
Glashier(InvGlashier(M))=M
For each partition M into odd parts.
By using this gem, or otherwise program the inverse of Sylvester's bijection, Syl(L), call it InvSyl, such that InvSyl(Syl(L))=L for each odd partition L and Syl(InvSyl(D))=D for each distinct partition D.
Added Dec. 14, 2020: The solutions of the students who kindly agreed to have them posted AND were perfect (or almost perfect) are in this directory