One place to get you started: take a look
removeTautologies :: Formula -> Formula
Now suppose we can write a function
isTautology :: Clause -> Bool
Then we may have the opportunity to use this function to filter general formulas. Therefore, I am trying to ignore everything except the isTautology function. Essentially the question here is: what is a tautology and how do we discover it? Some of the ideas posted by Edward Z. Young should definitely help you understand what's going on. In this case, we could look at the sentence [(True,"A"), (True,"B"), (False,"A")] and try to pass it to isTautology for testing it. Similar to another sentence published by Edward, [(True,"B"), (True,"C"), (True,"A")] .
The trick as a whole is to figure out how to break the functions into smaller components that are easy to write, and then glue these separate parts together with the code to solve the final problem. We decompose removeTautologies , which works with general formulas, into the isTautology helper, which can work on sentences in a formula, and then we try to define removeTautologies through it through some filtering code.
Hope this helps you get started with your problem. This may seem completely inappropriate, but note that the model verification algorithms use more advanced options that confirm the correctness of your processor, that the protocols behave, and are also recently used in automatic refactoring, see http: //coccinelle.lip6 .fr / for use. Thus, this problem is a good way to study serious applicability in the real world!
I will edit it here to help you, and not respond in the comments section. You wrote:
rt ((x, x') : (y, y') : rest) | x' == y' = rt rest | otherwise = (x, x') : rt ((y, y') : rest)
There are a couple of problems with this approach, as you mentioned. First of all, the game is that your rt function is working on sentences. If this sentence is a tautology, it should be deleted, so it would be better to call it isTautology type mentioned above, or simply simply:
isRemovableClause :: Clause -> Bool
The path you take requires you to sort the list in a lexicographic document, and then consider what to do if you have [P, P, not P, Q] for example. Another approach is to set up a search. Let's pretend that
isRemovableClause ((tv, name) : rest) = ...
Note that if the value (not tv, name) present in rest , this sentence should be a tautology. Otherwise, we can throw away (tv, name) and look for a tautology in rest .
Moving the focus to removeTautologies , itβs clear that the function can be written using isRemovableClause : The formula is a list of sentences, so we can just go through the list of sentences and delete all those for which isRemovableClause returns true. To do this, a bold solver will use List.filter , a higher order function.