Question: Clojure Project In this project you will write a Clojure program to recursively convert logical expressions made up of the and, or , and not
Clojure Project
In this project you will write a Clojure program to recursively convert logical expressions made up of the and, or and not connectives to expressions using only the nor connective, then symbolically simplify the resulting expression.
To start this project, use a Lispstyle prefix notation to represent the logical expressions as unevaluated lists, allowing for a single argument for the not connective, and two or more arguments for the and and or connectives. To perform the symbolic conversion you must have your program deconstruct the input lists and build new lists to output. A sample of the conversions for you to generalize from are provided below. Please notice that the following examples are not nested.
not xnor xand x ynor nor xnor yand x y znor nor xnor ynor zand w x y znor nor wnor xnor ynor zor x ynor nor x yor x y znor nor x y zor w x y znor nor w x y z
Based on the above implement, you should build functions which uses recursion to build the output for nested expressions. Your life will be easiest if the function works from the inside expressions outward. You may wish to modify deepsubstitute for this task. For example, the expressions may look like
def pand x or x and y not zdef pand and z falseor x true falsedef por true a
Then, write a Clojure program using at least one higher order function eg map, filter, reduce, some, to symbolically simplify boolean nor relations of arbitrary length represented as unevaluated lists. Simplification consists of replacing particular forms with equivalent forms or symbols. For example, in each of the below sample simplifications, given an unevaluated list representation of the item on the left, the result should be the item on the right.
nor false true nor true false nor nor x x nor nor nor xnor xnor nor nor nor x x nor x xnor xnor x x xnor xnor x ynor x ynor x true false nor x falsenor xnor false false true nor x y falsenor x ynor x false falsenor xnor false false false true nor x y true false nor x y znor x y z
You should generalize for any length expression based on these patterns. Your program must work for any arbitrary variables used. You may wish to write functions to handle certain kinds of cases, and handle the nonrecursive case before you handle the recursive one.
The main entry point to the program, evalexp, calls functions that simplify, norconvert, and bind these expressions. Binding consists of replacing some or all of the variables in expressions with constants true or false and then returning the partially evaluated form. Weve already written a function which does this, in the form of deepsubstitute.
The evalexp function should take a symbolic expression and a binding map and return the simplest form that might just be a constant One way to define this is:
defn evalexp exp bindingssimplify norconvert bindvalues bindings exp
Example:
def pand x or x and y not z
evalexp px false, z true
binds x and z but not y in p leading to
and false or false and y not true
Then the conversion to nor occurs resulting in:
nor nor falsenor nor nor false nor nor ynor nor true
and then further simplifies to just false. You may wish to work out other cases for yourself in order to thoroughly test your code. Try experimenting with p p and p with varied variable binding maps.
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
