|
CMSC 631, Spring 2013Program Analysis and UnderstandingProject 111:59:59pm Part 1: List functionsWrite your solutions to the following problems in a file part1.ml Implement the following functions in OCaml. Do not use any functions in the List module, i.e., write every function from scratch using just list notation [...], ::, and pattern matching.
Part 2: Boolean FormulaeIn this part of the project, you can use the List library. Write your solutions to this part of the project in a file part2.ml. You will use the following data type, representing boolean formulae:
type formula =
False
| True
| Var of char
| And of formula * formula
| Or of formula * formula
| Not of formula
| Forall of char * formula
| Exists of char * formula
Here False and True represent the obvious values. Var c represents the boolean variable with name c (notice that variable names can only be characters). The constructors And, Or, and Not represent boolean conjunction, disjunction, and negation, respectively. For example, the mathematical formula (a or b) and c would be represented by the OCaml value And(Or(Var 'a', Var 'b'), Var 'c'). (We'll explain Forall and Exists in a moment.) We will use associative lists, which are just lists of pairs, to represent assignments of truth values to variables: type assignment = (char * bool) list Here if an assignment contains the pair (c,b), then that assignment gives the variable represented by the character c the value b. When working with the type assignment, you will find the functions List.assoc, List.mem_assoc, and related functions helpful. See the OCaml library documentation for more details. You may assume for purposes of this project that whenever you work with an assignment, all listed variables are distinct (i.e., you don't need to worry about names in one part of the list "shadowing" names elsewhere in the list). The last two kinds of formula, Forall and Exists, represent the similarly named quantifiers. The boolean formula Forall(x, f) is true if f is true under all assignments to x, i.e., if f is true when x=true and when x=false. The boolean formula Exists(x, f) is true if f is true either for x=true or x=false. For example, the formula Forall('x', Or(Var 'x', Var 'y')) is true under the assignment [('y', true)] and false under the assignment [('y', false)]. Write the following functions that work with boolean formulae:
What to SubmitSubmit part1.ml and part2.ml. Academic IntegrityThe Campus Senate has adopted a policy asking students to include the following statement on each assignment in every course: "I pledge on my honor that I have not given or received any unauthorized assistance on this assignment." Consequently your program is requested to contain this pledge in a comment near the top. Please carefully read the academic honesty section of the course syllabus. Any evidence of impermissible cooperation on projects, use of disallowed materials or resources, or unauthorized use of computer accounts, will be submitted to the Student Honor Council, which could result in an XF for the course, or suspension or expulsion from the University. Be sure you understand what you are and what you are not permitted to do in regards to academic integrity when it comes to project assignments. These policies apply to all students, and the Student Honor Council does not consider lack of knowledge of the policies to be a defense for violating them. Full information is found in the course syllabus---please review it at this time. |