ForAll
This commit is contained in:
parent
6b46965435
commit
256a189125
4 changed files with 70 additions and 4 deletions
|
@ -123,6 +123,7 @@ open class Preprocessor {
|
|||
term.functor == "write/1" -> Write(args[0])
|
||||
term.functor == "read/1" -> Read(args[0])
|
||||
term.functor == "initialization/1" -> Initialization(args[0] as Goal)
|
||||
term.functor == "forall/2" -> ForAll(args[0] as LogicOperand, args[1] as Goal)
|
||||
|
||||
else -> {
|
||||
term.arguments = args
|
||||
|
|
|
@ -5,6 +5,9 @@ import prolog.Substitutions
|
|||
import prolog.ast.logic.LogicOperand
|
||||
import prolog.ast.terms.Atom
|
||||
import prolog.ast.logic.LogicOperator
|
||||
import prolog.ast.terms.Goal
|
||||
import prolog.ast.terms.Operand
|
||||
import prolog.ast.terms.Operator
|
||||
|
||||
class Initialization(val goal: LogicOperand) : LogicOperator(Atom(":-"), null, goal) {
|
||||
override fun satisfy(subs: Substitutions): Answers = goal.satisfy(subs).take(1)
|
||||
|
@ -14,3 +17,14 @@ class Initialization(val goal: LogicOperand) : LogicOperator(Atom(":-"), null, g
|
|||
class Query(val query: LogicOperand) : LogicOperator(Atom("?-"), null, query) {
|
||||
override fun satisfy(subs: Substitutions): Answers = query.satisfy(subs)
|
||||
}
|
||||
|
||||
/**
|
||||
* For all alternative bindings of Cond, Action can be proven.
|
||||
* It does not say which is wrong if one proves wrong.
|
||||
*
|
||||
* @see [SWI-Prolog Predicate forall/2](https://www.swi-prolog.org/pldoc/doc_for?object=forall/2)
|
||||
*/
|
||||
class ForAll(condition: LogicOperand, action: Goal) : Operator(Atom("forall"), condition, action) {
|
||||
private val not = Not(Conjunction(condition, Not(action)))
|
||||
override fun satisfy(subs: Substitutions): Answers = not.satisfy(subs)
|
||||
}
|
||||
|
|
Reference in a new issue