Got it! This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
True and false can be represented as Prolog facts using the b predicate.
b(0).
b(1).
Note that facts are assumed to be true. Realize, though, that Prolog has no idea what the facts for b really mean.
3. Enumerate the values
The following Prolog program finds values for X and Y that will succeed, and then backtracks to find successive values until no more values can be found.
Here is the Prolog code.
Here is the output of the Prolog code.
4. Logical negation
The logical negation operator not can be expressed as the Prolog predicate not1 as the following facts.
not1(0,1).
not1(1,0).
Note that not1 is used since not is a reserved word in Prolog, as is and and or.
5. Logical conjunction
The logical conjunction operator and can be expressed as the Prolog predicate and2 as the following facts.
In an imperative (destructive assignment) programming language the order of the assignments to variables is important.
In a declarative programming logic programming system the order may impact efficiency (and issues due to the depth first search computation strategy) but the order is much less important.
Below, the order of the predicates are reversed (from the above). The result is the same.
Here is the Prolog code.
Here is the output of the Prolog code.
12. Declarative order
Even the order of the values for X and Y can be changed, but note that this may change the order of X and Y in the resulting table. The calculated values are the same.
Here is the Prolog code.