if(NO PROJECT PROPOSAL && NO WORKING CODE)
NO DEFENSE + NO GRADE
Submit your proposal this coming Saturday, July 30, 2011.
NO PROPOSAL NO DEFENSE basis.
Prepare a one-page proposal.
What to write?
-Project Description
-Web framework that you will be using
Example of projects: Online Contacts, Diary, File Repository, Gallery and other projects you want to build...
Read the doc on Final Project in this group to give you an idea of what to do.
As for an additional information for your project, your project is to build a website that is created using an Erlang web framework. There are many erlang web frameworks today like Chicago Boss, Erlang Web, Nitrogen and etc. You have the freedom to choose on your own but I will encourage you to choose Erlang Web since it is up to date.
Do not waste your time so that you have more time to study and complete your project on time.
Erlang Web - http://www.erlang-web.org/
Chicago Boss - http://www.chicagoboss.org/
Nitrogen Project - http://nitrogenproject.com/
------------
Study your assignment because I will be giving you a grade of ZERO if you have no idea of what you are submitting.
It is a ONE ON ONE defense, one student at a time and the rest will wait.
You are given 10 minutes to explain. I will ask you about your code.
NO DEFENSE/NO SCORE if your code is not running.
CSc 102 – Computer Programming II augments the topics covered in CSc 101. It introduces functional programming and then progresses to more advanced topics: multi-core systems and concurrency, parallel programming and models of computing (client-server, peer-to-peer, and distributed systems), using the Erlang programming language.
Wednesday, July 27, 2011
Thursday, July 21, 2011
Pre-Prelim Exercise
As part of the requirement for the Prelim Exam, you have to submit a hardcopy of the Fibonacci and the Mobius problem and will have a defense on the class.
This will serves as your assignment and at the same time will cover the 20% of your written prelim exam. This is also worth 200 pts. This is no working solution no score basis. You score will be based on your answer and the correctness of your solution.
So, please make sure that you did your assignment and have a thorough understanding of it. Thanks.
Thank you for your participation.
Saturday, July 16, 2011
Assignment Revisited
Redo your first assignment on Fibonacci and Mobius problem. This assignment will practice on doing recursive functions. Make sure that you understand what are you submitting in the class.
- Apply your knowledge on recursion both tail recursion and non-tail recursion.
- Include in your submission a test case for every function you have implemented. Maybe a printscreen of your work. Make sure that they will work before doing next instructions. Do not proceed if your function will fail.
Note: I just want you to practice the language and I hope that you will appreciate the language. I know it is quite difficult to learn functional programming. Even me I sometimes forgot the syntax but I do understand what behind its design and implementations. So, please participate and you will pass the course. That's all what I need from you. Focus and participation.
- Apply your knowledge on recursion both tail recursion and non-tail recursion.
- Include in your submission a test case for every function you have implemented. Maybe a printscreen of your work. Make sure that they will work before doing next instructions. Do not proceed if your function will fail.
Note: I just want you to practice the language and I hope that you will appreciate the language. I know it is quite difficult to learn functional programming. Even me I sometimes forgot the syntax but I do understand what behind its design and implementations. So, please participate and you will pass the course. That's all what I need from you. Focus and participation.
Tuesday, June 28, 2011
Updates on your Grading System
Please take note the following changes of your grading system.
Homework/Quizzes 20%
Exams 50%
Laboratory MPs 20%
Final Project 10%
Saturday, June 25, 2011
Homework: Recursive Function in Erlang
1. Fibonacci
For this part you will create several implementations of the Fibonacci function fib(N), which returns the Nth value in the Fibonacci sequence.Make sure to follow this specification for fib(N):
- fib(0) = 0
- fib(1) = 1
- fib(N) = fib(N - 1) + fib(N - 2) (N > 2)
Your Tasks
- Create a module named "fib", in the file "fib.erl".
- Create a non-tail-recursive function fib_p that takes a single argument N, and returns the Nth value in the Fibonacci sequence. Use pattern matching on the arguments to specify the various cases for this function.
Add fib_p to your module's export-list, and test it to make sure it works properly.
- Create another non-tail-recursive function fib_g with the same specification as before, but use guards (i.e. when clauses) to specify the various cases for this function.
Add fib_g to your module's export-list, and test it to make sure it works properly.
(There should be no difference in performance between fib_p and fib_g; implementing both of them will just give you practice with the syntax.)
- Create a third function tail_fib with the same specification as before, but implement it to be tail-recursive. (You will need a helper function to implement this to be tail-recursive.)
Add tail_fib to your module's export-list, and test it to make sure it works properly.
- Start an Erlang interpreter, compile your module, and perform these simple experiments. Write your answers to the following questions in a file named "answers.txt".
- Starting with N = 20, and increasing by steps of 5, how far do you get before fib_p(N) takes more than five seconds to run? Why does it behave this way?
- How long does it take to compute tail_fib(10000)? Why?
2. Square-Multiples and the Möbius Function
The Möbius Function is a simple classifier of positive integers, devised by (surprise) August Möbius. Given a positive integer n, the Möbius function μ(n) returns:- 0 if the number is a multiple of a square
- -1 if the number has an odd number of distinct prime factors
- 1 if the number has an even number of distinct prime factors
You can probably see right away that this function is all about generating and then analyzing the list of prime factors for the input value. A number is a multiple of a square if it has any duplicate prime factors; for example, 12 = 2 × 2 × 3, so it is a multiple of a square, and therefore μ(12) = 0.
(If you want to learn about some of the more esoteric qualities of this function then you can look at this page.)
For this section we will focus on one interesting detail about the Möbius Function; runs of square-multiples. We want to write a program that finds the first run of square-multiples of length N. For example, the first run of three square-multiples starts with 48; 48, 49 and 50 are all multiples of squares.
All of your recursive functions for this section should be tail-recursive! Tail recursion is an extremely important aspect of Erlang, so it is important for you to be familiar with it. This section will give you plenty of opportunities to practice implementing tail-recursive functions.
Your Tasks
- Create a module named "mobius", in the file "mobius.erl".
- Create a function is_prime that takes a single argument N, and returns true if the number is prime, or false if the number is not prime.
Your implementation doesn't need to be particularly fast or clever. For example, you can create a helper function that iterates over integers from 2 to sqrt(N), checking whether N is evenly divisible by each value. If N is not evenly divisible by any value then it is prime; otherwise, it is not prime.
- Hint 1: You can use the remainder operator rem to check if N is evenly divisible by a particular value. A rem B returns the remainder from dividing A by B.
- Hint 2: Computing square-roots is costly. A better approach is to take the test value, which we will call Divisor, and if Divisor × Divisor > N then you are done. (Could be a good when-guard...)
- Create a function prime_factors that takes a single argument N, and returns a list of all prime factors of N. The result doesn't have to be in any particular order. Add this function to your module's export-list.
- Create a function is_square_multiple that takes a single argument N, and returns true if the argument is a multiple of some square, or false if it is not.
- Hint 1: A number is a multiple of a square if it has any prime-factors that appear more than once.
- Hint 2: You might find some of the functions in the lists and/or sets modules to be of use! The online erlang documentation is available here. For example, you might sort the list of prime-factors, then search the sorted list for the same prime-factor appearing twice in sequence.
- Finally, create a function find_square_multiples(Count, MaxN). This function takes a count of how many square-multiples in a row there should be, and also a maximum value of where to stop searching.
- If the function finds a series of Count square-multiples in the range [2, MaxN], it should return the first number in the run.
- If the function doesn't find any series of Count square-multiples in this range, it should return the atom fail.
1> c(mobius.erl). {ok,mobius} 2> mobius:find_square_multiples(3, 50). 48 3> mobius:find_square_multiples(3, 20). fail 4>Note that the start of the run must be no larger than MaxN; the entire run itself may extend beyond MaxN.
This function should also be exported by your mobius module.
- Once you have finished this function, find the first square-multiple runs of length 4, length 5, and length 6. You will need to choose a MaxN of 30000. Your program should definitely complete in under 1 minute; if it takes longer then you may have non-tail-recursive code in your implementation, and you need to fix this. (In fact, a good implementation shouldn't take very long to find the answers, but you will have up to a minute to compute the answer.)
Upon submitting your work, prepare a print-out source codes written in Erlang with test cases at the end of each problem. It should be in a short bond paper, using a courier new font, with 10 points in size. Duplicated work will be marked as 0.
NO LATE SUBMISSION WILL BE ACCEPTED.
Saturday, June 18, 2011
On Functional Programming
The objective of this course is to introduce the theory and practice of functional programming (FP). The characteristic feature of FP is the emphasis on computing by calculation. The traditional distinction between program and data characteristic of imperative programming (IP) is replaced by an emphasis on classifying expressions by types (see Erlang Data Types) that specify their behavior. Execution of imperative programs is generalized to evaluation of well-typed expressions by a smooth extension of mathematical experience to programming practice.
The advantages of FP are significant:
Moreover, FP generalizes IP by treating commands as forms of data that may be executed for their effects on the environment in which they occur.
Source: http://www.cs.cmu.edu/~15150/
The advantages of FP are significant:
- Verification: There is a close correspondence between the reasoning that justifies the correctness of a program and the program itself. Principles of proof by induction go hand-in-hand with the programming technique of recursion.
- Parallelism: Evaluation of compound expressions is naturally parallel in that the values of sub-expressions may be determined simultaneously without fear of interference or conflict among them. This gives rise to the central concepts of the work (sequential) and span (idealized parallel) complexity of a program, and allows programs to exploit available parallelism without fear of disrupting their correctness.
- Abstraction: FP stresses data-centric computation, with operations that act on compound data structures as whole, rather than via item-by-item processing. More generally, FP emphasizes the isolation of abstract types that clearly separate implementation from interface. Types are used to express and enforce abstraction boundaries, greatly enhancing maintainability of programs, and facilitating team development.
Moreover, FP generalizes IP by treating commands as forms of data that may be executed for their effects on the environment in which they occur.
Source: http://www.cs.cmu.edu/~15150/
Class Materials
Development Tools
For Windows
How to enable Erlang syntax-highlighting in Notepad++? (Windows Only)
For Windows
How to enable Erlang syntax-highlighting in Notepad++? (Windows Only)
- Install Notepad++ if you have not done so.
- Download the Erlang language definition file, userDefineLang.xml (Right-click, Save link as...).
- Click Start, then Run (or go to the Search box in Vista or Win7), then type, %appdata% and then press ENTER.
- Place userDefineLang.xml inside the Notepad++ folder (listed when you did Step 3) and then restart Notepad++.
After doing this, your Notepad++ should be able to do syntax-highlighting in your Erlang source code once you save it with a .erl extension.
For Linux Users: Download and install the Erlang runtime environment via your distro's package manager. Or better yet, install it from source.
Here's how:
- Download the latest source tarball (http://www.erlang.org/download/otp_src_R14B03.tar.gz)
- Copy your source tarball into your /usr/local/src folder (you must be root to write into this folder).
- Uncompress it by tar xvzf otp_src_R14B03.tar.gz
- Then cd otp_src_R14B03
- Issue the command, ./configure
- Then, make
- And finally, make install
To start the Erlang runtime environment, issue the following command (as non-root) at the command prompt,
$ erl
You can use gEdit as your source code editor.
Textbook / References:
Online Tutorial:
Erlang Users/Apps:
Wednesday, June 15, 2011
Announcement: Class Facebook
I would like to inform everybody that the class has a Facebook account. We could use Facebook to raise questions and other matter regarding about the course. Please add if you are interested.
Click HERE to visit the group.
Click HERE to visit the group.
Sunday, June 5, 2011
Subscribe to:
Posts (Atom)