11export is_satisfiable
22
3+ """
4+ get_most_general_unifier(unifiables::Set{<:Unifiable})
5+
6+ Returns the most general unifier of `unifiable1` and `unifiable2`.
7+
8+ This is a naive implementation of a unification algorithm. It is supposed to be comprehensible.
9+ """
310function get_most_general_unifier (unifiables:: Set{<:Unifiable} )
411 unifier = Substitution ()
512 unified = first (unifiables)
@@ -10,6 +17,13 @@ function get_most_general_unifier(unifiables::Set{<:Unifiable})
1017 unifier
1118end
1219
20+ """
21+ most_general_unifier!(unifier!::Substitution, unifiable1::Unifiable, unifiable2::Unifiable)
22+
23+ Computes the most general unifier of `unifiable1` and `unifiable2` and stores it in `unifier!`.
24+
25+ This is a naive implementation of a unification algorithm. It is supposed to be comprehensible.
26+ """
1327function most_general_unifier! (unifier!:: Substitution , unifiable1:: Unifiable , unifiable2:: Unifiable )
1428 substituted_unifiable1 = substitute (unifiable1, unifier!)
1529 substituted_unifiable2 = substitute (unifiable2, unifier!)
@@ -65,7 +79,16 @@ function most_general_unifier!(unifier!::Substitution, unifiable1::Unifiable, un
6579 end
6680end
6781
68- # Apply substitution in order.
82+ """
83+ substitute(formula::Union{Term, Formula, Literal, Clause}, substitution::Substitution)
84+
85+ Return `formula` with all entries in `substitution` applied in order.
86+
87+ A `substitution` entry consists of a variable and a term. An entry is applied by replacing all
88+ occurrences of the variable with the term.
89+ """
90+ function substitute end
91+
6992function substitute (formula:: Union{Term, Formula, Literal, Clause} , substitution:: Substitution )
7093 substituted_formula = formula
7194 for (substitutee, substituter) in substitution
@@ -103,6 +126,14 @@ function substitute(formula::Union{Term, Formula, Literal, Clause}, substitutee,
103126 end
104127end
105128
129+ """
130+ rename_all_variables(formula, replacements=Dict{Variable, Variable}())
131+
132+ Return `formula` with all variables replace by new, unique names. The returned
133+ formula is logically equivalent to `formula`.
134+
135+ The `replacements` dictionary is for internal use only.
136+ """
106137function rename_all_variables (formula, replacements= Dict {Variable, Variable} ())
107138 @match formula begin
108139 f:: Clause => @applyrecursively rename_all_variables (:_ , replacements) f Clause
@@ -134,6 +165,16 @@ function rename_all_variables(formula, replacements=Dict{Variable, Variable}())
134165 end
135166end
136167
168+ """
169+ get_maybe_unifiable_literals(clause1::Clause, clause2::Clause)
170+
171+ Return a set of clauses that might be unifiable.
172+
173+ Each returned clause consists of literals in `clause1` and literals in
174+ `clause2`. To be considered unifiable, the selected literals in `clause1`
175+ must have the opposite negation of the literals in `clause2`. This function
176+ is used to reduce the search space for literals for the unification algorithm.
177+ """
137178function get_maybe_unifiable_literals (clause1:: Clause , clause2:: Clause )
138179 maybe_unifiable_literals = Set {Set{Literal}} ()
139180 all_literals = union (clause1, clause2)
@@ -159,6 +200,21 @@ function get_maybe_unifiable_literals(clause1::Clause, clause2::Clause)
159200 maybe_unifiable_literals
160201end
161202
203+ """
204+ is_satisfiable(formula; maxsearchdepth)
205+
206+ Check if `formula` is satisfiable.
207+
208+ If `formula` is unsatisfiable, this function will return `false` in finite time.
209+ If `formula` is satisfiable, this function may run forever. This behavior stems
210+ from the fundamental limit that the satisfiability problem for first-order logic
211+ is semidecidable. The `maxsearchdepth` parameter allows you to work around this
212+ limitation by specifying the maximum expansion depth of the resolution algorithm
213+ search tree. If the algorithm exceeds that limit, it throws an OverMaxSearchDepthError
214+ exception.
215+ """
216+ function is_satisfiable end
217+
162218function is_satisfiable (clauses:: CNF ; maxsearchdepth= Inf )
163219 if maxsearchdepth == 0
164220 throw (OverMaxSearchDepthError ())
0 commit comments