Skip to content

Commit cd63fa9

Browse files
dajiaohuangdmeoli
andauthored
Document first-order syntax support (#1354)
* Document first-order syntax support * Map the grammar of Figure 8.3 onto expr instead of repeating the connectives --------- Co-authored-by: Donato Meoli <donato.meoli@outlook.com>
1 parent 63afb16 commit cd63fa9

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

‎notebooks/logic.ipynb‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3503,6 +3503,70 @@
35033503
"The class `FolKB` can be used to represent a knowledge base of First-order logic sentences. You would initialize and use it the same way as you would for `PropKB` except that the clauses are first-order definite clauses. We will see how to write such clauses to create a database and query them in the following sections."
35043504
]
35053505
},
3506+
{
3507+
"cell_type": "markdown",
3508+
"metadata": {},
3509+
"source": [
3510+
"### First-order syntax in `expr`\n",
3511+
"\n",
3512+
"The connectives are written as in the table at the top of this notebook; the rest of the grammar of Figure 8.3 is written as follows.\n",
3513+
"\n",
3514+
"| Figure 8.3 | In `expr` | Example |\n",
3515+
"|------------|-----------|---------|\n",
3516+
"| *Constant* | a symbol starting with an uppercase letter | `John` |\n",
3517+
"| *Variable* | a symbol starting with a lowercase letter, with no arguments | `x` |\n",
3518+
"| *Predicate*(*Term*, ...) | a call | `Brother(Richard, John)` |\n",
3519+
"| *Function*(*Term*, ...) | a call nested inside another one | `LeftLeg(John)` in `Person(LeftLeg(John))` |\n",
3520+
"| *Term* = *Term* | not supported | |\n",
3521+
"| &forall; *Variable* *Sentence* | implicit: the variables of a clause in a `FolKB` are universally quantified | `King(x) & Greedy(x) ==> Evil(x)` |\n",
3522+
"| &exist; *Variable* *Sentence* | not supported: the object is named by a Skolem constant | `Owns(Nono, M1)` |\n",
3523+
"\n",
3524+
"`Expr` does not tell a predicate from a function, so the role of a call is given by where it appears. Python's `==` compares two expressions and returns `True` or `False`, so `x == y` is not an equality sentence; and since `FolKB` holds only definite clauses, there is no syntax for quantifiers. The variables of a query are answered by substitutions."
3525+
]
3526+
},
3527+
{
3528+
"cell_type": "code",
3529+
"execution_count": null,
3530+
"metadata": {},
3531+
"outputs": [
3532+
{
3533+
"data": {
3534+
"text/plain": [
3535+
"(False, (LeftLeg(John),))"
3536+
]
3537+
},
3538+
"execution_count": null,
3539+
"metadata": {},
3540+
"output_type": "execute_result"
3541+
}
3542+
],
3543+
"source": [
3544+
"x, y = expr('x, y')\n",
3545+
"x == y, expr('Person(LeftLeg(John))').args"
3546+
]
3547+
},
3548+
{
3549+
"cell_type": "code",
3550+
"execution_count": null,
3551+
"metadata": {},
3552+
"outputs": [
3553+
{
3554+
"data": {
3555+
"text/plain": [
3556+
"[{w: John}]"
3557+
]
3558+
},
3559+
"execution_count": null,
3560+
"metadata": {},
3561+
"output_type": "execute_result"
3562+
}
3563+
],
3564+
"source": [
3565+
"kb = FolKB([expr('King(x) & Greedy(x) ==> Evil(x)'),\n",
3566+
" expr('King(John)'), expr('Greedy(John)')])\n",
3567+
"list(fol_fc_ask(kb, expr('Evil(w)')))"
3568+
]
3569+
},
35063570
{
35073571
"cell_type": "markdown",
35083572
"metadata": {},

0 commit comments

Comments
 (0)