1
2
3
4
5
6
7
8
9 """
10 Interfaces for theorem provers and model builders.
11
12 L{Prover} is a standard interface for a theorem prover which tries to prove a goal from a
13 list of assumptions.
14
15 L{ModelBuilder} is a standard interface for a model builder. Given just a set of assumptions.
16 the model builder tries to build a model for the assumptions. Given a set of assumptions and a
17 goal M{G}, the model builder tries to find a counter-model, in the sense of a model that will satisfy
18 the assumptions plus the negation of M{G}.
19 """
20
22 """
23 Interface for trying to prove a goal from assumptions.
24 Both the goal and the assumptions are
25 constrained to be formulas of L{logic.Expression}.
26 """
27 - def prove(self, goal=None, assumptions=[], verbose=False):
28 """
29 @return: Whether the proof was successful or not.
30 @rtype: C{bool}
31 """
32 raise NotImplementedError()
33
35 """
36 Interface for trying to build a model of set of formulas.
37 Open formulas are assumed to be universally quantified.
38 Both the goal and the assumptions are
39 constrained to be formulas of L{logic.Expression}.
40 """
41 - def build_model(self, goal=None, assumptions=[], verbose=False):
42 """
43 @return: A model if one is generated; None otherwise.
44 @rtype: C{nltk.sem.evaluate.Valuation}
45 """
46 raise NotImplementedError()
47
48
121
123 """
124 This class holds a C{Prover}, a goal, and a list of assumptions. When
125 prove() is called, the C{Prover} is executed with the goal and assumptions.
126 """
127 - def __init__(self, prover, goal=None, assumptions=[]):
128 """
129 @param prover: The theorem tool to execute with the assumptions
130 @type prover: C{Prover}
131 @see: C{TheoremToolCommand}
132 """
133 self._prover = prover
134 """The theorem tool to execute with the assumptions"""
135
136 TheoremToolCommand.__init__(self, goal, assumptions)
137
138 self._proof = None
139
140 - def prove(self, verbose=False):
141 """
142 Perform the actual proof. Store the result to prevent unnecessary
143 re-proving.
144 """
145 if self._result is None:
146 self._result, self._proof = self._prover.prove(self.goal(),
147 self.assumptions(),
148 verbose)
149 return self._result
150
153
156
158 """
159 This class holds a C{ModelBuilder}, a goal, and a list of assumptions. When
160 build_model() is called, the C{ModelBuilder} is executed with the goal and
161 assumptions.
162 """
163 - def __init__(self, modelbuilder, goal=None, assumptions=[]):
164 """
165 @param modelbuilder: The theorem tool to execute with the assumptions
166 @type modelbuilder: C{ModelBuilder}
167 @see: C{TheoremToolCommand}
168 """
169 self._modelbuilder = modelbuilder
170 """The theorem tool to execute with the assumptions"""
171
172 TheoremToolCommand.__init__(self, goal, assumptions)
173
174 self._valuation = None
175
177 """
178 Perform the actual proof. Store the result to prevent unnecessary
179 re-building.
180 """
181 if self._result is None:
182 self._result, self._valuation = \
183 self._modelbuilder.build_model(self.goal(),
184 self.assumptions(),
185 verbose)
186 return self._result
187