Math 640: EXPERIMENTAL MATHEMATICS Spring 2011 (Rutgers University) Webpage

http://sites.math.rutgers.edu/~zeilberg/math640_11.html

Last Update: May 16, 2011.

Description

Experimental Mathematics used to be considered an oxymoron, but the future of mathematics is in that direction. In addition to learning the philosophy and methodology of this budding field, students will become computer-algebra wizards, and that should be very helpful in whatever mathematical specialty they are doing (or will do) research in.

We will first learn Maple, and how to program in it. This semester we will focus on ALGORITHMS, both general (complexity theory, trying to prove that P ≠ NP or at least get closer to it than people did before), but first learning what is a computation and what is a Turing Machine and other computational models (simulating them all in Maple). This would be one part. The other part will focus on a very specific kind of algorithms, sorting algorithms, in particular those useful in bioinformatics (and for sorting pancakes by flipping).

But the actual content is not that important, it is mastering the methodology of computer-generated and computer-assisted research that is so crucial for your future.

There are no prerequisites, and no previous programming knowledge is assumed. Also, very little overlap with previous years. The final projects for this class may lead to journal publications.

Volunteer tutors

The following Maple whizes volunteered to help novices with any questions about Maple Added March 27, 2011: PICK (OR SUGGEST!) A PROJECT

Diary and Homework

Programs done on Thurs., Jan. 20, 2011

Homework for Thurs., Jan. 20, class (due Jan. 24, 2011)

All homework should be handed-in on paper at the beginning of the next class.
  1. (For Novices only) Read and do all the examples, plus make up similar ones, in the first 30 pages of Frank Garvan's awesome Maple booklet. [Hand in a printout of two pages with sample commands]
  2. Find (experimentally!) the answer to Amer. Math. Monthly problem 11546, proposed by Kieren MacMillan and Jonathan Sondow. If you feel like it, try and prove it rigorously.
  3. Write a program that inputs an "explicit" (i.e. one given by an expression) C2 function and outputs the difference between the right side and left side of AMM Problem 11548 (proposed by Cezar and Tudorel Lupu) try it out for many functions and verify the claim empirically. If you feel like it, also prove it.
  4. (For experts only) Write a program that inputs a positive integer d and outputs all polynomials of degree ≤ d in x that satisfy the condition of AMM problem 11549.
    f(f(f(x)))-3f(x)+2x=0 .
    (i.e. replace "continuous" by polynomials of degree ≤ d .)
  5. (For everyone). Read and understand the wikipedia entry on Boolean Logic

Programs done on Monday, Jan. 24, 2011

Jan24.txt , Contains procedures

Homework for Monday, Jan. 24, class (due Jan. 27, 2011)

All homework should be handed-in on paper at the beginning of the next class.
  1. (For novices only) Read and do all the examples, plus make up similar ones, in the first 60 pages of Frank Garvan's awesome Maple booklet. [Hand in a printout of two pages with sample commands]
  2. (For novices only) The current procedure nCube(n) outputs the set of vertices of the n-dimensional cube, {t,f}^n. Write a more general program nCubeG(n,S) that inputs a two-element set S and outputs the set (with 2n elements) of all vectors of length n (expressed as lists), whose components are elements of S. Make sure that nCubeG(n,{t,f}); gives the same output as nCube(n);
  3. (For experts, optional challenge for novices) Write a more general program nCubeG(n,S) that inputs any set S and outputs the set (with |S|n elements) of all vectors of length n (expressed as lists), whose components are elements of S. Make sure that nCubeG(n,{t,f}); gives the same output as nCube(n);
  4. (For experts, optional challenge for novices) Write a program BF(n,SLP) that inputs a positive integer n and a straight-line program SLP (in the format that we are using, [1, ...., n, [Inst1, Inst2, ..., Instk]], where Inst1, Inst2 are "instructions" written as triplets, and outputs the "Boolean function" that it evaluates expressed as subset of nCube(n). (Recall that there is an obvious one-to-one correspondence between Boolean functions on n variables and subsets of the n-dimensional discrete unit cube:
    f-> {v; v in nCube(n), f(v)=true} ).

Programs done on Thursday Jan. 27, 2011

Jan27.txt , Contains the procedures of Jan24.txt as well as the following new procedures:

Homework for Thurs., Jan. 27, class (due Jan. 31, 2011)

All homework should be handed-in on paper at the beginning of the next class. Note: I thank David Wilson for pointing out errors in the previous version (when I said "conjunctive normal form" I meant "disjunctive normal form")
  1. (For novices only) Read and do all the examples, plus make up similar ones, in pages 60-90 of Frank Garvan's awesome Maple booklet. [Hand in a printout of two pages with sample commands]
  2. (For experts, an optional challenge for novices) A boolean function in disjunctive normal form (DNF) has the form
    Z1 OR Z2 OR Z3 ...
    where Z1,Z2 are "products" of "literals" (xi or its negatin NOT xi) . For example
    (x1 AND (NOT x2) AND x3) OR ( (NOT x1) AND x2) OR ( (NOT x1) AND (NOT x3)) By comutativity we can represent such clause as a set of integers with a positive integer i representing the varibale xi and the negative integer -i representing its negation NOT xi , and the whole expression as a set of such sets. For example the above Boolean expression can be written as
    {{1,-2,3},{-1,2},{-1,-3}}
    Write a Maple procedure, DNFtoBF(n,DNF), similar to BF(n) that inputs a positive integer n and a Boolean expression in Disjunctive Normal Form and outputs the Boolean function it represents as a subset of nCube(n).
  3. (A Challenge for everyone) Write a Maple procedue BFoDNF(n,f) that inputs a Boolean function of n variables,f, given in terms of its truth vectors, as a subset of nCube(n), and outputs a disjunctive normal form that represents it.
  4. (for experts, an optional challenge for novices) Write a program that inputs positive integers n and m and outputs a random Boolean expression in Disjunctive Normal Form with m clauses, where each clause has exactly three different literals.

Programs done on Monday Jan. 31, 2011

Jan31.txt , Contains the procedures of Jan27.txt (and of course Jan24.txt) as well as the following new procedures:

Homework for Monday, Jan. 31, class (due Feb. 3, 2011)

All homework should be handed-in on paper at the beginning of the next class.
  1. (For novices only) Read and do all the examples, plus make up similar ones, in pages 90-120 of Frank Garvan's awesome Maple booklet. [Hand in a printout of two pages with sample commands]
  2. (For everyone) Read and understand the first two pages of Uri Zwick's article that I handed-in today.
  3. (For experts, optional challenge for novices) Procedure nCube(n) inputs a pos. integers and outputs the set of all vectors with n components consisting of {false, true}. Write a procedure nCubeList(n) that outputs all these vectors arranged in alphabetical order (f before t).
  4. (Challenge for everyone, $2 to be divided among correct solutions) Write a similar procedure, nCubeH(n) that also returns the list of all vectors, but in a Hamiltonian path way, in other ways, unlike the lexicgoraphic list, any two consecutive vectors in the list should differ in only one component. For example a legal output of nCubeH(2) could be
    [[f,f],[f,t],[t,t],[t,f]]
  5. Do some experimental mathematics with CNFs. Write a program CNFEx(n,m,K) that inputs positive integers n,m, and K, and generates K random 3-CNFs (i.e. CNFs where each clause has at most 3 literals), and then applies SAT(n,c) and counts what fraction out of these K CNF's is satisfiable.
  6. Using the previous procedure, write a super program Super CNFEx(n,M,K), that does the above for all m from 1 to M, and outputs the list of fractions of satisfiable CNF's for m from 1 to M. What is the output of
    CNFEx(5,100,1000);?
    CNFEx(10,100,1000);?
    Can you find some trends?

Programs done on Thurs. Feb. 3, 2011

Feb3.txt , Contains the procedures of Jan31.txt as well as the following new procedures:

Homework for Thurs., Feb. 3, 2011 class (due Feb. 7, 2011)

All homework should be handed-in on paper at the beginning of the next class.
  1. [For everyone] A Boolean funcion is symmetric if permuting the variables does not change it. How many symmetric Boolean functions of n variables are there? Write a program that inputs n and outputs all symmetric Boolean functions, represented in our data structure, as a set of n-tuples of true-false.
  2. [For everyone] Finish up procedure DNFtoSLP1(n,s). Right now it only handles sets s (i.e. clauses) with two elements.
  3. [For experts, challenge for novices] WriteDNFtoSLP(n,S), by "combining" SLPs by renumbering the gates, and then ORING the respective output gates (the last gate in each of the SLPs obtained from DNFtoSLP1(n,s)
  4. [For experts, challenge for novices] Define a "world history" as a list of m Eves nmumbers 1, ..., m and n Adams numbered 1 ... n, where people never die. At any given time any Female can mate with any Male and produce either a new Male or a new Female. Represent the world history as a list of triples where [1,i,j] or [-1,i,j] where 1 means Female and -1 means Male, and i is the Mother and j is the father, and i and j are already living people. Of course i should be Female and j should be Male. For example
    [1,-1,[-1,1,2],[-1,1,2],[1,1,2],[1,1,4]]
    is a world history with six people. One Eve, One Adam. The first two children of Adam and Eve were boys, and the third one was a girl. Then Adam mated his second daughter and a boy won born, the sixth oldest person in the world.

Programs done on Monday, Feb. 7, 2011

Feb7.txt , Contains the procedures of Feb3.txt as well as the following new procedures:

Homework for Monday, Feb. 7, 2011 class (due Feb. 10, 2011)

All homework should be handed-in on paper at the beginning of the next class.
  1. Write procedure DNFtoSLP(n,S), by iteratively "marrying" the SLPs generated by DNFtoSLP1(n,s) for the members s in S.
  2. Write a program RandBF(n,K) that inputs positive integers n and K (between 0 and 2n) and outputs a random Boolean function on n variables, and K truth-points.
  3. Read carefully pages 119-123 of Chapter 5 of Ingo Wegener's book that I handed-in today.
  4. Read carefully the wikipedia entry on Quine-McCluskey algorithm
  5. [Challenge for everyone!] Implement the Quine-McLuskey algorithm.
      Write a Maple program that inputs a Boolean function (as a set of n-vectors of t's and f's) and outputs the set of all prime implicants. Represent a prime implicant as we do, as a set of integers in {1,..n, -1, ..., -n} where i denotes xi and -i denotes NOT xi.
    1. Using the above program to constuct the matrix, expressed as a list of lists, such that with rows labelled by prime implicants and columns by members of the Boolean function (the n-vectors of t's and f's) such that L[i][j]=1 if the jth truth vector lies in the ith prime implicant [thanks to David J. Wilson for a correction!]
    2. [Challenge squared!] Write a program that inputs a Boolean function and outputs as simple as possible DNF for it.

Programs done on Thursday, Feb. 10, 2011

Feb10.txt , Contains the procedures of Feb7.txt as well as the following new procedures:

Homework for Thursday, Feb. 10, 2011 class (due Feb. 14, 2011)

All homework should be handed-in on paper at the beginning of the next class.
  1. Some of you have already met the challenge of writing your own Quine-McLuskey implementation, but continuing with what we did in class, use Implicants(n,f) to write a program PrimeImplicants(n,f) that inputs a positive integer n and a Boolean function f, and outputs the list whose i-th item is the set of prime implicants of dimension i-1. (Hint, the last entry of Implicants(n,f) (that is non-empty) consists of all prime implicants. Any superset of any of these that happen to reside on one of the entries to the left is automatically not prime, so you can kick them out. Keep going from right to left.
  2. Write a program, QM(n,f) that inputs a pos. integer n and a Boolean function f, and outputs a (hopefully) optimal or near-optimal minimal DNF for it. (Hint: of course it is a subset of the set of prime implicants. If there are points (alias truth-vectors) that are only contained in ONE prime implicant, the corresponding prime-implicant should be definitely picked. Once you picked these prime implicants (containing at least one point that does not have any other affiliations), look at the remaining one, and use a greedy algorithm to cover, at each step, as many as possible points of the Boolean function.
  3. choose(nCube(n),a) will give you all the Boolean functions of n variables with a truth vectors. Write a program, ImplicantAve(n,a,i) that inputs a positive integer n, a positive integer a between 1 and 2n, and a positive integer i between 0 and n, and finds the average number of i-dimensional implicants (NOT prime implicants) amongsts all such Booean functions. Of course Implicants(n,a,0) should always be a.
  4. ($5 to be divided among all correct entries) Using the numerical output of ImplicantAve(n,a,i) for various (small, and not small, n, a, and i=1,i=2, i=3...) Conjecture an explicit (closed form) expression for ImplicantAve(n,a,i).
  5. ($10 to be divided among all correct entries) Use human ingenuity to prove your conjecture rigorously.

    Added Feb. 14, 2011: Congratulations to Matthew Russel and C.K. Lee for winning these prizes. They each get (5+10)/2=7.5 dollars! Read Matthew Russel's pretty proof (here is Matthew Russel's testing), and CK Lee's pretty proof .

  6. (Three chocolate Valentines for the three best entries, to be posted here) Every year, before Feb. 14, 2011, I assign a problem, due Feb. 14, 2011, whose solution is shaped like a Valentine (but the students do not know that). So I make up problems whose solutions are sometimes a Cardioid, and sometimes the Mandelbrot set, and then I ask students to print the shape up and cut it out, and submit it as mandatory homework. This year I ran out of ideas, so here is a contest for the best entry, using Boolean functions (?) or otherwise whose answer is either one of the two above shapes, or another Valentine-like shape.

Programs done on Monday, Feb. 14, 2011

The program file has gotten to big to handle. I have converted it into a Maple package with built-in help Boole.txt. I have added a few more procedurs, making progress on Quine-Mcluskey, but not yet finishing it. I hope that we can finish it next time.

Homework for Monday, Feb. 14, 2011 class (due Feb. 17, 2011)

  1. Study the new procedures: PrimeImplicants and QMCrucial in the Maple package Boole.txt. Note that QMCrucial returns the crucial subset of the the set of prime implicants, that must be there, followed by the left-over points (not covered by these), and the left-over prime-implicants. Try to understand what is going on.
  2. [Challenge] Think of a greedy algorithm that takes the left-over prime implicant that covers the most of new points each time, until it runs out of points, and RETURNS a simplified DNF for the input Boolean Function.
  3. [Challenge] A Brute-force approach to the same problem, that guarantees optimality (alas at an exponential cost) is to examine all possible subsets of the set of left-over prime implicants (if there m prime implicants, there 2-1 possible non-empty sets. Find out which of these cover the left-over points, and amongsts those that do cover all these points, pick the "cheapest" one.
  4. Check empirically as many as possible of the Amer. Math. Monthly problems I handed in today from the Feb. 2011 issue.
  5. [up to $5 prize for EACH] Try to prove, using Maple, rigorously as many of these problems. If you cheat and use paper-and-pencil and/or human ingenuity, you may get a part of the $5.

Programs done on Thursday, Feb. 17, 2011

Today we started a new package PIE.txt, using Inclusin-Exclusion arguments to prove satisfiability (or rather the complement problem, deciding when a given DNF is a tautology). So far we only have:

Homework for Thurs., Feb. 17, 2011 class (due Feb. 21, 2011)

  1. Using AND1(C1,C2,n) repeatedly write a procedure AND(L,n) that inputs a list of AND-clauses and outputs
    L[1] AND L[2] AND ... L[nops(L)]
  2. write an adaptation of PIE(L), PIEdnf(n,S) that inputs a pos. integer n and a DNF S, expressed as a set of AND-clauses (each of which is a set of positive and negative integers, of course without any integer co-habiting with its negative) and outputs the NUMBER of truth-vectors (alias points in the n-dimen. unit cube) that belong to it divided by 2n. (Hint: instead of nops you have the weight of a clause, that is (1/2)nops(Clause). Indeed, the fraction of points in a DNF with one literal (e.g. x1 is 1/2), in two literals is 1/4 etc.
  3. Using PIEdnf(n,S) write a one-line program IsTaut(n,S) that inputs a pos. integer n and a DNF S and outputs true iff S is a tautology.
  4. By using RandDNF(n,m) of Boole.txt for many n and m, and DNFtoBF(n,S), experiment to see what is faster? IsTaut(n,S) or evalb(DNFtoBF(n,S)=2^n)
  5. [$10 prize] Write a procedure P11552(); that uses the many procedures of RENE to prove Amer. Math. Monthly 11552. If I like it, it would be added to the next version of RENE, and your name(s) would be mentioned.

Programs done on Monday, Feb. 21, 2011

We continued and have a new version of PIE.txt, with the following new procedures:

Homework for Mon., Feb. 21, 2011 class (due Feb. 24, 2011)

  1. Write a new version of RandDNF(n,m), call it RandDNF3(n,m) that inputs pos. integers n and m and outputs a random DNF in n variables and exactly m clauses (expressed in our format as a set of sets) where each clause (member set) has exactly three literals. For example, you can't have 2-clauses, like {1,-2}, and 1-clauses, like {3}. Of course, you should not have i and -i in the same clause (e.g. {3,-3,1} should not be allowed). For example one possible output of RandDNF(3,4) could be:
    {{1,-2,3},{-1,2,3},{1,2,3},{1,2,-3}}.
  2. Write a program TestPIEdnf(n,m,K) that inputs pos. integers n,m, and K, and generates, K times, a random 3-DNF, and runs PIEdnf on it. It should output the number of 3-DNF's that are tautologies, and the number that are not (obviously they should add up to K). Fix n=4, and experiment for m between 1 and 15. How does this number change?
  3. Modify PIEdnfF(L,n), call it PIEdnfF1(L,n), that also returns the i, i.e. stage in the Inclusion-Inclusion where we quitted for sure with either knowing that it is a tautology or not.
  4. Write a program TestPIEdnfF1(n,m,K,x) that inputs pos. integers n,m, and K, and generates, K times, a random 3-DNF, and runs PIEdnfF on it, and outputs the number of 3-DNF's that are tautologies, and the number that are not (obviously they should add up to K), and a list, let's call it M, such that M[i] is the number of 3-DNFs that exited at stage i of the PIE.
  5. Shame on you for not reading carefully and understanding both two proofs demanded in the pop-quiz (about half of you were able to reproduce the first proof). Please read and understand pages 119-123 in Ingo Wedener's book "The Complexity of Boolean Functions" that I handed in a few weeks ago. (There will be another pop quiz, sometime in the future, and I hope that you will do better next time!)
  6. Read pp. 47-50 of the Bill Gates and Christos Papadimitriou masterpiece as well as the complete Colvey Roney-Dougal and Vince Vatter's awsome article

Programs done on Thursday, Feb. 24, 2011

We started a new package FP.txt, to study flipping panckages. So far it contains the following procedures (that many of your wrote yourself, but here is the official version, contributed by David J. Wilson)

Homework for Thurs., Feb. 24, 2011 class (due Feb. 28, 2011)

  1. Write a program Shells(n) that inputs a positive integer n and outputs a list whose i-th entry is the set of all permutations that can be reverse-prefix sorted with i steps (but not less). The union of all the entries of the output-list should be permute(n), and its nops (number of entries, i.e. its length) is the quantity f(n).
  2. Using the above procedure, with option remember, write a program, Bill(n,i), that inputs pos. integers n and i and outputs the number of permutations of length n that are prefix-sortable with i flips. See whether the sequences {Bill(n,1)}, {Bill(n,2)}, etc. are in Sloane.
  3. ($5) prove the generating function, attributed by Sloane to Flajolet, for the number of adjancency-less permutations.
  4. Read (and understand!) pp. 49-50 of the Bill Gates and Christos Papadimitriou masterpiece.
  5. Program the sorting in Fig. 1.

Programs done on Monday, Feb. 28, 2011

The first half of the class was "wasted" when students tried to follow my stupid approach to prove by computer Amer. Math. Monthly Problem 11558 (March 2011, vol. 118, p. 275, proposed by Amdrew McFarland)
Given four concentric circles, find a necessary and sufficient condition that there be a rectangle with one corner on each circle. As Susan Durst (and possibly other people), it is more efficient to start with the rectangle, and look at the distances (or rather distance-squared) from the center to the vertices.
We also wrote the short file Max.txt and compared the naive algorithm for finding the maximum of a list of numbers (see MaxSlow below) to a "fast" approach (see MaxFast below) that turned out, at least empirically, to be much slower. The two procedures are:

Homework for Mon., Feb. 28, 2011 class (due March 3, 2011)

  1. Use Susan Durst's (and Yu Wang's) approach for solving the above Monthly problem by first empirically conjecturing a necessary condition for the four distances-squared from a point (x,y) to a the four corners of a rectangle, that without loss of generality are the points (0,0), (a,0), (0,b), and (a,b), by writing a program P(a,b,x,y) that inputs four real numbers a,b,x,y and outputs the four-tuple of distances-squared. By plugging-in several spefic numeric values for a,b,x,y try and find the neccessary condition
  2. (5$ to be divided) by using human (and/or computer) ingenuity, prove rigorously that necessary condition, and also prove that it is sufficient.
  3. (5$, to be divided) analyze the computational complexity of MaxFast(L) and prove that Dr. Z. is stupid, and that the theoretical computational complexity of MaxFast is not any better than MaxSlow(L). It still remains to be understood, why it is so much slower.
  4. Write a program adj(pi) that inputs a permutation pi and outputs the number of adjancies of pi, where having the largest element at the end counts as an adjancency.
  5. Using adj(pi), write a heuristic greedy algorithm, GS(pi), for prefix sort, that hopefully would require less flips than NS(pi) (Naive sort), that inputs a permutation pi, and and alway chooses a flip in such a way as to increase the number of adjancies, if possible, and otherwise, picks at random a flip that does not decrease that number, and if even that is not possible (but it probably can never happen) picks at random any flip. Keep going until you have nops(pi) adjancies. The output is the list of places where the flip occurs.
  6. Write a program TestGS(n,K) that inputs a positive integer n and a positive integer K and picks K random permutations of length n, and finds the average and standard deviation of the number of flips outputted (i.e. nops(GS(pi))). What did you get for TestGS(10,1000)? For TestGS(20,1000)?

Programs done on Thurs., March 3, 2011

BC.txt containing the following procedures:

Homework for Thurs., March 3, 2011 class (due March 7, 2011)

  1. Let a[i] be the number of permutations on {1, ..., i} that allow a wasteless prefix sort (in other words, those pi for which WLS(pi) yields the identity permutation. Write a program nuWL(n) that inputs a positive integer n and outputs the first n terms of that sequence. Comute nuWL(8) and check whether it is in Sloane.
  2. Write a program aWLS1(pi,r) that inputs a permutation pi and outputs all the permutation that allow a wasteless sort until the r-th flip, then at the r-th flip, performs a flip that does not increase the number of adjancencies (but does not decrease it either), and then keep going with wasteless flips until it gets stuck (or gets completely sorted).
  3. Let b[i] be the number of permutations on {1, ..., i} that allow an almost wasteless prefix sort (i.e. it gets completey sorted by aWSLS11(pi,r) for some r between 1 and adj1(pi)+1) and that are not sortable with WLS(pi). Write a program nuaWL(n) that inputs a positive integer n and outputs the first n terms of that sequence. Comute nuaWL(7) and check whether it is in Sloane.
  4. Let t(pi) be the first element of a permutation pi, for example t([3,1,2,5,4])=3. Let B0(pi) be its first block, for example t([3,2,1,5,4])=[3,2,1], and t([2,3,5,1,4])=[2,3]. Let tp be the entry adjacent to the largest entry of B0(pi), and let tm be the entry adjacent to the smallet entry of B0(pi) (one of them is t+1 or t-1), let B1(pi) be the block containing tp and let Bm1(pi) be the block containing tm. Call the block B0(pi) block 0, the block B1(pi) block 1, and the block Bm1(pi), block -1. Of course block 0 must come first, but sometimes block 1 is to the left of block -1 and sometimes it is the other way. So the two possibilities are
    [0,1,-1] and [0,-1,1]
    Each individual block is either a singelton, increasing, or decreasing. Indicate this information by 0,1, and -1 respectively. If block i (i=0,1,-1) is increasing write this is as [i,0] etc. The type of a permutation is either
    [[0,c1],[1,c2],[-1,c3]] (where each of c1,c2,c3 belong to {-1,0,1})
    (when block 1 came to the left of block -1) or
    [[0,c1],[-1,c2],[1,c3]] (where each of c1,c2,c3 belong to {-1,0,1})
    (when block -1 came to the left of block 1) . If one of the blocks is non-existent (e.g. when the first block is the singelton 1 or the singleton n) then we only have either [[0,c1],[-1,c2]] or[[0,c1],[1,c3]]. Call these triple (or pair) of pairs the type of the permutation. Write a program, Type(pi), that inputs a permutation pi and outputs its type.

Programs done on Mon., March 7, 2011

Strassen.txt containing the following procedures:

Homework for Monday, March 7, 2011 class (due March 10, 2011)

  1. Modify NRP(a,b) and write a program CRP(a,b) (Clever Recursive product), using the deep identity
    ad+bc=(a+b)(c+d)-ac-bd
  2. By using time();, experiment, with very large integers a and b, (generated randomly) whether CRP(a,b) is significantly faster than NRP(a,b).
  3. (Small Challenge) Write a program RMP(A,B) that does matrix multiplication recursively, but using the obvious eight multiplications. Check whether it gives the same answer as MP(A,B)
  4. (Challenge, I'll be proud of you!) Look up (in wikipedia or elsewhere) the Strassen algorithm, that uses seven multiplication in every recursive step, and implement it.

    Added March 10, 2010: Quite a few people met the challenge. For example, see Simao Herdade's Strassen code

Programs done on Thurs., March 10, 2011

CB.txt containing the following procedures:

Homework for Thurs. March 10, 2011 class (due March 21, 2011)

Andrew Baxter pointed out that the approach that I suggested for WhatType(pi) and FindBlock(pi,a) was unnecessarily complicated. It is much better to do the following approach suggested by him.
  1. Write a procedure BreakUp(pi) that inputs a permutation pi and outputs the list of blocks. For example, BreakUp([5,4,1,2,7,6,3,9,8]); should return the list [[5,4],[1,2],[7,6],[3],[9,8]]
  2. Using BreakUp(pi) write a new version of WhatType(pi)
  3. Write a procedure Types(n) that inputs a positive integer n and outputs the set of possible types that permutations of [1,n] can have.
  4. Write a procedure HowMany(n) that inputs a positive integer and returns a table indicating how many permutations of {1, ..., n} belong to each of the types.
  5. Have a nice and relaxing Spring Break!

Programs done on Monday, March 21, 2011

Spring11.txt containing the following procedures:

Homework for Mon. March 21, 2011 class (due March 24, 2011)

  1. Procedure WhatType(pi) only tells you the relative placement of what we called "block +1" and "block -1", but why stop there. (Recall that block +1 consists of numbers that are just above the entries of block 0, and block -1 consists of numbers that are just below. One can define WhatType2(pi) that does the same for blocks +2,+1,-1,-2. Modify WhatType(pi), and write a procedure, WhatType2(pi), that outputs a list of (up to) length 5 that gives you this type2. For example, WhatType2([5,7,1,3,4,2,6]); should yield (I hope!) [[0,0],[2,0],[-1,1],[-2,0],[1,0]].
  2. Ditto for WhatType3(pi).
  3. (Challenge!) Write a program gWhatType(pi,a) that inputs a permutation pi and a pos. integer a, and outputs a list of size ≤ 2a+1 that describes the relative placments, and the status (singleton, increasing, or decreasing) of pi.
    gWhatType(pi,1) is the same as WhatType(pi), gWhatType(pi,2) is the same as WhatType2(pi), and gWhatType(pi,3) is the same as WhatType3(pi).
  4. Write a procedure BestFlips(n) that inputs a positive integer n, and outputs a table such for any permutation pi, of length n, T[pi] is an optimal sequence of flips. For example, if T2:=BestFlips(2), then
    T2[[1,2]]=[] and T2[[2,1]]=[2]
    If T3:=BestFlips(3) then
    T3[[1,2,3]]=[], T3[[2,1,3]]=[2], T3[[3,2,1]]=[3], T3[[312]]=[3,2], T3[[2,3,1]]=[2,3], T3[[1,3,2]]=[2,3,2] .

    (Hint: go backwards. Of course T[IdentityPermutation]=[], then gather those that are "distance 1" from IdentityPermutation, and record where the flip occurs, then those of "distance 2", not yet encountered etc.

Programs done on Thursday, March 24, 2011

Today' class is dedicated in loving memory of Philippe FLAJOLET (Dec. 1, 1948- March 22, 2011) (see also wiki) studying his great expository article on Singular Combinatorics (based on his ICM 2002 invited talk) and his seminal article on inherently ambigious formal languages.

Today we wrote the file flajolet.txt containing the following procedures:

Homework for Thurs. March 24, 2011 class (due March 28, 2011)

  1. Write procedure Test3(n), testing Example 2 on page 564 of Philippe Flajolet's article on Singular Combinatorics
  2. Write a procedure TestExample1(N) , testing Example 1 on page 564 of Philippe Flajolet's article on Singular Combinatorics
  3. Modify procedure Shar(N), call it Shark(N,k) to crank out the first N terms of the Maclaurin expansion of the unique formal power series
    f(z)=1+z*f(z)k
    (Note that Shark(N,2) is Shar(N))
  4. (Challenge!) Guess the asymptotic behavior a(n)=Cannβ of the sequence Shark(N,3), and Shark(N,4), except for the C.
  5. (Big Challenge!) Guess the asymptotic behavior a(n)=C*annβ of the sequence Shark(N,k), including the C! Prove it!
  6. Fix procedure s(z,N).
  7. (Challenge!) Write a procedure HNY09(N) that inputs a positive integer N, and verifies the correctness of Kν for ν=1...N, with the given dn in the infinite continued fraction on the right in Philippe Flajolet's lovely 2009 Happy New Year card (Note: as far as I know this is still a conjecture!)

Programs done on Monday, March 28, 2011

Today we wrote the file Mar28.txt culminating in a brute-force, but optimal, algorithm for prefix-sort. A slight modification produced Mar28a.txt that does the analogous job for stacks of burnt pancakes (alias signed permutations). The first file The second file contains all the above, adapated to signed permutation, except that f(n) and fSeq(N) have been renamed g(n) and gSeq(N).

Homework for Monday March 28, 2011 class (due March 31, 2011)

  1. Recall that a type is a list of pairs [i,j] where i is an integer, and j is either -1 (representing a decreasing block), 0 (representing a singleton) or 1 (representing an increasing block). For example
    T=[[0,-1],[1,1],[-1,0]].
    Define the padded-version of a a type PD(T) to be the same with 0-s inserted beween two consective pairs (but not at the beginning or end). For example,
    PD(T)=[[0,-1],0,[1,1],0,[-1,0]]
    Define the Sorted Version a rearrangent of the pairs such that Write a program IsSV(T,T1) that inputs a type T and a list T1 of pairs and 0s and outputs true if and only if T1 is a sorted version of PD(T).
  2. Adapt BFPF(pi) to write BFPFtype(T) that inputs a type, and outputs an optimal list of flips, applied to PD(T) that leads it to a sorted version.
  3. Translate the diagram on p. 50 of the Bill Gates and Christos Papadimitriou article into the new notation, and apply BFPFtype(T) to each of the sixteen types displayed, and check if your computer got the same things that Bill Gates got doing it by hand.

Programs done on Thurs., March 31, 2011

Today we wrote the file Mar31.txt that contains all the procedures of Mar28.txt, and in addition:

Homework for Thursday March 31, 2011 class (due April 4, 2011)

  1. Finish up BFTF by first finishing up SphereT, writing BallT (the type analog of Ball), and whatever it takes.
  2. [If you haven't done it already in the March 28, 2011 homework] Translate the diagram on p. 50 of the Bill Gates and Christos Papadimitriou article into the new notation, and apply BFTF(T) (formerly called BFPFtyle) to each of the sixteen types displayed, and check if your computer got the same things that Bill Gates got doing it by hand.
  3. (Chanllenge, 5 dollars to be divided among all correct answers to EACH problem) Do as many as possible of the American Mathematical Monthly problems of the April 2011 issue, using Maple as much as possible. It does not have to be completely computer-generated, but it would be nice if you use Maple experimentations to conjecture and/or suggest a solution.

    Added April 5, 2011: Andrew Baxter and Matthew Russell, independently solved David Callan's AMM probelm 11567, and shared a $5 prize. Read Andrew Baxter's brilliant solution. I hope to soon post Matthew Russel's equally brilliant solution.

    Justin Gilmer solved Kurt Bresniker and Stan Wagon's AMM problem 11569. I hope to post his solution soon.

Programs done on Monday, April 4, 2011

In the first part we had a belated celebration of "π day", exploring the amazing website of the later-day-Ramanujan, Jesús Guillera, and had a context who would code fastest the top formula in his hopepage. Andrew Baxter won 1 dollar, and Taylor Burmeister came second and won 25 cents. Matthew Russel also came close.

The second part was back to pancake flipping. Today we wrote the file Apr4.txt that completed the procedures of Mar31.txt and added a new one: GatesTypes():

Homework for Monday April 4, 2011 class (due April 7, 2011)

  1. Code the first formula in Jesús Guillera's amazing homepage. Try to get as many digits of Pi as possible.
  2. Code the second (still conjectured) formula in Jesús Guillera's amazing homepage. Try to get as many digits of Pi as possible.
  3. Write a new version of procedure WhatType(pi) that inputs a permutation pi and output its padded type, followed by a list of integers that constitute a "translation" between the blocks and their ending places. For example,

    WhatType([5,6,7,1,2,3,4]); should return
    [[0,1],[-1,1]],[3,7]

  4. (Challenge!) Using WhatType(pi) and BFTP(T), write a general sorting algorithm, PancakeSorting(pi,Types) and inputs a permutation pi and a list of Types, and outputs a sequence of flips that sorts it.

Programs done on Thursday, April 7, 2011

Today, we had the surprise visit of Michael Somos, one of the greatest experimental mathematicians alive today, and we exlored the amazing Somos Sequence. Then we continuted pancake flipping.

Homework for Thurs. April 7, 2011 class (due April 11, 2011)

  1. MANDATORY (anyone who does not submit it by April 11, would only get a B+ in the class) Write a Maple program that implements the breakpoint algorithm as described in Chapter 5 of the Jones-Pevzner book on informatics.
  2. MANDATORY (anyone who does not submit it by April 11, would only get an A- in the class) Complete procedure WhatTypeG(pi), and test it out.
  3. Using the completed WhatTypeG(pi), and using the BFTF(pi) of Apr4.txt write a perfix-sorting program that inputs a permutation pi, and outputs a list of places where to flip to make it the identity permutation, by first determining the type, then invoking BFTF, then transcribing the "meta-information" there into the actual places given by the second part of the output of WhatType(G) and keep going until the type is [[0,1]] (one increasing block).

Programs done on Monday, April 11, 2011

We attempted to write procedure PS3(pi) that inputs a permutation pi and outputs a list of filps indicating the places where one should flip to get the identity permutation, implementing and generalized and streamlined (and completely auotmatic!) Gates-Papadimitriou style prefix-sorting algorithm. The incomplete code is contained in the file Apr11.txt, that uses the following files At the last ten minutes we investigated the Monthly problem Kurt Bresniker and Stan Wagon's AMM problem 11569, brilliantly solved by Justin Gilmer. The short file is contained in Apr11a.txt,

Homework for Monday April 11, 2011 class (due April 14, 2011)

  1. Combine all the relevant procedures that are needed from the various files mentioned above, and use Emilie Hogan's ideas of keeping track of the block-lengths rather than the ending point, and finish up (or start from scratch) procedure PS3(pi). Call that ONE file MyNamePF.txt, (where MyName is your name, for example JakeBaronPF.txt) and if you are proud of it and it works well, EMail it to me, so that I can post it.
  2. Assuming that you have succeeded to program PS3(pi), write a Maple procedure, StatPS3(n), that inputs a positive integer n, and outputs (i) the largest number of necessary flips using PS3(pi), amongst all permutations pi of {1, ..., n} along with the set of "champions", as well as as the average number of flips, for all n! permutation. Find out the output for n between 2 and 8.
  3. (Challenge) By analyzing the data of LosingList(N) (for N=200 or whatever) in Apr11a.txt, repeat Justin Gilmer's feat of conjencturing, and then proving, a characterization of all losing positions.
  4. Read (and understand!) the first four pages of the Noga Alon-Ravi Boppana masterpiece.

Programs done on Thurs., April 14, 2011

We started studying antichains in the Boolean lattice (alias monotone Boolean functions) Apr14.txt, that uses the following files

Homework for Thurs. April 14, 2011 class (due April 18, 2011)

  1. A MSLP (Monotone Straight Line Program) on n variables and m non-input lines is a list of length n+m, such that the first n entries are x1, ..., xn, and entry k for n < k ≤ n+m is either a pair [i,j,UNION], or [i,j,INTERSECT] with i < j < k. The evaluation of such an MSLP is obtained by putting in location i (1 ≤ i ≤ n) the set of all 2n-1 sets that contain i, and then evaluating each line in its turn. The output is a certain set of sets that is monotone. Write a Maple procedure EvalMSLP(MSLP,n) that inputs such a monotone straight line program and outputs the monotone Boolean functions (expressed as a set of sets).
  2. Write a program ACtoMBF(AC) that inputs an antichain and outputs the corresponding monotone Boolean function
  3. Write a program MBFtoAC(AC) that inputs a monotone Boolean function (expressed as a set of sets) and outputs the corresponding antichain.

Programs done on Monday, April 18, 2011

Apr18.txt,

We started to implement the constuctions and definitions in the Noga Alon-Ravi Boppana masterpiece. (Combinaorica 7(1) (1987) 1-22), in particular page 5. So far we have the procedures:

Homework for Monday April 18, 2011 class (due April 21, 2011)

  1. A multiset is a set of pairs {[a1,i1],[a2,i2], ...} where i1,i2, ... ≥ 1, and this means that a1 shows up i1 times, a2 shows up i2 times .... Write an analog of choose(S,k), call is Mchoose(S,k) that inputs a finite set S and outputs the set of all multisets with k members. For example
    Mchoose({1,2,3},2);
    should return {{[1,2]},{[2,2]}, {[3,2]},{[1,1],[2,1]},{[1,1],[3,1]}, {[2,1],[3,1]}}
  2. Using Mchoose, write a new version of Clusure1 that does exactly what the Alon-Boppana article intends.

Programs done on Thursday, April 21, 2011

Apr21.txt, contains:

Homework for Thurs. April 21, 2011 class (due April 25, 2011)

  1. Using gNCP(L), write a program ExtremePrk(r,k) that uses procedure gNCP(L) to constant the family of all possible menu-choices from a k-course meal, where each course has (r-1) different dishes to choose from, and all the dishes are distinct.
  2. Check that ExtremePrk(r,k) has property P(r,k) for ALL 1 ≤ r ≤ 3 and 2 ≤ k ≤ 4
  3. Read and understand the proof of Lemma 3.2 on p.6 of the Alon-Boppana masterpiece.
  4. Verify empirically the statement that if F has property P(r,k) then FC (as defined in the proof of Lemma 3.2) has property P(r-1,k-|C|), by trying out various F.
  5. (Challenge) Using what we started in Apr18.txt, (but now using the Mchoose to make it complete), implement the closure algorithm, call is that inputs a collection C of sets and outputs its closure.

Programs done on Monday, April 25, 2011

Apr25.txt, contains:

Homework for Monday April 25, 2011 class (due April 28, 2011)

  1. Write a program, NuA(m,g,W,ListW): that inputs pos. integers g and m, a subset W, of {1, ..., m}, and a list of subsets of {1, ..., m}, ListW, and outputs the number of g-colorings of {1, ..., m} that makes (i) W Properly Colored (ii) None of the sets in ListW Properly by complete brute-force.
  2. By dividing by gm, write the analogous program for PrA(m,g,W,ListW), the probability that a random g-coloring of {1, ..., m} would have the enough specifications.
  3. Write a program RandCol(m,g) that inputs positive integers m and g, and outputs, uniformly at random, one g-coloring of {1, ...,m}, expressed as a list of m integers, each entry drawn from {1, ..., g}
  4. Write a program AppxPrA(m,g,W,ListW,K), that approximates PrA(m,g,W,ListW) by trying out, using RandCol(m,g) K times, and finding those for which (i) W Properly Colored (ii) None of the sets in ListW Properly and dividing by K.
  5. Experiment with various W's and ListW's (with at least three sets), and see well AppxPrA(m,g,W,ListW,K) approximates PrA(m,g,W,ListW);
  6. (Human mathematics): Given two subsets A and B of {1, ...,m} such that |A intersect Complememt(B)|=a, |A intersect B|=c, |Complement(A) intersect B|=b, find a closed-form formula (in terms of a, b,c, and g) for the probability that a (uniformly-at-) random g-colring of {1, ..., m} would make both A and B Properly Colored.
  7. Read and understand the statements and proofs of Lemmas 3.6 and 3.7, pp. 8-9, in: Alon-Boppana masterpiece.
  8. (Human mathematics, $5, to be divided)[corrected April 26, 2011, 12:32pm, thanks to CK LEE]: Given three subsets A1 and A2, A3 of {1, ...,m} such that (let C(S) be the complement of the set S)

    |A1 intersect A2 intersect A3|=a111,
    |A1 intersect A2 intersect C(A3)|=a110,
    |A1 intersect C(A2) intersect A3|=a101,
    |A1 intersect C(A2) intersect C(A3)|=a100
    |C(A1) intersect A2 intersect A3|=a011,
    |C(A1) intersect A2 intersect C(A3)|=a010,
    |C(A1) intersect C(A2) intersect A3|=a001,

    find a closed-form formula (in terms of a111, ..., a001, and g) for the probability that a (uniformly-at-) random g-colring of {1, ..., m} would make both A1, A2, and A3 Properly Colored.

Programs done on Thurs., April 28, 2011

Today we said good-bye to Boolean circuit complexity (but please go back to the Alon-Boppana masterpiece when you have a chance, read and re-read it, it is worth the effort!), and we followed the footsteps of my brilliant former PhD student Thotsaporn "Aek" Thanatipanonda who wrote the following masterpiece.

We started the following program, chess.txt, that contains procedures:

Homework for Thursday April 28, 2011 class (due May 2, 2011)

  1. Finish up procedure WMove(m,n,P), that inputs pos. integers m and n and a position P=[WK,WR,BK] and outputs the set of positions reachable from P on one move, if it is White's turn to move.
  2. Write procedure BMove(m,n,P), that inputs pos. integers m and n and a position P=[WK,WR,BK] and outputs the set of positions reachable from P on one move, if it is Black's turn to mov
  3. Write a procedure IsCheckMate(m,n,P) that returns true if position P is a CheckMate for Black, and false otherwise. (Recall that the Black King is CheckMated if it is threatended by the White Rook, and has no safe place to go).
  4. Write a procedure IsStaleMate(m,n,P) that returns true if position P is a Stalemate for Black (it is not threatened by the White Rook, but wherever it goes it would die)

What We did on May 2, 2011

I thank Andrew Baxter for reminding me of the Experimental Mathematics' class of 2009's great group project. Today we planned (outside, while sipping our coffees (5), teas(2), hot chocolate (1) lemonades(4) and water(1), and sharing 5 healthy (oatmeal raisin) and 5 junky (chocolate-chip) cookies) the class-project for this year's class: design and write a similar computer-generated webbook for Rectangular (m by n) Chess end-game problems (White to mate in k moves). The tentative deadline is June 3, 2011.

Here is the organizational chart:

Big bosses: Dr. Emilie Hogan and Dr. Andrew Baxter

Homework for Monday May 2, 2011

No homework, but a first, preliminary draft of the project is due May 10, 2011.


Added May 16, 2011: Here are the students' evaluations.
Added June 9, 2011: Here is the class's awsome group project to generate mini-chess end-game puzzles.
Dr. Z.'s teaching page