-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|597|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Snippet Home -> Misc


 
Cower
Created : 21 September 2009
Edited : 12 March 2014
Language : Ruby

Parse/Evaluate Symbolic Logic

Also generates truth tables (doesn't handle proofs)

Alrighty, re-added this.

logical.rb


Example:


Note: this is set to run using Ruby 1.9.1 on my machine. You do not need Ruby 1.9, it will work with 1.8.7 (and probably 1.8.6 as well).

Jay, fix the Language/System thingy please >_>

 

Comments


Monday, 21 September 2009, 09:18
Jayenkai
My head doesn't scan through stuff like that as well as it does standard "a=b+c" stuff. I tend to need to closely read it before I can understand what my code's doing, so I tend to stay away from "complex" looking stuff like that.

I'm sure it's useful, though!
Monday, 21 September 2009, 10:41
Cower
Ruby isn't really that complex. It just tends to look that way since there are a few things that other languages don't have (since most languages are not near as flexible when it comes to syntax).

Anyhow, updated it so that there's a bug fixed with incorrectly parsing WFFs, moved the tautology? method into the LogicOperator method (it really has no business being in here at all, but I like it), and added some methods to determine when an expression is true/false and to return a string with a complete truth table for the expression.
Friday, 25 September 2009, 22:26
Cower
I've taken this down for the time being.
Saturday, 26 September 2009, 02:46
Jayenkai
How come?
Saturday, 26 September 2009, 03:36
JL235
Why take it down? It's really nice to see some non-gaming code snippets, especially those done in Ruby and written to a high standard.

It would be nice to see this re-added.
Saturday, 26 September 2009, 20:16
Cower
There is the possibility for the university to disagree with my intent in writing the code, so for the time being, it's gone.
Thursday, 01 October 2009, 19:37
Cower
Re-added this since there's unlikely to be any disagreement now.