fix: Groene vinkjes

This commit is contained in:
Tibo De Peuter 2025-05-06 21:10:44 +02:00
parent 4810b91628
commit dff53b4e68
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
2 changed files with 7 additions and 5 deletions

View file

@ -44,14 +44,16 @@ abstract class Clause(var head: Head, var body: Body) : Term, Resolvent {
bodyAnswer.fold(
onSuccess = { bodySubs ->
// If the body can be proven, yield the (combined) substitutions
var result = goalToHeadSubs.mapValues { applySubstitution(it.value, bodySubs) }
yield(Result.success(result))
val goalToHeadResult = goalToHeadSubs.mapValues { applySubstitution(it.value, bodySubs) }
val headResult = headToGoalSubs.filterKeys { key -> goalToHeadSubs.any { occurs(key as Variable, it.value) } }
yield(Result.success(goalToHeadResult + headResult))
},
onFailure = { error ->
if (error is AppliedCut) {
// Find single solution and return immediately
if (error.subs != null) {
yield(Result.failure(AppliedCut(headAndGoalSubs + error.subs)))
var result = goalToHeadSubs.mapValues { applySubstitution(it.value, error.subs) }
yield(Result.failure(AppliedCut(result)))
} else {
yield(Result.failure(AppliedCut()))
}