-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathb3_direct.metta
50 lines (46 loc) · 1.58 KB
/
b3_direct.metta
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Example from OpenCog Classic wiki on PLN Backward Chaining
; No explicit backward chaining is needed
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; facts
(= (croaks Fritz) T)
(= (eat_flies Fritz) T)
; Rules
(= (And T T) T)
(= (frog $x)
(And (croaks $x)
(eat_flies $x)))
(= (green $x)
(frog $x))
; Conclusion from facts and rules
!(assertEqual
(green Fritz)
T)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This is not just functional programming,
; because we can do inference
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(= (ift T $then) $then)
!(assertEqual
(ift (green $x) $x)
Fritz)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; One can call a function with a variable as an argument
; and retrieve the variable binding but constructing
; an expression with it
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
!(assertEqual
($x (green $x))
(Fritz T))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; We can also use expressions with `=` in `match`
; NOTE: `=` is not an ordinary symbol, and declarative reasoning over expressions
; with it may work differently from that over purely symbolic expressions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
!(assertEqualToResult
(match &self (= ($p Fritz) T) $p)
(croaks eat_flies))