Mathematical Logic and Programming Languages Exercise #1

This is the first exercise. A solution should be about 45 lines of code. It is due in two days, that is Wednesday October 1, by class time (2:00 PM). You must submit your solution. It will not be graded, but it I will check that it is submitted and will glance over it. Be prepared to discuss what you have done. We will spend considerable time discussing this in class on Wednesday. You may be called upon to elaborate your submission.

In this exercise you will implement some simple algorithms for propositional logic in Haskell. You will use the file SimpleProp.hs that implements the data structures for propositional logic (Prop n) a pretty printer for propositional logic (pp), and a valuation function (value) for propositional logic. You may want to study these functions before you begin the exercise below.

Write the following functions

• addvars :: Ord a => Prop a -> [a] -> [a]
The function addvars adds the propositional variables of its first argument to the list which is its second argument. For example the call addvars ((LetterP 1) \/ (LetterP 3) ~> (LetterP 1))  returns the list [1,2,3]. Note that every variable appears only once in the result.

• Using addvars write the function vars :: Ord a => Prop a -> [a].

• Write the function assigns, that given a [Int] (representing a list of propositional variables) compute a [[(Int,Bool)]], representing all possible Boolean valuations for those variables. For example assigns [2,5] returns the list [[(2,True),(5,True)],[(2,True),(5,False)],[(2,False),(5,True)],[(2,False),(5,False)]] Note that the length of the output list will always be 2 raised to the power of the length of the input lists.

• Write the predicate over propositional formula taut:: Prop Int -> Bool that checks if a formula is a tautology.

• Write the binary predicate over propositional formula equal:: Prop Int -> Prop Int -> Bool that checks if two formula are functionally equivalent.

Put all these functions into a file called Ex1.hs, test your functions and submit it to D2L.