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).

9 comments:

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

Connelly said...

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

أيفون said...

this very professionalism thanks

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

Connelly Barnes said...

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

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.

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')"?

kopiluwak nya said...

Jacket Leather Indonesia
Civet Coffee Indonesia
http://bantalsilikon01.blogspot.com/

cd
anne jelita brenda anne caca tasya ruth
bantal web jual bantal bantal bantal silikon pembicara hellow bumbu bumbu bumbu bumbu bumbu distro distro

distro
sabunherbal
keset
bantal
seo
distro
jual
marinir
bumbu

Khaled Soliman said...

وكالة نيوز
مباراة
1437
مصر
منوعات