-
Notifications
You must be signed in to change notification settings - Fork 5
/
parent_go.metta
executable file
·47 lines (33 loc) · 1.2 KB
/
parent_go.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
!(import! &kb go_rel)
(: Nat Type)
(: Z Nat)
(: S (-> Nat Nat))
;; Define <=
(: <= (-> $a $a Bool))
(= (<= $x $y) (or (< $x $y) (== $x $y)))
;; Define cast functions between Nat and Number
(: fromNumber (-> Number Nat))
(= (fromNumber $n) (if (<= $n 0) Z (S (fromNumber (- $n 1)))))
(: fromNat (-> Nat Number))
(= (fromNat Z) 0)
(= (fromNat (S $k)) (+ 1 (fromNat $k)))
;; Curried Backward Chainer
(: bc (-> $a Nat $a))
;; Base case
(= (bc (: $prf $ccln) $_)
(let () (println! (bc-base (: $prf $ccln)))
(match &kb (: $prf $ccln)
(let () (println! (bc-base-ground (: $prf $ccln))) (: $prf $ccln)))))
;; Recursive step
(= (bc (: ($prfabs $prfarg) $ccln) (S $k))
(let () (println! (bc-rec (: ($prfabs $prfarg) $ccln) (S $k)))
(let* (((: $prfabs (-> $prms $ccln)) (bc (: $prfabs (-> $prms $ccln)) $k))
((: $prfarg $prms) (bc (: $prfarg $prms) $k)))
(: ($prfabs $prfarg) $ccln))))
;!(bc (: $prf (member $g $o $k)) (fromNumber 3))
!(bc_impl! (: $prf (member $g $o $k)) (fromNumber 3))
!(pragma! rtrace true)
!(bc_impl! (: $prf (member $g $o $k)) (fromNumber 3))
!(pragma! rtrace false)
;!(bcm!)
!(bc_impl! (: $prf (member $g $o $k)) (fromNumber 3))