Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The assignment is to write a Clojure program that performs symbolic simplification and evaluation of boolean expressions using and, or, and not will be assumed

The assignment is to write a Clojure program that performs symbolic simplification and evaluation of boolean expressions using "and", "or", and "not" will be assumed to take one argument, while "and" and "or" will take one or more. Use false for False and true for True.

Examples of expressions created as unevaluated lists:

(def p1 '(and x (or x (and y (not z)))))

(def p2 '(and (and z false) (or x true)))

(def p3 '(or true a))

set p1, p2, and p3 to the given unevaluated expressions. Start off with three functions that build (unevaluated) expressions:

(defn andexp [e1 e2] (list 'and e1 e2))

(defn orexp [e1 e2] (list 'or e1 e2))

(defn notexp [e1] (list 'not e1))

---

e.g p3 could have been created using

(def p3 (orexp true 'a))

You will need to modify andexp and orexp to allow for one or more arguments.

The main function to write, evalexp, entails functions that simplify, bind, and evaluate these expressions.

Simplification consists of replacing particular forms with equivalent functions, including the following (you may add others too):

(or true) => true; (or false) => false; (and true) => true; (and false) => false; (or x false) => x; (or false x) => x; (or true x) => true; (or x true) => true; (and x false) => false; (and false x) => false; (and x true) => x; (and true x) => x; (not false) => true; (not true) => false; (or x y z) => (or x (or y z)); (and x y z) => (and x (and y z)); (not (and x y)) => (or (not x) (not y)); (not (or x y)) => (and (not x) (not y));

Binding consists of replacing some or all of the variables in expressions with constants (true or false), and then returning the partially evaluated form.

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 bindings] (simplify (bind-values bindings exp)))

E.g:

(evalexp p1 '{x false, z true})

binds x and z (but not y) in p1, leading to (and false (or false (and y (not true)))) and then further simplifies to just false.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

3. How would you address the problems that make up the situation?

Answered: 1 week ago

Question

2. What recommendations will you make to the city council?

Answered: 1 week ago