All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.it.unibo.tuprolog.unify.UnificationUtils.kt Maven / Gradle / Ivy

@file:JvmName("UnificationUtils")

package it.unibo.tuprolog.unify

import it.unibo.tuprolog.core.Substitution
import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.core.Var
import kotlin.jvm.JvmName

/** Transforms an [Equation] of a [Var] with a [Term] to the corresponding [Substitution] */
fun  Equation.toSubstitution(): Substitution =
    Substitution.of(this.toPair())

/** Creates a [Substitution] out of a [Iterable] of [Equation]s assigning [Var]s to [Term]s  */
fun  Iterable>.toSubstitution(): Substitution =
    Substitution.of(this.map { it.toPair() })

/** Transforms a [Substitution] into the list of corresponding [Equation]s */
fun Substitution.toEquations(): List> =
    this.entries.map { (variable, term) -> Equation.Assignment(variable, term) }

/** Creates an equation with [this] and [that] terms */
@Suppress("unused", "FunctionName")
infix fun Term.eq(that: Term): Equation = Equation.of(this, that)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy