module documentation

This module provides data structures for representing first-order models.

Class Assignment A dictionary which represents an assignment of values to variables.
Class Model A first order model is a domain D of discourse and a valuation V.
Class Valuation A dictionary which represents a model-theoretic Valuation of non-logical constants. Keys are strings representing the constants to be interpreted, and values correspond to individuals (represented as strings) and n-ary relations (represented as sets of tuples of strings).
Exception Error Undocumented
Exception Undefined Undocumented
Function arity Check the arity of a relation. :type rel: set of tuples :rtype: int of tuple of str
Function demo Run exists demos.
Function foldemo Interpretation of closed expressions in a first-order model.
Function folmodel Example of a first-order model.
Function is_rel Check whether a set represents a relation (of any arity).
Function propdemo Example of a propositional model.
Function read_valuation Convert a valuation string into a valuation.
Function satdemo Satisfiers of an open formula in a first order model.
Function set2rel Convert a set containing individuals (strings or numbers) into a set of unary tuples. Any tuples of strings already in the set are passed through unchanged.
Function trace Undocumented
Variable mult Undocumented
Function _read_valuation_line Read a line in a valuation file.
Constant _ELEMENT_SPLIT_RE Undocumented
Constant _TUPLES_RE Undocumented
Constant _VAL_SPLIT_RE Undocumented
def arity(rel): (source)

Check the arity of a relation. :type rel: set of tuples :rtype: int of tuple of str

def demo(num=0, trace=None): (source)

Run exists demos.

  • num = 1: propositional logic demo
  • num = 2: first order model demo (only if trace is set)
  • num = 3: first order sentences demo
  • num = 4: satisfaction of open formulas demo
  • any other value: run all the demos
Parameters
numUndocumented
tracetrace = 1, or trace = 2 for more verbose tracing
def foldemo(trace=None): (source)

Interpretation of closed expressions in a first-order model.

def folmodel(quiet=False, trace=None): (source)

Example of a first-order model.

def is_rel(s): (source)

Check whether a set represents a relation (of any arity).

Parameters
s:seta set containing tuples of str elements
Returns
boolUndocumented
def propdemo(trace=None): (source)

Example of a propositional model.

def read_valuation(s, encoding=None): (source)

Convert a valuation string into a valuation.

Parameters
s:stra valuation string
encoding:strthe encoding of the input string, if it is binary
Returns
Valuationa nltk.sem valuation
def satdemo(trace=None): (source)

Satisfiers of an open formula in a first order model.

def set2rel(s): (source)

Convert a set containing individuals (strings or numbers) into a set of unary tuples. Any tuples of strings already in the set are passed through unchanged.

For example:
  • set(['a', 'b']) => set([('a',), ('b',)])
  • set([3, 27]) => set([('3',), ('27',)])
Parameters
s:setUndocumented
Returns
set of tuple of strUndocumented
def trace(f, *args, **kw): (source)

Undocumented

mult: int = (source)

Undocumented

def _read_valuation_line(s): (source)

Read a line in a valuation file.

Lines are expected to be of the form:

noosa => n
girl => {g1, g2}
chase => {(b1, g1), (b2, g1), (g1, d1), (g2, d2)}
Parameters
s:strinput line
Returns
tuplea pair (symbol, value)
_ELEMENT_SPLIT_RE = (source)

Undocumented

Value
re.compile(r'\s*,\s*')
_TUPLES_RE = (source)

Undocumented

Value
re.compile('''\\s*
                                (\\([^)]+\\))  # tuple-expression
                                \\s*''',
           re.VERBOSE)
_VAL_SPLIT_RE = (source)

Undocumented

Value
re.compile(r'\s*=+>\s*')