Sync
This commit is contained in:
parent
a937b1bc44
commit
fc8b83fca3
8 changed files with 117 additions and 19 deletions
|
@ -27,27 +27,21 @@ abstract class Clause(var head: Head, var body: Body) : Term, Resolvent {
|
|||
// Only if the body can be proven, the substitutions should be returned.
|
||||
// Do this in a lazy way.
|
||||
|
||||
val preHead = applySubstitution(head, subs)
|
||||
val preGoal = applySubstitution(goal, subs)
|
||||
|
||||
val (headEnd, headRenaming) = numbervars(preHead, Program.variableRenamingStart, subs)
|
||||
val headReverse = headRenaming.entries.associate { (a, b) -> b to a }
|
||||
val (headEnd, headRenaming) = numbervars(head, Program.variableRenamingStart, subs)
|
||||
Program.variableRenamingStart = headEnd
|
||||
|
||||
val renamedHead = applySubstitution(head, headRenaming)
|
||||
unifyLazy(preGoal, renamedHead, subs).forEach { headAnswer ->
|
||||
unifyLazy(goal, renamedHead, subs).forEach { headAnswer ->
|
||||
headAnswer.map { headSubs ->
|
||||
// If the body can be proven, yield the (combined) substitutions
|
||||
val preBody = applySubstitution(body, headRenaming + headSubs) as Body
|
||||
preBody.satisfy(subs).forEach { bodyAnswer ->
|
||||
bodyAnswer.fold(
|
||||
onSuccess = { bodySubs ->
|
||||
var result = (headSubs + bodySubs)
|
||||
.mapKeys { applySubstitution(it.key, headReverse) }
|
||||
.mapValues { applySubstitution(it.value, headReverse) }
|
||||
result = result.map { it.key to applySubstitution(it.value, result) }
|
||||
.toMap()
|
||||
.filterNot { it.key in headRenaming.keys && !occurs(it.key as Variable, goal, emptyMap())}
|
||||
val newSubs = headSubs + bodySubs
|
||||
val result = newSubs
|
||||
.mapValues { applySubstitution(it.value, newSubs) }
|
||||
.filter { it.key !is AnonymousVariable && occurs(it.key as Variable, goal, emptyMap()) }
|
||||
yield(Result.success(result))
|
||||
},
|
||||
onFailure = { error ->
|
||||
|
|
Reference in a new issue