Main Overview

Class Logic

Class Logic: Propositional Logic
This is a static class (only static methods available)
Formulae of propositional logic, passed to the static methods, must be composed as follows:
Variables must be single letters.
Junctors: "not", "and", "or", "xor", "->", "<->".

Overview:

Class methods (static methods)

MethodMeaning
equivalent (f1, f2)Are the formulae f1 and f2 equivalent??
implies (f1, f2)implies the formula f1 the formula f2??
satisfiable (f)Is the formula f satisfiable?
satisfies (f, truthTable)Is the formula f true under the truthTable?
truthTables (formula)All possible truth tables for variables in formula
valid (f)Is the formula f valid?

Class methods (static methods)

equivalent

equivalent(f1, f2)

Usage: Logic.equivalent(f1, f2)

Description:
Are the formulae f1 and f2 equivalent??
Example
Logic.equivalent("not (A and B)", "not A or not B")) returns True.


implies

implies(f1, f2)

Usage: Logic.implies(f1, f2)

Description:
implies the formula f1 the formula f2??
Example
Logic.implies("A and B", "A or B") returns True.


satisfiable

satisfiable(f)

Usage: Logic.satisfiable(f)

Description:
Is the formula f satisfiable?
Example
Logic.satisfiable("A and not A") returns False.


satisfies

satisfies(f, truthTable)

Usage: Logic.satisfies(f, truthTable)

Description:
Is the formula f true under the truthTable?
Example
Logic.satisfies("A or B", {"A":True, "B":False}) returns True.


truthTables

truthTables(formula)

Usage: Logic.truthTables(formula)

Description:
All possible truth tables for variables in formula
The result is returned as a generator object (for a single iteration).
Example
for t in Logic.truthTables("A and B"): print(t)
returns:
{'A': False, 'B': False}
{'A': False, 'B': True}
{'A': True, 'B': False}
{'A': True, 'B': True}


valid

satisfies(f, truthTable)

Usage: Logic.valid(f)

Description:
Is the formula f valid?
Example
Logic.valid("A or not A") returns True.