Last update: Oct. 31, 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 cupying-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 decompostion 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 interset S| + |C interset L| + |C interset K| + |S interset L| + |S interset K| + +|L interset K| )
+( |C interset S intersect L| +|C interset S intersect K| +|C interset K intersect L| +|S interset 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 derargment 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(statemnet)=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 ( Prodcut( 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..infiniy)
[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 sequenes of any length whose entries are either 1 (mod 5) or 4 (mod 5) and that add up to 341
In a
compositon 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 LARGET 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 inegers S (where [0, ..., 0] is not allowed) and a positive ineteger 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) explicilty.
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 Canibals 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 canniabls 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 occurence 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 inetgers 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 squre-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-partion of {1, ..., n} where each of them has the same probability of being picked.
Hint: One way of doing it is first write a prelininary 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 partions 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 partion 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 ?
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)); ?
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!