| Return pure symbols and their values to satisfy clause. | Pure symbols are symbols in a formula that exist only in one form, | either complemented or otherwise. | For example, | {{A4 , A3 , A5' , A1 , A3'} , {A4} , {A3}} has pure symbols A4, A5' and A1. This has the fol
(
clauses: list[Clause], symbols: list[str], model: dict[str, bool | None]
)
| 182 | |
| 183 | |
| 184 | def find_pure_symbols( |
| 185 | clauses: list[Clause], symbols: list[str], model: dict[str, bool | None] |
| 186 | ) -> tuple[list[str], dict[str, bool | None]]: |
| 187 | """ |
| 188 | | Return pure symbols and their values to satisfy clause. |
| 189 | | Pure symbols are symbols in a formula that exist only in one form, |
| 190 | | either complemented or otherwise. |
| 191 | | For example, |
| 192 | | {{A4 , A3 , A5' , A1 , A3'} , {A4} , {A3}} has pure symbols A4, A5' and A1. |
| 193 | |
| 194 | This has the following steps: |
| 195 | 1. Ignore clauses that have already evaluated to be ``True``. |
| 196 | 2. Find symbols that occur only in one form in the rest of the clauses. |
| 197 | 3. Assign value ``True`` or ``False`` depending on whether the symbols occurs |
| 198 | in normal or complemented form respectively. |
| 199 | |
| 200 | >>> formula = Formula([Clause(["A1", "A2'", "A3"]), Clause(["A5'", "A2'", "A1"])]) |
| 201 | >>> clauses, symbols = generate_parameters(formula) |
| 202 | >>> pure_symbols, values = find_pure_symbols(clauses, symbols, {}) |
| 203 | >>> pure_symbols |
| 204 | ['A1', 'A2', 'A3', 'A5'] |
| 205 | >>> values |
| 206 | {'A1': True, 'A2': False, 'A3': True, 'A5': False} |
| 207 | """ |
| 208 | pure_symbols = [] |
| 209 | assignment: dict[str, bool | None] = {} |
| 210 | literals = [] |
| 211 | |
| 212 | for clause in clauses: |
| 213 | if clause.evaluate(model): |
| 214 | continue |
| 215 | for literal in clause.literals: |
| 216 | literals.append(literal) |
| 217 | |
| 218 | for s in symbols: |
| 219 | sym = s + "'" |
| 220 | if (s in literals and sym not in literals) or ( |
| 221 | s not in literals and sym in literals |
| 222 | ): |
| 223 | pure_symbols.append(s) |
| 224 | for p in pure_symbols: |
| 225 | assignment[p] = None |
| 226 | for s in pure_symbols: |
| 227 | sym = s + "'" |
| 228 | if s in literals: |
| 229 | assignment[s] = True |
| 230 | elif sym in literals: |
| 231 | assignment[s] = False |
| 232 | return pure_symbols, assignment |
| 233 | |
| 234 | |
| 235 | def find_unit_clauses( |
no test coverage detected