-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathb0_chaining_prelim.metta
57 lines (51 loc) · 1.39 KB
/
b0_chaining_prelim.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
51
52
53
54
55
56
57
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; From matching to evaluation of expressions via equality queries chaining
; It's possible to chain together matching queries
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Some knowledge base entries
; `:=` is a custom symbol
; Combinatory logic rules
(:= (I $x) $x)
(:= ((K $x) $y) $x)
(:= (K $x $y) $x)
(:= (S $x $y $z) ($x $z ($y $z)))
; A single matching step
!(assertEqualToResult
(match &self
(:= (S K K x) $r)
$r)
((K x (K x))))
; A second matching step; the result of the previous
; step is manually used as input for the next query
!(assertEqualToResult
(match &self
(:= (K x (K x)) $r)
$r)
(x))
; Combined reduction via matching in two steps
!(assertEqualToResult
(match &self
(:= (S K K x) $r)
(match &self (:= $r $r2)
$r2))
(x))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Another example (Peano summation)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(:= (Add $x Z) $x)
(:= (Add $x (S $y)) (Add (S $x) $y))
; First step
!(assertEqualToResult
(match &self
(:= (Add (S Z) (S Z)) $r)
$r)
((Add (S (S Z)) Z)))
; Two steps together
!(assertEqualToResult
(match &self
(:= (Add (S Z) (S Z)) $r)
(match &self (:= $r $r2)
$r2))
((S (S Z))))