Monday, September 24, 2007

JavaScript and Logic

Two years ago, I was in a logic course at WWU. The class was interesting, but some of the assigned online work was a bit repetitive. I did enjoy proving theorems, but filling out the truth tables was not exciting.

So, after some thinking, I quickly wrote a script called "logic.js" which can evaluate prepositional logic. I thought of how to do this from scratch (looking back on it there are probably better ways to do evaluate infix notation). For compound expressions, the idea was to use regex to find the innermost operation and evaluate it, replacing it with the result. Then this process would be repeated until there was only one value.

I used the engine to Draw Truth Tables and Evaluate Logic.

For fun, I wrote a similar program for a ProbStat course, at around the same time, for Set Diagrams. None of these are "finished" finished, but they work well enough.

No comments: