Question: For example, a statement in CNF might look like this: ( a OR NOT b ) AND ( b OR c OR NOT d )
For example, a statement in CNF might look like this:
a OR NOT b AND b OR c OR NOT d AND d OR NOT e
In our project, a literal also includes two boolean constants TRUE and FALSE. Your program should return a list of variable assignments that make the CNF formula true. For instance, to make AND a b true, both a and b need to be TRUE. To make OR a b true, there are three possible solutions, both a and b are TRUE, or a is TRUE, b is FALSE, or b is TRUE, a is FALSE.
The contextfree grammar for the CNF formula is straightforward and defined in our project as below:
:: AND mid
::O Rmid
::mid N O T
::abldotsz TRUE mid FALSE
Input and Output of the Program
The input to the program is a string list. An example is below:
a OR b OR NOT c AND NOT a AND TRUE"
The program's output is of the type string bool list, which gives the first possible boolean value assignment of the variables to satisfy the CNF formula. An example is below:
If such an assignment doesn't exist, please return a list of one tuple, as in
the example shown below:
error true
Basic Function Implementations
First, you need to break down the input string into a string list by eliminating
white spaces. This function is already provided to you in the "projectdriver.ml
file, called "tokensListFromString str : string
Next, you will need to implement a basic called "partition" in the code
package given to you. The purpose of the "partition" function is to break down
a string list with respect to a delimiter. It will help you get the input string list
represented in a way that facilitates further processing.
Table : Required Functions
The input and output type of the "partition" function is given in Table
An example of the input and output of the "partition" function is below:
Name: partition
Input: ; a; OR; "NOT"; b; ; "AND"; ; b; "AND"
Output: ; a; OR; "NOT"; b; ; ; b;
There are a few other basic functions you have to implement, listed below:
The next function you will have to implement is called "getVariables". It
takes a string list and gets the list of the variable names from the CNF The
input and output types are specified in Table It filters out the leftright
parenthesis, ANDOR TRUEFALSE and NOT items out of the string list
representing the input. The output should not have duplicates. An example is
given below:
Name: getVariables
Input: ; a; OR; "NOT"; b; ; "AND"; ; b;
Output: a; b
You will also have to implement the function called "generateDefaultAssign
ments". It takes the list of variables, and outputs a list of tuples, each tuple
being a variable name and the boolean value "false". It is used to initialize the
set of variables to the "false" value. An example is given below:
Name: generateDefaultAssignments
Input: a;b
Output: a falseb false
You will also have to implement the function called "generateNextAssign
ments". This function takes a list of stringboolean tuples, and returns an up
dated list of stringboolean tuples as if the singular binary number represented
by the booleans is incremented by as well as an additional boolean value carry
for when it overflows. Essentially, starting with the rightmost variable, if the
checked variable is assigned to false, it is set to true. If the checked variable
is true, it is set to false and the algorithm carries to next variable to the left.
The returned boolean value carry is true only if the resulting binary number
overflows the given space, ie the algorithm reaches the leftmost variable and
still carries.
Name: generateNextAssignments
Input: a falseb false
Output: a falseb true false
Input: a falseb true
Output: a trueb false false
Input: a trueb true
Output: a falseb false true
You will also have to implement the function called "LookupVar". This
function takes a assignment list of stringboolean tuples as well as a string, and
returns the boolean value associated with the given string in the assignment
list. Behavior for string values not in the assignment list will not be tested.
Name: LookupVar
Input: a falseb truea
Output: false
Advanced Function Implementations
Now, we will handle the boolean satisfiability evaluation function and data
structures to represent the satisfiability funct
The buildCNF function
Thi
N
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
