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 = []
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.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F63009fa9-49a0-4390-b30a-cfe08e27e31e%2F56803517-a7c4-41f1-bc7e-bc323fb36388%2F9dlw3k_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 4 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)