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 = []

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter14: Exception Handling
Section: Chapter Questions
Problem 3PE
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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning