Skip to content

Commit 4540e1f

Browse files
committed
Fix
1 parent b594c62 commit 4540e1f

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

other/davis_putnam_logemann_loveland.py

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ class Clause:
1919
"""
2020
| A clause represented in Conjunctive Normal Form.
2121
| A clause is a set of literals, either complemented or otherwise.
22-
| For example:
23-
| * {A1, A2, A3'} is the clause (A1 v A2 v A3')
24-
| * {A5', A2', A1} is the clause (A5' v A2' v A1)
22+
23+
For example:
24+
* {A1, A2, A3'} is the clause (A1 v A2 v A3')
25+
* {A5', A2', A1} is the clause (A5' v A2' v A1)
2526
2627
Create model
2728
@@ -74,12 +75,14 @@ def assign(self, model: dict[str, bool | None]) -> None:
7475

7576
def evaluate(self, model: dict[str, bool | None]) -> bool | None:
7677
"""
77-
| Evaluates the clause with the assignments in model.
78-
| This has the following steps:
79-
| 1. Return ``True`` if both a literal and its complement exist in the clause.
80-
| 2. Return ``True`` if a single literal has the assignment ``True``.
81-
| 3. Return ``None`` (unable to complete evaluation) if a literal has no assignment.
82-
| 4. Compute disjunction of all values assigned in clause.
78+
Evaluates the clause with the assignments in model.
79+
80+
This has the following steps:
81+
1. Return ``True`` if both a literal and its complement exist in the clause.
82+
2. Return ``True`` if a single literal has the assignment ``True``.
83+
3. Return ``None`` (unable to complete evaluation)
84+
if a literal has no assignment.
85+
4. Compute disjunction of all values assigned in clause.
8386
"""
8487
for literal in self.literals:
8588
symbol = literal.rstrip("'") if literal.endswith("'") else literal + "'"
@@ -155,9 +158,10 @@ def generate_parameters(formula: Formula) -> tuple[list[Clause], list[str]]:
155158
"""
156159
| Return the clauses and symbols from a formula.
157160
| A symbol is the uncomplemented form of a literal.
158-
| For example,
159-
| * Symbol of A3 is A3.
160-
| * Symbol of A5' is A5.
161+
162+
For example,
163+
* Symbol of A3 is A3.
164+
* Symbol of A5' is A5.
161165
162166
>>> formula = Formula([Clause(["A1", "A2'", "A3"]), Clause(["A5'", "A2'", "A1"])])
163167
>>> clauses, symbols = generate_parameters(formula)
@@ -233,15 +237,17 @@ def find_unit_clauses(
233237
model: dict[str, bool | None], # noqa: ARG001
234238
) -> tuple[list[str], dict[str, bool | None]]:
235239
"""
236-
| Returns the unit symbols and their values to satisfy clause.
237-
| Unit symbols are symbols in a formula that are:
238-
| - Either the only symbol in a clause
239-
| - Or all other literals in that clause have been assigned ``False``
240-
| This has the following steps:
241-
| 1. Find symbols that are the only occurrences in a clause.
242-
| 2. Find symbols in a clause where all other literals are assigned ``False``.
243-
| 3. Assign ``True`` or ``False`` depending on whether the symbols occurs in
244-
| normal or complemented form respectively.
240+
Returns the unit symbols and their values to satisfy clause.
241+
242+
Unit symbols are symbols in a formula that are:
243+
- Either the only symbol in a clause
244+
- Or all other literals in that clause have been assigned ``False``
245+
246+
This has the following steps:
247+
1. Find symbols that are the only occurrences in a clause.
248+
2. Find symbols in a clause where all other literals are assigned ``False``.
249+
3. Assign ``True`` or ``False`` depending on whether the symbols occurs in
250+
normal or complemented form respectively.
245251
246252
>>> clause1 = Clause(["A4", "A3", "A5'", "A1", "A3'"])
247253
>>> clause2 = Clause(["A4"])
@@ -280,12 +286,13 @@ def dpll_algorithm(
280286
clauses: list[Clause], symbols: list[str], model: dict[str, bool | None]
281287
) -> tuple[bool | None, dict[str, bool | None] | None]:
282288
"""
283-
| Returns the model if the formula is satisfiable, else ``None``
284-
| This has the following steps:
285-
| 1. If every clause in clauses is ``True``, return ``True``.
286-
| 2. If some clause in clauses is ``False``, return ``False``.
287-
| 3. Find pure symbols.
288-
| 4. Find unit symbols.
289+
Returns the model if the formula is satisfiable, else ``None``
290+
291+
This has the following steps:
292+
1. If every clause in clauses is ``True``, return ``True``.
293+
2. If some clause in clauses is ``False``, return ``False``.
294+
3. Find pure symbols.
295+
4. Find unit symbols.
289296
290297
>>> formula = Formula([Clause(["A4", "A3", "A5'", "A1", "A3'"]), Clause(["A4"])])
291298
>>> clauses, symbols = generate_parameters(formula)

0 commit comments

Comments
 (0)