Saturday, October 29, 2005

Propositional logic in Python

Propositional logic inference via compressed truth tables. Module entail is presumably slower than your industrial-grade C inference algorithm, but logical statements are given as Python expressions, and entailment can be checked at the interactive prompt. This makes the module easy to use, and fun. (Source Code).

7 Comments:

Blogger Connelly said...

Example usage

>>> S = AssumptionSet()
>>> S.assume('a => b')
>>> S.assume('b => c')
>>> S.assume('c => a')
>>> S.implies('a <=> b')
True
>>> S.implies('a')
False
>>> S.assume('a')
>>> S.implies('c')
True

1:03 AM  
Blogger Connelly said...

See also my post "intelligent minesweeper" [1], based on this module.

9:35 PM  
Anonymous أيفون said...

this very professionalism thanks

11:14 AM  
Blogger Dave said...

>>> import entail
>>> Socrates = entail.AssumptionSet()
>>> Socrates.assume('A=>B')
>>> Socrates.implies('A')
False
>>> Socrates.assume('~A')
>>> Socrates.implies('~B')
True
>>>
Error?
Denying the antecedent

11:08 PM  
Blogger Connelly Barnes said...

Hey Dave, you should use 'not A' and 'not B' then it works correctly.

1:50 PM  
Blogger antoinne85 said...

Does your library allow for the "AND" and "OR" operators or nesting?

For instance, could I express a proposition like any of the below:

A & B & C => X
A | B | C => X
A & (B | C) => X

I like the sample usage, by the way. Lean and easy to read.

1:04 PM  
Blogger antoinne85 said...

I should add that I've never written a line of python in my life, but that I've been searching for a lightweight propositional logic system for some time.

I also, spoke before I looked at the code (big mistake). It does look like it supports nesting, AND, and OR (at least from viewing the unit tests).

It does make me wonder, though. Is there a way to retract assumptions? For instance, can I "S.assume('a')" then later "S.unassume('a')"?

1:10 PM  

Post a Comment

<< Home