Exercise #5 – Extended Lab Proposal and Exploratory Coding

DUE: As indicated on Canvas

Please read Chapter 10 and Chapter 11 in Programming Language Pragmatics. The goal of this lab is to expose you to alternative programming paradigms including functional programming with Lisp and declarative programming with . The idea is that with this exploratory programming, you can then choose and in-depth comparative programming algorithm study. Once you have done this, then I’d like to you choose an algorithms from your data structures, algorithms and general programming experience to explore with your native imperative procedural (perhaps also object oriented) programming language of choice and in a new language that uses an alternate paradigm by comparison (see language types on page 11 of PLP for review). Alternative languages you can choose from include: , Halide, Lisp, Scheme, Java, Python and Prolog (or other with instructor approval) and Primary languages to compare to can include: C/C++, Ada83, Ada95, and MATLAB that are taught in the SWE program. So, choose TWO programming languages and ONE example to compare from the following:

1. Concurrency – Use a library for concurrency in C/C++ like POSIX threads (simple example) or OpenMP and compare to language supported concurrency in Java or Ada95. Tale a simple example like this one for Sieve of Eratosthenes (simple single thread and more complex threaded C code) and compare with language supported concurrency and take a position on which is better and substantiate with performance, ease of programming, maintainability, etc. (in Lab #6). Other options are even simpler initial exploration through Fibonacci (single thread, multi-thread, and functional). 2. Functional Programming with Lisp – Compare functional programming for a data structure and algorithm you know that is reasonably complex (e.g. a binary tree with insert, delete and search) and implement in Java/C++ and Lisp and compare. Use GNU Common Lisp on Virtual-Box Linux as we’ll learn in this lab. 3. Declarative Programming with Prolog – Compare declarative programming for a logical problem such as feasibility in discrete mathematics or within a rule and fact system of your own devising. One interesting feasibility problem from discrete mathematics worthy of consideration is proving that a real-time schedule is feasible. 4. Scripting with R – Use “R” as we did in Lab #1, but to explore a complex set of equations similar to Lorenz or real data from the Internet gathered by Google or others to analyze large and/or non-linear data models and to make use of 3-D plotting and analysis – e.g. use Regula Falsi to find the root of a complex function (e.g. polynomials, the Lorenz equations, etc.). 5. Dataflow programming with Halide – Use Halide for image processing and transformation and compare to alternatives like GIMP (sudo apt-get install gimp) and OpenCV (sudo apt-get install libopencv-dev or build) for image processing tasks such as scaling an image, converting a color image to a graymap, etc. 6. Make up your Own (get approved) e.g. I want to implement a dictionary-based spell checker in both Lisp and Java and compare best known data structure and algorithm implementation in each or I want to compare lossy image compression methods in Java and Halide. The point of this assignment is to explore implementation in the language you are most comfortable with as well as an alternative. If your outcome in Lab #5 is that it’s very awkward or implementation in the alternative is not possible, that’s ok (and interesting), but you’ll have to pick a project for Lab #6 that can be implemented in both and compare the two and make a case for one language or the other as “better” for implementation of the algorithm and data structures you choose to investigate.

Exercise #5 Requirements:

1) [30 points] As a rapid introduction to Lisp programming, this exercise asks you to download, install, and start to use Lisp. a) [3 pts] First download and install GNU Common Lisp (sudo apt-get install gcl and sudo apt-get install gcl-doc) on Virtual-Box Ubuntu Linux as follows and show that you can reduce a simple expression with a screen-shot (e.g. (* 2 (cos 0) (+ 4 6)) => 20.0). Spend more time reading through Lisp tutorials and teaching yourself basics with Lisp. Alternatively, just use Steel Bank LISP on PRClab as described in class notes. b) [12 pts] Define the Fibonacci sequence as a recursive “defun” in Lisp (you may find this helpful) and enable tracing for you function fibonacci with “(trace fibonacci)”. Compute the Fibonacci sequence value for 3 and show a trace for this as a screen shot. Then, do a trace for 17 and capture this output to a file and count how many recursive calls are made and provide that number here. c) [6 pts] Download the C, Java and C++ Fibonacci iterative and recursive implementations (found here as C, here as C++ and here as Java). Describe one advantage and disadvantage of each and then pick what you believe is the best of these three imperative procedural implementations and describe why. d) [9 pts] Compare to the Lisp implementation and take a position on whether Lisp and functional programming makes mathematics like sequences easier to understand and implement or not. You must provide at least 3 arguments in favor or against Lisp and support them with specific examples or observations from this quick study.

2) [15 points] Install SWI Prolog or gprolog on VB-Linux and prove that your installation works with a simple example rule/fact base and derivation, or use SWI Prolog on PRClab as described in class notes. a) [5 pts] Install SWI Prolog and documents or simply test use of Prolog as shown in class (/usr/local/gprolog-1.4.4/gprolog) on PRClab (for SWI Prolog on your own Linux machine use sudo apt-get install swi-prolog and sudo apt-get install swi-prolog-doc) and show a screen shot of the prolog interpreter. b) [10 pts] Enter 3 simple logic rules of your own creation (e.g. you could enter logical AND, OR and NOT types of rules for something like rules for SWE graduation) and some facts (derive whether a student can graduate based on facts given ERAU SWE rules or made up). Any example is acceptable as long as it uses at least 3 rules and 3 or more facts and you can run a derivation (see documentation) and learn by examples.

3) [15 points] Read our textbook, lecture notes, and supporting materials, consider example code, and choose an alternative PL comparison study topic that is ONE of the six example algorithm/application areas described in the introduction for this assignment: a) Concurrency b) Functional programming c) Declarative programming d) Scripting with “R” e) Dataflow programming with Halide f) Of your own creation

Describe your selection and approach for comparison in good detail (several paragraphs with diagrams or examples).

4) [15 points] Write a 3 paragraph proposal for your comparative implementation proposal above that describes how you believe that one language or the other will provide a better implementation based on features that are: a) Optimal – describe how a programming language can provide improved performance, debug visibility or accuracy in the implementation and how you will verify this. b) Target – describe the expected basic features of the implementation in both languages (e.g. the implementation should be able to find all roots of any polynomial in bounded time to precision of 15 digits). c) Minimum – simple objectives that define basic success (both run and produce a result for 3 simple test cases).

5) [25 points] Develop a working proof-of-concept that shows that the application you propose is feasible in both your native imperative procedural programming language and the alternate. Provide make files, source code and details on how to run the alternate implementation (assume the reader is completely new to the alternate – e.g. tell them where to download the interpreter, how to install, and how to run your code). The code should convince you (and your instructor) that what you propose can be implemented.

Grading Checklist

[30 points] Introduction to Common Lisp:

[3 pts] a) use screen shot______

[12 pts] b) recursive trace______

[6 pts] c) imperative compare______

[9 pts] d) compare to Lisp______

[15 points] SWI Prolog introduction:

[5 pts] screen shot of interpreter______

[10 pts] 3 rules or more ______

[15 points] Selection of alternate PL to study:

[5 pts] selection ______

[10 pts] rationale______

[15 points] Proposal for PL comparison:

[5 pts] minimal objectives______

[5 pts] target objectives ______

[5 pts] goal objectives ______

[25 points] Alternative PL Proof-of-concept ______

[5 pts] Code runs or builds______

[10 pts] Testing and demonstration______

[10 pts] Concept ______