Debian Codegraph @

reasoning/arcus/meta-interpretation/README.md

raw
1 # đź§® Meta-Interpreter in arcus
2
3 This arcus reasoning model implements a **meta-interpreter**, a reasoning construct that **interprets its own logic rules**. It’s inspired by [Markus Triska’s meta-interpreter](https://www.metalevel.at/acomip/) and showcases how to define logic programming semantics within N3 Logic.
4
5 The model also includes an encoding of **natural numbers**, demonstrating recursive computation within a logical framework.
6
7 ---
8
9 ## 📚 Prefixes
10
11 ```turtle
12 @prefix list: <http://www.w3.org/2000/10/swap/list#> .
13 @prefix log: <http://www.w3.org/2000/10/swap/log#> .
14 @prefix var: <http://www.w3.org/2000/10/swap/var#> .
15 @prefix : <http://example.org/#> .
16 ```
17
18 ---
19
20 ## đź§  Meta-Interpreter Rules
21
22 ### Base Case: The empty program succeeds
23
24 ```turtle
25 [ log:graph (
26 [ log:triple (() :mi ()) ]
27 )] log:isImpliedBy true.
28 ```
29
30 This defines success for an empty goal list.
31
32 ---
33
34 ### Recursive Case: Evaluate a goal and then continue
35
36 ```turtle
37 [ log:graph (
38 [ log:triple (() :mi var:A) ]
39 )] log:isImpliedBy [ log:graph (
40 [ log:triple (var:A list:firstRest (var:G var:Gs)) ]
41 [ log:triple (() :headBody (var:G var:Goals var:Gs)) ]
42 [ log:triple (() :mi var:Goals) ]
43 )].
44 ```
45
46 This rule evaluates the head of a goal list (`var:G`) by matching it to a rule body, then recursively evaluates the body.
47
48 ---
49
50 ## 🧩 Rule Interpretation (Head–Body Pairs)
51
52 These rules extract and evaluate `headBody` rules, simulating a Prolog-like interpreter in RDF:
53
54 ```turtle
55 [ log:graph (
56 [ log:triple (() :headBody ([ log:graph (
57 [ log:triple (() :mi var:A) ]
58 )] var:B var:Rs)) ]
59 )] log:isImpliedBy [ log:graph (
60 [ log:triple (var:A list:firstRest (var:G var:Gs)) ]
61 [ log:triple (var:B list:firstRest ([ log:graph (
62 [ log:triple (() :headBody (var:G var:Goals var:Gs)) ]
63 )] var:C)) ]
64 [ log:triple (var:C list:firstRest ([ log:graph (
65 [ log:triple (() :mi var:Goals) ]
66 )] var:Rs)) ]
67 )].
68 ```
69
70 These rules recursively evaluate compound structures of goals, just like a mini logic engine.
71
72 ---
73
74 ## 🔢 Natural Number Logic
75
76 This portion encodes **Peano-style natural numbers** using successor notation:
77
78 ### Base Case: Zero is a natural number
79
80 ```turtle
81 [ log:graph (
82 [ log:triple (() :headBody ([ log:graph (
83 [ log:triple (() :natnum (0)) ]
84 )] var:Rs var:Rs)) ]
85 )] log:isImpliedBy true.
86 ```
87
88 ### Recursive Case: `s(X)` is a natnum if `X` is a natnum
89
90 ```turtle
91 [ log:graph (
92 [ log:triple (() :headBody ([ log:graph (
93 [ log:triple (() :natnum (:s var:X)) ]
94 )] var:A var:Rs)) ]
95 )] log:isImpliedBy [ log:graph (
96 [ log:triple (var:A list:firstRest ([ log:graph (
97 [ log:triple (() :natnum var:X) ]
98 )] var:Rs)) ]
99 )].
100 ```
101
102 ---
103
104 ## âť“ Query: Evaluate a Deeply Nested Goal
105
106 ```turtle
107 [ log:graph (
108 [ log:triple (() :mi ([ log:graph (
109 [ log:triple (() :mi ([ log:graph (
110 [ log:triple (() :mi ([ log:graph (
111 [ log:triple (() :natnum (:s (:s (:s (:s (:s (0))))))) ]
112 )])) ]
113 )])) ]
114 )])) ]
115 )] log:impliesAnswer [ log:graph (
116 [ log:triple (() :natnum (:s (:s (:s (:s (:s (0))))))) ]
117 )].
118 ```
119
120 This query asks whether `:s(:s(:s(:s(:s(0)))))` is a valid natural number using the meta-interpreter. The deeply nested `:mi` calls simulate layered interpretation.
121
122 ---
123
124 ### âś… Expected Output
125
126 ```turtle
127 ():natnum (:s (:s (:s (:s (:s (0))))))
128 ```
129
130 Which confirms that 5 (in successor notation) is a valid natural number.
131
132 ---
133
134 > **TIP:** A meta-interpreter allows arcus to reason about its own reasoning rules — enabling logic reflection and dynamic rule chaining.
135
136 > **NOTE:** This model recursively evaluates goals using RDF list structure and simulated logic program clauses.
137
138 > **Reference:** Inspired by [Markus Triska's article](https://www.metalevel.at/acomip/) on meta-interpreters in Prolog, adapted here into RDF/N3 logic with arcus.
139