[EDIT]
For those of you who are interested, I'll be putting here any interesting links I find during my endeavor.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Cool MIT lecture notes on propositional and first
order logic automation (see chapters 9 and 10):
http://tinyurl.com/77nfyx9
Logic for Computer Science : Foundations
of Automatic Theorem Proving (free pdf)
http://www.cis.upenn.edu/~jean/gbooks/logic.html
On integrating theorem proving and symbolic computation...
http://www.calculemus.net/
http://tinyurl.com/7o99oot
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[/EDIT]
For the last couple of months, my duties have entailed helping a professor of mine discover new, interesting theorems in the domain of control theory. Whenever he comes up with something, I write a small Mathematica script to test its validity extensively, and if everything is OK, we proceed to trying to prove it. So far, we have some good results, but nothing too serious as to make us (rich and) famous overnight. So, one day I thought "OK, this is stupid. It's not going to get us anywhere good anytime soon. So, why don't we just automate the whole procedure?". And that's what I decided to do. I told him about my plan, but he didn't seem very enthusiastic, probably because he isn't much of a programmer himself. Nevertheless, I decided to proceed.
I googled a bit around "automated theorem proving" and got some good links. I did some studying on logic and stuff, and, eventually, my first attempt came to life. It's a propositional logic theorem prover. You give it a propositional formula, and it tells you if it's valid (always true), unsatisfiable (always false) or satisfiable (can be true). The first version was written in Haskell. However, I realized that there are two problems with this approach. The first one is that this algorithm doesn't work for every kind of logic. It only works with propositional and first-order logic. And I want more. The higher the order of the logic I use, the more detailed the modeling of my domain can be and, therefore, the more interesting the theorems I can describe and prove can be. The second problem is that I want not only a theorem prover, but also a theorem generator. I'd like to have something that I feed with all sorts of axioms and spits out all sorts of interesting theorems deriving from these axioms. To deal with these problems, it looks like I'll have to use stuff like pathfinding algorithms with smart heuristics. Now, I seriously doubt my ability to code something like A* in Haskell, in a way that is both simple and efficient, so, I decided to switch to Scala, where I can mix imperative and functional style any way I want.
Ok, that was enough introduction. Here's the code ->
http://ideone.com/P2deE
I'd really appreciate it if a (certain) Scala specialist could review the code and tell me how I could make it smaller and / or faster. The code is an almost direct translation of the Haskell version, so, I think there are parts that would be better written in imperative style. For example, I believe the lcnf function could make use of list buffers. Also, about that same function, I tried to implement it like this...
def lcnf(expr: Expr): List[List[Expr]] = {
def lcnfH[T <: Expr](list: List[Expr])(expr: Expr): List[Expr] = expr match {
case T(p, q) => list ::: lcnfH[T](List())(p) ::: lcnfH[T](List())(q) case e => e :: list }
(lcnfH[And](List())(expr)) map lcnfH[Or](List())_
} |
...but it didn't work :/ It seems that I can't pattern match against T. Why? Is there a workaround?
Has anyone else played with stuff like that? If yes, do you have any good (preferably online) studying material I could use?
Finally, if you want, you can help me submit it bug-free to daniweb's code snippet competition. Just try any crazy propositional formula you can think of and tell me if you get a wrong result. I think you can actually do it on the same ideone paste I posted above.
EDIT: Fixed two bugs that caused it to enter an infinite loop for some inputs.
EDIT2: Another bug fix... It should be ok now... I guess...