Skip to content

Commit 8e7d82e

Browse files
committed
Fix some issues in docs.
1 parent 3f8154f commit 8e7d82e

File tree

3 files changed

+94
-94
lines changed

3 files changed

+94
-94
lines changed

docs/concepts/search.md

Lines changed: 91 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,6 @@ The search engine:
2222

2323
## Creating a Search Engine
2424

25-
=== "Python"
26-
27-
```python
28-
import apyds
29-
30-
# Create with default sizes
31-
search = apyds.Search()
32-
33-
# Create with custom sizes
34-
search = apyds.Search(limit_size=1000, buffer_size=10000)
35-
```
36-
3725
=== "TypeScript"
3826

3927
```typescript
@@ -46,6 +34,18 @@ The search engine:
4634
const search2 = new Search(1000, 10000);
4735
```
4836

37+
=== "Python"
38+
39+
```python
40+
import apyds
41+
42+
# Create with default sizes
43+
search = apyds.Search()
44+
45+
# Create with custom sizes
46+
search = apyds.Search(limit_size=1000, buffer_size=10000)
47+
```
48+
4949
=== "C++"
5050

5151
```cpp
@@ -64,20 +64,6 @@ The search engine:
6464

6565
Use the `add()` method to add rules and facts to the knowledge base.
6666

67-
=== "Python"
68-
69-
```python
70-
import apyds
71-
72-
search = apyds.Search()
73-
74-
# Add a fact
75-
search.add("(parent john mary)")
76-
77-
# Add a rule with premises
78-
search.add("(father `X `Y)\n----------\n(parent `X `Y)\n")
79-
```
80-
8167
=== "TypeScript"
8268

8369
```typescript
@@ -92,6 +78,20 @@ Use the `add()` method to add rules and facts to the knowledge base.
9278
search.add("(father `X `Y)\n----------\n(parent `X `Y)\n");
9379
```
9480

81+
=== "Python"
82+
83+
```python
84+
import apyds
85+
86+
search = apyds.Search()
87+
88+
# Add a fact
89+
search.add("(parent john mary)")
90+
91+
# Add a rule with premises
92+
search.add("(father `X `Y)\n----------\n(parent `X `Y)\n")
93+
```
94+
9595
=== "C++"
9696

9797
```cpp
@@ -108,6 +108,23 @@ Use the `add()` method to add rules and facts to the knowledge base.
108108

109109
The `execute()` method performs one round of inference. It matches all rules against all facts and generates new conclusions.
110110

111+
=== "TypeScript"
112+
113+
```typescript
114+
import { Search } from "atsds";
115+
116+
const search = new Search();
117+
search.add("(father `X `Y)\n----------\n(parent `X `Y)\n");
118+
search.add("(father john mary)");
119+
120+
const count = search.execute((rule) => {
121+
console.log(`Found: ${rule.toString()}`);
122+
return false; // Continue searching
123+
});
124+
125+
console.log(`Generated ${count} new facts`);
126+
```
127+
111128
=== "Python"
112129

113130
```python
@@ -126,23 +143,6 @@ The `execute()` method performs one round of inference. It matches all rules aga
126143
print(f"Generated {count} new facts")
127144
```
128145

129-
=== "TypeScript"
130-
131-
```typescript
132-
import { Search } from "atsds";
133-
134-
const search = new Search();
135-
search.add("(father `X `Y)\n----------\n(parent `X `Y)\n");
136-
search.add("(father john mary)");
137-
138-
const count = search.execute((rule) => {
139-
console.log(`Found: ${rule.toString()}`);
140-
return false; // Continue searching
141-
});
142-
143-
console.log(`Generated ${count} new facts`);
144-
```
145-
146146
=== "C++"
147147

148148
```cpp
@@ -169,36 +169,6 @@ The callback receives each newly inferred rule and should return:
169169

170170
To search until a specific target is found:
171171

172-
=== "Python"
173-
174-
```python
175-
import apyds
176-
177-
search = apyds.Search(1000, 10000)
178-
179-
# Set up propositional logic
180-
search.add("(`P -> `Q) `P `Q") # Modus ponens
181-
search.add("(`p -> (`q -> `p))") # Axiom 1
182-
search.add("((`p -> (`q -> `r)) -> ((`p -> `q) -> (`p -> `r)))") # Axiom 2
183-
search.add("(((! `p) -> (! `q)) -> (`q -> `p))") # Axiom 3
184-
search.add("(! (! X))") # Premise
185-
186-
target = apyds.Rule("X")
187-
188-
while True:
189-
found = False
190-
def check(candidate):
191-
nonlocal found
192-
if candidate == target:
193-
print(f"Found: {candidate}")
194-
found = True
195-
return True
196-
return False
197-
search.execute(check)
198-
if found:
199-
break
200-
```
201-
202172
=== "TypeScript"
203173

204174
```typescript
@@ -229,24 +199,54 @@ To search until a specific target is found:
229199
}
230200
```
231201

232-
## Configuration Methods
202+
=== "Python"
233203

234-
### Set Limit Size
204+
```python
205+
import apyds
235206

236-
Controls the maximum size for each stored rule/fact:
207+
search = apyds.Search(1000, 10000)
237208

238-
=== "Python"
209+
# Set up propositional logic
210+
search.add("(`P -> `Q) `P `Q") # Modus ponens
211+
search.add("(`p -> (`q -> `p))") # Axiom 1
212+
search.add("((`p -> (`q -> `r)) -> ((`p -> `q) -> (`p -> `r)))") # Axiom 2
213+
search.add("(((! `p) -> (! `q)) -> (`q -> `p))") # Axiom 3
214+
search.add("(! (! X))") # Premise
239215

240-
```python
241-
search.set_limit_size(2000)
216+
target = apyds.Rule("X")
217+
218+
while True:
219+
found = False
220+
def check(candidate):
221+
global found
222+
if candidate == target:
223+
print(f"Found: {candidate}")
224+
found = True
225+
return True
226+
return False
227+
search.execute(check)
228+
if found:
229+
break
242230
```
243231

232+
## Configuration Methods
233+
234+
### Set Limit Size
235+
236+
Controls the maximum size for each stored rule/fact:
237+
244238
=== "TypeScript"
245239

246240
```typescript
247241
search.set_limit_size(2000);
248242
```
249243

244+
=== "Python"
245+
246+
```python
247+
search.set_limit_size(2000)
248+
```
249+
250250
=== "C++"
251251

252252
```cpp
@@ -257,18 +257,18 @@ Controls the maximum size for each stored rule/fact:
257257

258258
Controls the internal buffer size for operations:
259259

260-
=== "Python"
261-
262-
```python
263-
search.set_buffer_size(20000)
264-
```
265-
266260
=== "TypeScript"
267261

268262
```typescript
269263
search.set_buffer_size(20000);
270264
```
271265

266+
=== "Python"
267+
268+
```python
269+
search.set_buffer_size(20000)
270+
```
271+
272272
=== "C++"
273273

274274
```cpp
@@ -279,18 +279,18 @@ Controls the internal buffer size for operations:
279279

280280
Clears all rules and facts:
281281

282-
=== "Python"
283-
284-
```python
285-
search.reset()
286-
```
287-
288282
=== "TypeScript"
289283

290284
```typescript
291285
search.reset();
292286
```
293287

288+
=== "Python"
289+
290+
```python
291+
search.reset()
292+
```
293+
294294
=== "C++"
295295

296296
```cpp

docs/examples/basic.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Given the premise ¬¬X (double negation of X), we can derive X.
4040
while True:
4141
found = False
4242
def callback(candidate):
43-
nonlocal found
43+
global found
4444
if candidate == target:
4545
print("Found:", candidate)
4646
found = True

docs/getting-started/quickstart.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Rules represent logical inference steps. A rule has premises (conditions) and a
105105
auto rule = ds::text_to_rule("(father `X `Y)\n----------\n(parent `X `Y)\n", 1000);
106106

107107
std::cout << "Rule premises: " << rule->premises_count() << std::endl;
108-
std::cout << "Rule conclusion: " << ds::rule_to_text(fact->conclusion(), 1000).get() << std::endl;
108+
std::cout << "Rule conclusion: " << ds::term_to_text(fact->conclusion(), 1000).get() << std::endl;
109109
return 0;
110110
}
111111
```
@@ -140,7 +140,7 @@ The search engine performs logical inference by matching rules with facts.
140140
while True:
141141
found = False
142142
def callback(candidate):
143-
nonlocal found
143+
global found
144144
if candidate == target:
145145
print(f"Found: {candidate}")
146146
found = True

0 commit comments

Comments
 (0)