20 lines
785 B
Kotlin
20 lines
785 B
Kotlin
package prolog.builtins
|
|
|
|
import prolog.components.terms.Atom
|
|
import prolog.components.terms.Structure
|
|
import prolog.components.terms.Term
|
|
import prolog.components.terms.Variable
|
|
|
|
/**
|
|
* True if Term1 is equivalent to Term2. A variable is only identical to a sharing variable.
|
|
*/
|
|
fun equivalent(term1: Term, term2: Term): Boolean {
|
|
return when {
|
|
term1 is Variable && term2 is Variable -> term1 == term2
|
|
term1 is Variable -> term1.alias().isPresent && equivalent(term1.alias().get(), term2)
|
|
term2 is Variable -> term2.alias().isPresent && equivalent(term2.alias().get(), term1)
|
|
term1 is Atom && term2 is Atom -> term1.compareTo(term2) == 0
|
|
term1 is Structure && term2 is Structure -> term1.compareTo(term2) == 0
|
|
else -> false
|
|
}
|
|
}
|