The questions should be completed with OCaml. Running screenshots should be provided.  The background information is given by the picture.  Question 1: Provide 5 good test cases each for eval_success_tests and eval_failure_tests, following the format of: let eval_success_tests : ((truth_assignment * formula) * bool) list = [] let eval_failure_tests : ((truth_assignment * formula) * exn) list = []

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The questions should be completed with OCaml. Running screenshots should be provided. 

The background information is given by the picture. 

Question 1: Provide 5 good test cases each for eval_success_tests and eval_failure_tests, following the format of:

let eval_success_tests : ((truth_assignment * formula) * bool) list = []

let eval_failure_tests : ((truth_assignment * formula) * exn) list = []

 

Question 2: Implement the function eval : truth_assignment -> formula -> bool.

let eval (state : truth_assignment) (formula : formula) : bool =

    raise Not_implemented

You are evaluating boolean formulae instead of float arithmetic. You also need to use the correct boolean value for each variable. We recommend using Variable_map.find_opt to perform lookups in the truth assignment. If a variable is needed but does not appear in the truth assignment, you must raise an Unassigned_variable x exception, where x is the unassigned variable.

Once again, you may use any functions you want and whichever recursive style you prefer.

The test cases you must implement for this problem are split into two lists. eval_success_tests is a list of tests for when eval does not raise an exception and yields a bool, and eval_failure_tests is a list of tests for when eval raises an exception.

Note: "f x && g y" is not the same as "let fx = f x in let gy = g y in fx && gy" if g has side effects (like raising an exception, which it may do in this problem). So you should prefer to use the second option in your implementation. We specifically designed tests that check for this issue.

You will use exception-based backtracking to solve a well-known problem called SAT. SAT is short
for "boolean satisfiability." Simply put, if you have a boolean formula with variables, SAT asks if
there is any way to assign true and false to each variable so that the value of the formula
is true. In this assignment, we write & for boolean AND, | for boolean OR, and for boolean
NOT.
In order to make sets of variables and dictionaries of variables, we have defined
the Variable_set and Variable_map_modules for you. The interface is very similar to simplified
one you saw in class. These modules are defined using OCaml's
standard Set.Make and Map.Make functors. The links in the previous sentence will take you to their
documentation.
For example, we could define the set of variables {x,y,z} as
let xyz : Variable_set.t
=
Variable_set.singleton
|> Variable_set.add "y"
|> Variable_set.add "z";;
We could also define the truth assignment that maps × to true, and y and z to false :
let xyz_truth_asgn : truth_assignment
Variable_map.singleton "x" true
"y" false
"y" false
=
|> Variable_map.add
|> Variable_map.add
You are encouraged to define some constant variable sets and truth assignments to use in your
tests.
Question 1: Provide 10 good test cases for collect_variables_tests, following the format of:
let collect_variables_tests : (formula * Variable_set.t) list =
Question 2: Implement the function collect_variables : formula -> Variable_set.t.
This function takes a formula and returns the set of variable names which appear anywhere in the
formula. You may use any functions you want and whichever recursive style you prefer.
Transcribed Image Text:You will use exception-based backtracking to solve a well-known problem called SAT. SAT is short for "boolean satisfiability." Simply put, if you have a boolean formula with variables, SAT asks if there is any way to assign true and false to each variable so that the value of the formula is true. In this assignment, we write & for boolean AND, | for boolean OR, and for boolean NOT. In order to make sets of variables and dictionaries of variables, we have defined the Variable_set and Variable_map_modules for you. The interface is very similar to simplified one you saw in class. These modules are defined using OCaml's standard Set.Make and Map.Make functors. The links in the previous sentence will take you to their documentation. For example, we could define the set of variables {x,y,z} as let xyz : Variable_set.t = Variable_set.singleton |> Variable_set.add "y" |> Variable_set.add "z";; We could also define the truth assignment that maps × to true, and y and z to false : let xyz_truth_asgn : truth_assignment Variable_map.singleton "x" true "y" false "y" false = |> Variable_map.add |> Variable_map.add You are encouraged to define some constant variable sets and truth assignments to use in your tests. Question 1: Provide 10 good test cases for collect_variables_tests, following the format of: let collect_variables_tests : (formula * Variable_set.t) list = Question 2: Implement the function collect_variables : formula -> Variable_set.t. This function takes a formula and returns the set of variable names which appear anywhere in the formula. You may use any functions you want and whichever recursive style you prefer.
Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
System Management Strategies
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education