20-CS-4003-001 Organization of Programming Languages Fall 2017
Streams

Lambda calculus, Type theory, Formal semantics, Program analysis

All lectures
Data Driven Solutions to Selected Problems

Hamming's Problem: (Applet)
Given a list P of prime numbers in increasing order, output a list L of integers, in increasing order, such that for every integer X in L, all the prime factors of X are members of P and every integer not in L has at least one prime factor that is not in P.

Example:     If P = { 3,5,11 }     Then L = { 3,5,9,11,15,25,27,33,45,55,...}

Documentation: hamming solution

slow-ham.c Generate and test solution to Hamming's problem (very slow).
Stream.java Threaded Stream class, used by S1.java and Hamming_0.java.
S1.java Data driven solution to Hamming's problem, in Java, with Threads.
Hamming_0.java Alternative to the above, slightly improved.
hamming.cc A C++ data driven solution without Threads using classes as closures.
    bigint.cc Homemade BigInteger support for hamming.cc.
    bigint.h Include file for bigint.cc and hamming.cc.
    Makefile Makefile for hamming.cc, bigint.cc, bigint.h.
StreamC.java Unthreaded Stream class for use by Hamming_1.java and Hamming_2.java.
BIArrayC.java Big Integer array class used by Hamming_1.java and Hamming_2.java.
Hamming_1.java Java data driven solution mimicking hamming.cc (no Threads).
Hamming_2.java An application version of the above.
hamming.hs Haskell data driven solution (uses streams)

Topological Sort     
Given a set N of Nodes, each having a dependency set M of Nodes which is a subset of N. Find a linear order L for the Nodes of N such that every Node exists in L after all nodes in its dependency list MM. Such a linear order is called a topological sort of the partial order described by the Nodes and their dependency sets.

Example:   If N = {1,2,3,4}   and M(1) = {2,4}, M(2) = {4}, M(3) = {1}, M(4) = {}   Then L = [4,2,1,3].

topo.pdf Powerpoint demo of the operation of the code below.
topo.cc Data driven C++ solution without Threads.
Topo.java Java data driven solution to topological sort using Threads.
topo.dat     topo.0.dat     topo.1.dat     Data files - download to home directory.

Stirling Numbers     
Stirling numbers are defined recursively as follows:
    S(m,n) = S(m-1,n-1) + m*S(m,n-1);
    S(0,n) = 0;
    S(1,n) = 1;
    S(n,n) = 1;

Example:   S(1,10)=1, S(2,10)=511, S(3,10)=9330, S(4,10)=34105, S(5,10)=42525

stirling.cc Data driven C++ solution without Threads.
Stirling.java Data driven Java solution without Threads.

Fibonacci Numbers     
Fibonacci numbers are defined recursively as follows:
    F(n) = F(n-1) + F(n-2);
    F(0) = 1;
    F(1) = 1;

Example:   F(2)=2, F(3)=3, F(4)=5, F(5)=8, F(6)=13

Fibon.java Data driven Java solution with Threads.