Hi There!

I'm Dan Schlegel, an Associate Professor in the Computer Science Department at SUNY Oswego

CSC344 – Assignment 2

Microproject

Write a Clojure program using higher order functions (e.g., map, filter, reduce, some, …) to symbolically simplify non-nested boolean disjunctions of arbitrary length >= 1 represented as unevaluated lists. For example, in each of the below, given a list representation of the item on the left (you should quote the list), the result should be the item on the right.

Your program must work for any arbitrary variables used.

Main Project

In this project you will symbolically simplify arbitrary boolean expressions containing the “and”, “or”, and “not” connectives. “not” will be assumed to take one argument, while “and” and “or” will take one or more. You should use false for False and true for True.

Expressions are created as unevaluated lists. For example:

Simplification consists of replacing particular forms with equivalent forms or symbols. Some examples are provided below, though you must be sure your project works in general.

The main entry point to the program, “evalexp”, calls functions that simplify, bind, and evaluate 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.

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

Example:

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.

Extra Credit

Write a set of Clojure functions that perform symbolic simplification and evaluation of the set-oriented logical connectives “andor” and “thresh” [1]. These connectives generalize all of the standard boolean logic connectives (such as and, or, xor, and not), and allow the use of many more. They are defined as follows (adapted from [1]):

andor

Syntax: (andor (i j) p1 … pn) 0 <= i <= j <= n

Semantics: (andor (i j) p1 …pn) is True if at least min(i, |{p1 … pn}|) and at most min(j, |{p1 … pn}|) of pi ∈ {p1,…,pn} are True; otherwise it is False.
(andor (0 0)) ≡ True.

thresh

Syntax: (thresh (i j) p1 … pn) 0 <= i <= j <= n

Semantics: (thresh (i j) p1 …pn) is True if either fewer than min(i, |{p1 … pn}|) or more than min(j, |{p1 … pn}|) of pi ∈ {p1,…,pn} are True; otherwise it is False.
(thresh (0 0)) ≡ False

[1] Shapiro, Stuart C. “Set-Oriented Logical Connectives: Syntax and Semantics.” KR. 2010.

Suggested Development Environment

Either: