nx_question_genealogy.nx source
↩ module page · 290 lines · 10936 B
1// nx_question_genealogy.nx -- the why-chain primitive.
2//
3// Records the chain of refinement questions that motivate each
4// theorem / primitive. Per QUESTION_GENEALOGY_DOCTRINE: a newcomer's
5// "why does this matter?" question resolves CONTINUOUSLY from the
6// layperson root question to the niche specialization, with each
7// node citing the theorem that answered it and the new sub-question
8// it opened.
9//
10// Data structure: a forest of question-trees (DAG, but for now
11// modeled as parent-pointer tree; one node may be referenced from
12// multiple children but only one parent is tracked here).
13//
14// genealogy_id: feynman_motivational_explanation + popper_problem_situations
15// + dewey_inquiry_pragmatism
16// lineage_id: pedagogical_scaffolding + question_tree
17// axioms: NX_AX_LOGIC_IDENTITY (a question's identity = its phrasing)
18
19// nx_safety_envelope:
20// intended_use: AUTO_APPLIED -- primitive-specific tuning queued
21// sil_target: SIL1
22// evidence: [bulk_applied_2026-05-16, see-file-comment-for-detail]
23// verdict: NOT_YET_EVALUATED
24
25import "syscalls.nx"
26import "nx_axioms.nx"
27
28// ===== sealed tier (mirrors nx_jargon) ===============================
29
30const NX_QG_TIER_ROOT: i64 = 0 // layperson original question
31const NX_QG_TIER_REFINEMENT: i64 = 1 // refinement chain
32const NX_QG_TIER_NICHE: i64 = 2 // niche specialization
33const NX_QG_TIER_OPEN_RESEARCH: i64 = 3 // unanswered frontier
34
35// ===== node ==========================================================
36
37struct QuestionNode {
38 node_id: i64,
39 parent_node_id: i64, // -1 for roots
40 tier: i64, // sealed NX_QG_TIER_*
41 question_text: *u8,
42 answering_theorem_id: i64, // 0 if open
43 answering_year: i64, // 0 if no canonical
44 answering_author: *u8,
45 depth_from_root: i64,
46}
47
48const NX_QG_NODE_BYTES: i64 = 64
49
50struct QuestionTree {
51 nodes: *QuestionNode,
52 n_nodes: i64,
53 capacity: i64,
54}
55
56const NX_QG_MAX_NODES: i64 = 4096
57
58func nx_qg_tree_alloc() -> *QuestionTree {
59 let raw: *u8 = sys_mmap(24)
60 let t: *QuestionTree = raw as *QuestionTree
61 t.nodes = (sys_mmap(NX_QG_MAX_NODES * NX_QG_NODE_BYTES)) as *QuestionNode
62 t.n_nodes = 0
63 t.capacity = NX_QG_MAX_NODES
64 return t
65}
66
67func nx_qg_node_at(t: *QuestionTree, i: i64) -> *QuestionNode {
68 return (((t.nodes as i64) + i * NX_QG_NODE_BYTES) as *QuestionNode)
69}
70
71// Add a root question (no parent). Returns node id.
72func nx_qg_add_root(t: *QuestionTree, text: *u8) -> i64 {
73 if t.n_nodes >= t.capacity { return -1 }
74 let n: *QuestionNode = nx_qg_node_at(t, t.n_nodes)
75 n.node_id = t.n_nodes
76 n.parent_node_id = -1
77 n.tier = NX_QG_TIER_ROOT
78 n.question_text = text
79 n.answering_theorem_id = 0
80 n.answering_year = 0
81 n.answering_author = "" as *u8
82 n.depth_from_root = 0
83 let id: i64 = t.n_nodes
84 t.n_nodes = t.n_nodes + 1
85 return id
86}
87
88// Add a refinement under a parent node. Returns node id.
89func nx_qg_add_refinement(t: *QuestionTree, parent_id: i64, tier: i64,
90 text: *u8,
91 answering_theorem_id: i64,
92 answering_year: i64,
93 answering_author: *u8) -> i64 {
94 if t.n_nodes >= t.capacity { return -1 }
95 if parent_id < 0 { return -2 }
96 if parent_id >= t.n_nodes { return -2 }
97 let parent: *QuestionNode = nx_qg_node_at(t, parent_id)
98 let n: *QuestionNode = nx_qg_node_at(t, t.n_nodes)
99 n.node_id = t.n_nodes
100 n.parent_node_id = parent_id
101 n.tier = tier
102 n.question_text = text
103 n.answering_theorem_id = answering_theorem_id
104 n.answering_year = answering_year
105 n.answering_author = answering_author
106 n.depth_from_root = parent.depth_from_root + 1
107 let id: i64 = t.n_nodes
108 t.n_nodes = t.n_nodes + 1
109 return id
110}
111
112// Trace from a target node back to root. Writes the chain into
113// out_ids[] (root first, target last); returns the chain length.
114func nx_qg_trace_from_root(t: *QuestionTree, target: i64,
115 out_ids: *i64, max_len: i64) -> i64 {
116 if target < 0 { return 0 }
117 if target >= t.n_nodes { return 0 }
118 // First walk back to root to count depth.
119 var cur: i64 = target
120 var depth: i64 = 0
121 while cur >= 0 {
122 if depth >= max_len { return -1 }
123 let n: *QuestionNode = nx_qg_node_at(t, cur)
124 cur = n.parent_node_id
125 depth = depth + 1
126 }
127 // Now write in reverse order.
128 cur = target
129 var i: i64 = depth - 1
130 while cur >= 0 {
131 out_ids[i] = cur
132 let n: *QuestionNode = nx_qg_node_at(t, cur)
133 cur = n.parent_node_id
134 i = i - 1
135 }
136 return depth
137}
138
139// Audit: how many nodes are at each tier?
140func nx_qg_count_by_tier(t: *QuestionTree, tier: i64) -> i64 {
141 var c: i64 = 0
142 var i: i64 = 0
143 while i < t.n_nodes {
144 let n: *QuestionNode = nx_qg_node_at(t, i)
145 if n.tier == tier { c = c + 1 }
146 i = i + 1
147 }
148 return c
149}
150
151// Walk a chain and emit narrative to fd.
152func qg_putc(fd: i64, c: i64) -> i64 {
153 let buf: *u8 = sys_mmap(1)
154 buf[0] = c & 0xFF
155 sys_write(fd, buf, 1)
156 return 0
157}
158
159func qg_str(fd: i64, s: *u8, n: i64) -> i64 {
160 sys_write(fd, s, n)
161 return 0
162}
163
164func qg_strz(fd: i64, s: *u8) -> i64 {
165 var i: i64 = 0
166 while s[i] != 0 { i = i + 1 }
167 sys_write(fd, s, i)
168 return i
169}
170
171func qg_i64(fd: i64, n: i64) -> i64 {
172 if n < 0 {
173 qg_putc(fd, 45)
174 return qg_i64(fd, -n)
175 }
176 if n == 0 {
177 qg_putc(fd, 48)
178 return 0
179 }
180 let digits: *u8 = sys_mmap(32)
181 var d: i64 = 0
182 var v: i64 = n
183 while v > 0 {
184 digits[d] = (v % 10) + 48
185 v = v / 10
186 d = d + 1
187 }
188 while d > 0 {
189 d = d - 1
190 qg_putc(fd, digits[d])
191 }
192 return 0
193}
194
195func nx_qg_emit_narrative(fd: i64, t: *QuestionTree, target: i64) -> i64 {
196 let chain: *i64 = (sys_mmap(64 * 8)) as *i64
197 let depth: i64 = nx_qg_trace_from_root(t, target, chain, 64)
198 if depth <= 0 { return -1 }
199 var i: i64 = 0
200 while i < depth {
201 let n: *QuestionNode = nx_qg_node_at(t, chain[i])
202 qg_str(fd, "L", 1)
203 qg_i64(fd, n.depth_from_root)
204 qg_str(fd, " ", 2)
205 qg_strz(fd, n.question_text)
206 if n.answering_theorem_id > 0 {
207 qg_str(fd, " -- ", 5)
208 qg_strz(fd, n.answering_author)
209 qg_str(fd, " (", 2)
210 qg_i64(fd, n.answering_year)
211 qg_str(fd, ")", 1)
212 }
213 qg_str(fd, "\n", 1)
214 i = i + 1
215 }
216 return 0
217}
218
219// ===== seed corpus =====================================================
220//
221// Pre-populates three classic chains: pi / Pythagoras / primes.
222// Provides instant illustration of the question-genealogy mechanism.
223
224func nx_qg_seed_corpus(t: *QuestionTree) -> i64 {
225 // === pi chain ===
226 let pi_root: i64 = nx_qg_add_root(t,
227 "Is there a fixed relationship between a circle's circumference and its diameter?" as *u8)
228 let pi_l1: i64 = nx_qg_add_refinement(t, pi_root, NX_QG_TIER_REFINEMENT,
229 "Is pi rational?" as *u8, 1, 1768, "Lambert" as *u8)
230 let pi_l2: i64 = nx_qg_add_refinement(t, pi_l1, NX_QG_TIER_REFINEMENT,
231 "Is pi at least algebraic?" as *u8, 53, 1882, "Lindemann" as *u8)
232 let pi_l3: i64 = nx_qg_add_refinement(t, pi_l2, NX_QG_TIER_REFINEMENT,
233 "Can we square the circle with compass and straightedge?" as *u8,
234 53, 1882, "Lindemann (corollary)" as *u8)
235 let pi_l4: i64 = nx_qg_add_refinement(t, pi_l3, NX_QG_TIER_REFINEMENT,
236 "Which numbers can compass-and-straightedge construct at all?" as *u8,
237 16, 1832, "Galois" as *u8)
238 let pi_l5: i64 = nx_qg_add_refinement(t, pi_l4, NX_QG_TIER_NICHE,
239 "How many real numbers are transcendental like pi?" as *u8,
240 15, 1874, "Cantor" as *u8)
241 let pi_l6: i64 = nx_qg_add_refinement(t, pi_l5, NX_QG_TIER_NICHE,
242 "Can we find specific non-pi non-e transcendentals?" as *u8,
243 18, 1844, "Liouville" as *u8)
244 let pi_l7: i64 = nx_qg_add_refinement(t, pi_l6, NX_QG_TIER_OPEN_RESEARCH,
245 "Is pi + e^alpha transcendental for any non-zero algebraic alpha?" as *u8,
246 0, 0, "Schanuel's conjecture (open)" as *u8)
247
248 // === Pythagoras chain ===
249 let py_root: i64 = nx_qg_add_root(t,
250 "How do I measure a distance I cannot walk along directly?" as *u8)
251 let py_l1: i64 = nx_qg_add_refinement(t, py_root, NX_QG_TIER_REFINEMENT,
252 "What if my triangle is not right-angled?" as *u8,
253 94, -100, "Greek geometers / Law of cosines" as *u8)
254 let py_l2: i64 = nx_qg_add_refinement(t, py_l1, NX_QG_TIER_REFINEMENT,
255 "What if my space is not flat (Earth's surface, curved 3D)?" as *u8,
256 0, 1854, "Riemann" as *u8)
257 let py_l3: i64 = nx_qg_add_refinement(t, py_l2, NX_QG_TIER_REFINEMENT,
258 "What about spacetime in physics?" as *u8,
259 0, 1908, "Minkowski" as *u8)
260 let py_l4: i64 = nx_qg_add_refinement(t, py_l3, NX_QG_TIER_REFINEMENT,
261 "How do gravity and matter curve spacetime?" as *u8,
262 0, 1915, "Einstein" as *u8)
263 let py_l5: i64 = nx_qg_add_refinement(t, py_l4, NX_QG_TIER_NICHE,
264 "How do we experimentally detect the predicted metric curvature?" as *u8,
265 0, 2015, "LIGO collaboration" as *u8)
266
267 // === primes chain ===
268 let pr_root: i64 = nx_qg_add_root(t,
269 "Why can't every integer be split evenly into smaller pieces?" as *u8)
270 let pr_l1: i64 = nx_qg_add_refinement(t, pr_root, NX_QG_TIER_REFINEMENT,
271 "How many primes are there?" as *u8,
272 11, -300, "Euclid IX.20" as *u8)
273 let pr_l2: i64 = nx_qg_add_refinement(t, pr_l1, NX_QG_TIER_REFINEMENT,
274 "Are primes distributed in any pattern as you go to infinity?" as *u8,
275 5, 1896, "Hadamard + de la Vallee Poussin (PNT)" as *u8)
276 let pr_l3: i64 = nx_qg_add_refinement(t, pr_l2, NX_QG_TIER_REFINEMENT,
277 "Can we predict the next prime exactly?" as *u8,
278 0, 1859, "Riemann (hypothesis, open)" as *u8)
279 let pr_l4: i64 = nx_qg_add_refinement(t, pr_l3, NX_QG_TIER_REFINEMENT,
280 "Can we test whether a 2048-bit number is prime without factoring?" as *u8,
281 0, 2002, "Agrawal-Kayal-Saxena (AKS)" as *u8)
282 let pr_l5: i64 = nx_qg_add_refinement(t, pr_l4, NX_QG_TIER_NICHE,
283 "Can we use the prime/factor asymmetry for secure communication?" as *u8,
284 74, 1977, "Rivest-Shamir-Adleman (RSA)" as *u8)
285 let pr_l6: i64 = nx_qg_add_refinement(t, pr_l5, NX_QG_TIER_OPEN_RESEARCH,
286 "Can quantum computers factor large integers fast enough to break RSA?" as *u8,
287 0, 1994, "Shor (algorithm) + active engineering work" as *u8)
288
289 return t.n_nodes
290}