Skip to content

Commit f367a16

Browse files
committed
The notebook at an itermediate stage
1 parent 4ed9716 commit f367a16

1 file changed

Lines changed: 49 additions & 9 deletions

File tree

logic.ipynb

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"source": [
99
"# Explaining the logic.py module\n",
1010
"*Author: Chirag Vartak*<br>\n",
11-
"*Date: 23rd March 2016*"
11+
"*Date: 23rd March 2016*\n",
12+
"\n",
13+
"---"
1214
]
1315
},
1416
{
@@ -42,8 +44,8 @@
4244
"The class `PropKB` now.\n",
4345
"* `__init__(self, sentence=None)` : The constructor `__init__` creates a single field `clauses` which will be a list of all the sentences of the knowledge base. Note that each one of these sentences will be a 'clause' i.e. a sentence which is made up of only literals and `or`s.\n",
4446
"* `tell(self, sentence)` : When you want to add a sentence to the KB, you use the `tell` method. This method takes a sentence, converts it to its CNF, extracts all the clauses, and adds all these clauses to the `clauses` field. So, you need not worry about `tell`ing only clauses to the knowledge base. You can `tell` the knowledge base a sentence in any form that you wish; converting it to CNF and adding the resulting clauses will be handled by the `tell` method.\n",
45-
"* `ask_generator(self, query)` : The `ask_generator` function is to be used by the `ask` function. It calls the `tt_entails` function, which in turn returns `True` if the knowledge base entails query and `False` otherwise. The `ask_generator` itself returns and empty dict `{}` if the knowledge base entails query and `None` otherwise. This might seem weird to you a little bit. After all, it makes more sense just to return a `True` or a `False` instead of the `{}` or `None` But this is to maintain consistency with how things are in First-Order Logic, where, an `ask_generator` function, is supposed to return all the substitutions that make the query true in a dict. I will be mostly be using the `ask` function which returns a `{}` or a `False`, but if you don't like this, you can always use the `ask_if_true` function which returns a `True` or a `False`.\n",
46-
"* `retract(self, sentence)` : This function removes all the clauses of the sentence given from the knowledge base. Like the `tell` function, you don't have to explicitly pass only clauses to remove them from the knowledge base; any sentence will do fine. The function will take care of converting that sentence to clauses."
47+
"* `ask_generator(self, query)` : The `ask_generator` function is used by the `ask` function. It calls the `tt_entails` function, which in turn returns `True` if the knowledge base entails query and `False` otherwise. The `ask_generator` itself returns an empty dict `{}` if the knowledge base entails query and `None` otherwise. This might seem a little bit weird to you. After all, it makes more sense just to return a `True` or a `False` instead of the `{}` or `None` But this is done to maintain consistency with the way things are in First-Order Logic, where, an `ask_generator` function, is supposed to return all the substitutions that make the query true. Hence the dict, to return all these substitutions. I will be mostly be using the `ask` function which returns a `{}` or a `False`, but if you don't like this, you can always use the `ask_if_true` function which returns a `True` or a `False`.\n",
48+
"* `retract(self, sentence)` : This function removes all the clauses of the sentence given, from the knowledge base. Like the `tell` function, you don't have to pass clauses to remove them from the knowledge base; any sentence will do fine. The function will take care of converting that sentence to clauses and then remove those."
4749
]
4850
},
4951
{
@@ -55,33 +57,71 @@
5557
"## Getting started with Propositional Logic"
5658
]
5759
},
60+
{
61+
"cell_type": "markdown",
62+
"metadata": {},
63+
"source": []
64+
},
65+
{
66+
"cell_type": "markdown",
67+
"metadata": {},
68+
"source": [
69+
"### A note to delete later on\n",
70+
"\n",
71+
"1. Markdown is converted to HTML. It's closer to HTML than it is to Latex. Hence, to add special symbols, unicode characters etc., use HTML character reference rather than Latex symbols.\n",
72+
"2. Propositional symbols in markdown\n",
73+
" * &not; &emsp; `&not;`\n",
74+
" * &and; &emsp; `&and;`\n",
75+
" * &or; &emsp; `&or;`\n",
76+
" * &rarr; &emsp; `&rarr;`\n",
77+
" * &harr; &emsp; `&harr;`\n",
78+
"3. And some others\n",
79+
" * &#8872; &emsp; `&#8872;`\n",
80+
" * &equiv; &emsp; `&equiv;`"
81+
]
82+
},
83+
{
84+
"cell_type": "markdown",
85+
"metadata": {},
86+
"source": [
87+
"```python\n",
88+
"def my_function(string1, string2):\n",
89+
" for in in range(42):\n",
90+
" print string1 + string2\n",
91+
"```\n",
92+
"\n",
93+
"```python def __init__(self, sentence)```"
94+
]
95+
},
5896
{
5997
"cell_type": "code",
6098
"execution_count": null,
6199
"metadata": {
62100
"collapsed": true
63101
},
64102
"outputs": [],
65-
"source": []
103+
"source": [
104+
"dcsdfdsf"
105+
]
66106
}
67107
],
68108
"metadata": {
69109
"kernelspec": {
70-
"display_name": "Python 3",
110+
"display_name": "Python 2",
71111
"language": "python",
72-
"name": "python3"
112+
"name": "python2"
73113
},
74114
"language_info": {
75115
"codemirror_mode": {
76116
"name": "ipython",
77-
"version": 3
117+
"version": 2
78118
},
79119
"file_extension": ".py",
80120
"mimetype": "text/x-python",
81121
"name": "python",
82122
"nbconvert_exporter": "python",
83-
"pygments_lexer": "ipython3",
84-
"version": "3.4.4"
123+
"pygments_lexer": "ipython2",
124+
"version": "2.7.11"
85125
}
86126
},
87127
"nbformat": 4,

0 commit comments

Comments
 (0)