Example Script¶
Here's an example demonstrating zelph's capabilities:
(X "is a" Y) => (X ~ Y)
(X "is an" Y) => (X "is a" Y)
"is attribute of" "is opposite of" is
"is part of" "is opposite of" "has part"
"is for example" "is opposite of" "is a"
"has part" is transitive
"has attribute" is transitive
~ is transitive
(R is transitive, X R Y, Y R Z) => (X R Z)
(X is E, E "is a" K) => (X is K)
(X "has part" P, P "is a" K) => (X "has part" K)
(K is E, X "is a" K) => (X is E)
(K "has part" P, X "is a" K) => (X "has part" P)
(X "is opposite of" Y, X "is a" K) => (Y "is a" K)
(X "is opposite of" Y) => (Y "is opposite of" X)
(R "is opposite of" S, X R Y) => (Y S X)
(X "is opposite of" Y, A is X, A is Y) => !
(X "is opposite of" Y, A "has part" X, A "has part" Y) => !
(X "is opposite of" Y, A "is a" X, A "is a" Y) => !
(X is E, X "is a" E) => !
(X is E, E "is a" X) => !
(X is E, E "has part" X) => !
"is needed by" "is opposite of" needs
"is generated by" "is opposite of" generates
"is needed by" "is opposite of" needs
"is generated by" "is opposite of" generates
(X generates energy) => (X "is an" "energy source")
(A is hot) => (A generates heat)
(A generates "oxygen") => (A is alive)
chimpanzee "is an" ape
ape is alive
chimpanzee "has part" hand
hand "has part" finger
"green mint" "is an" mint
"water mint" "is a" mint
peppermint "is a" mint
mint "is a" lamiacea
catnip "is a" lamiacea
"green mint" is sweet
"is ancestor of" is transitive
peter "is ancestor of" paul
paul "is ancestor of" "pius"
A "is ancestor of" "pius"
When executed, the last line is interpreted as a query, because it contains a variable (single uppercase letter) and is no rule. Here are the results:
An imported script does not contribute deduction anchors, so in the default
focus mode only the query answer is printed and the derived facts are
counted (see Deduction Output Modes):
zelph> .import examples/english
Importing file examples/english.zph...
Answer: paul "is ancestor of" pius
(skipped 35 deductions)
.deductions all shows what those 35 are. The order in which they appear
is not fixed -- the reasoner is parallel, and the fixpoint is a set:
zelph> .deductions all
Deduction printing mode: all
zelph> .import examples/english
Importing file examples/english.zph...
Answer: paul "is ancestor of" pius
(peppermint ~ mint) โ (peppermint "is a" mint)
(catnip ~ lamiacea) โ (catnip "is a" lamiacea)
(mint ~ lamiacea) โ (mint "is a" lamiacea)
("water mint" ~ mint) โ ("water mint" "is a" mint)
( peppermint ~ lamiacea ) โ {( peppermint ~ mint ) ( ~ is transitive ) ( mint ~ lamiacea )}
("water mint" ~ lamiacea) โ {("water mint" ~ mint) (~ is transitive) (mint ~ lamiacea)}
(peter "is ancestor of" pius) โ {(peter "is ancestor of" paul) ("is ancestor of" is transitive) (paul "is ancestor of" pius)}
(chimpanzee "has part" finger) โ {(chimpanzee "has part" hand) ("has part" is transitive) (hand "has part" finger)}
(chimpanzee "is a" ape) โ (chimpanzee "is an" ape)
("green mint" "is a" mint) โ ("green mint" "is an" mint)
(needs "is opposite of" "is needed by") โ ("is needed by" "is opposite of" needs)
(is "is opposite of" "is attribute of") โ ("is attribute of" "is opposite of" is)
("has part" "is opposite of" "is part of") โ ("is part of" "is opposite of" "has part")
(generates "is opposite of" "is generated by") โ ("is generated by" "is opposite of" generates)
("is a" "is opposite of" "is for example") โ ("is for example" "is opposite of" "is a")
(finger "is part of" chimpanzee) โ {(chimpanzee "has part" finger) ("has part" "is opposite of" "is part of")}
(chimpanzee ~ ape) โ (chimpanzee "is a" ape)
(chimpanzee is alive) โ {(chimpanzee "is a" ape) (ape is alive)}
(ape "is for example" chimpanzee) โ {(chimpanzee "is a" ape) ("is a" "is opposite of" "is for example")}
("green mint" ~ mint) โ ("green mint" "is a" mint)
(mint "is for example" "green mint") โ {("green mint" "is a" mint) ("is a" "is opposite of" "is for example")}
(transitive "is attribute of" "has attribute") โ {("has attribute" is transitive) (is "is opposite of" "is attribute of")}
(transitive "is attribute of" ~) โ {(~ is transitive) (is "is opposite of" "is attribute of")}
(transitive "is attribute of" "is ancestor of") โ {("is ancestor of" is transitive) (is "is opposite of" "is attribute of")}
(alive "is attribute of" chimpanzee) โ {(chimpanzee is alive) (is "is opposite of" "is attribute of")}
(sweet "is attribute of" "green mint") โ {("green mint" is sweet) (is "is opposite of" "is attribute of")}
(transitive "is attribute of" "has part") โ {("has part" is transitive) (is "is opposite of" "is attribute of")}
(alive "is attribute of" ape) โ {(ape is alive) (is "is opposite of" "is attribute of")}
(hand "is part of" chimpanzee) โ {(chimpanzee "has part" hand) ("has part" "is opposite of" "is part of")}
(finger "is part of" hand) โ {(hand "has part" finger) ("has part" "is opposite of" "is part of")}
(lamiacea "is for example" mint) โ {(mint "is a" lamiacea) ("is a" "is opposite of" "is for example")}
(mint "is for example" "water mint") โ {("water mint" "is a" mint) ("is a" "is opposite of" "is for example")}
(lamiacea "is for example" catnip) โ {(catnip "is a" lamiacea) ("is a" "is opposite of" "is for example")}
(mint "is for example" peppermint) โ {(peppermint "is a" mint) ("is a" "is opposite of" "is for example")}
("green mint" ~ lamiacea) โ {("green mint" ~ mint) (~ is transitive) (mint ~ lamiacea)}
The results demonstrate zelph's powerful inference capabilities. It not only answers the specific query about who is an ancestor of pius, but it also derives numerous other facts based on the rules and base facts provided in the script.