memory.hoon 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. /= common /common/table/memory
  2. /= verifier-memory /common/table/verifier/memory
  3. /= * /common/zeke
  4. =/ util constraint-util
  5. ~% %memory-table ..ride ~
  6. |%
  7. +$ ion-triple-alt [size=pelt dyck=pelt leaf=pelt]
  8. +$ memory-bank
  9. $:(n=^ ax=@ op-l=@ op-r=@)
  10. +$ memory-bank-ex
  11. $: parent=ion-triple-alt
  12. left=ion-triple-alt
  13. right=ion-triple-alt
  14. ==
  15. ::
  16. ::
  17. ++ ids
  18. |%
  19. :: belts
  20. ++ pad-idx 0
  21. ++ axis-idx 1
  22. ++ axis-ioz-idx 2
  23. ++ axis-flag-idx 3
  24. ++ leaf-l-idx 4
  25. ++ leaf-r-idx 5
  26. ++ op-l-idx 6
  27. ++ op-r-idx 7
  28. ++ count-idx 8
  29. ++ count-inv-idx 9
  30. ++ dmult-idx 10
  31. ++ mult-idx 11
  32. ++ mult-lc-idx 12
  33. ++ mult-rc-idx 13
  34. :: pelts
  35. ++ input-idx 14
  36. ++ parent-size-idx 17
  37. ++ parent-dyck-idx 20
  38. ++ parent-leaf-idx 23
  39. ++ lc-size-idx 26
  40. ++ lc-dyck-idx 29
  41. ++ lc-leaf-idx 32
  42. ++ rc-size-idx 35
  43. ++ rc-dyck-idx 38
  44. ++ rc-leaf-idx 41
  45. ++ inv-idx 44
  46. :: mega-ext
  47. ++ ln-idx 47
  48. ++ nc-idx 50
  49. ++ kvs-idx 53
  50. ++ kvs-ioz-idx 56
  51. ++ kvsf-idx 59
  52. ++ decode-mset-idx 62
  53. ++ op0-mset-idx 65
  54. --
  55. ++ test-nocks
  56. ^- (list ^)
  57. :~ [[1 2 3] 3 0 1]
  58. [[1 2 3] 3 0 2]
  59. [[1 2 3] 3 1 4]
  60. [[1 2 3] 3 4 0 2]
  61. [[1 2 3] 3 4 1 99]
  62. [[1 2 3] 4 0 2]
  63. [[1 2 3] 5 [0 1] 0 1]
  64. [[1 2 3] 5 [0 1] 0 2]
  65. [42 6 [1 0] [1 2] 1 3]
  66. [42 6 [1 1] [1 2] 1 3]
  67. [42 7 [4 0 1] 1 15]
  68. [42 8 [4 0 1] 1 15]
  69. [[1 2 3] [4 0 2] 4 1 2]
  70. [[1 2 3] 2 [0 1] 1 0 2]
  71. new-pow-5
  72. new-pow-10
  73. ==
  74. ::
  75. ++ new-pow-5
  76. [ [1 2 3 4 5 0]
  77. [6 [3 0 62] [0 0] 4 0 62]
  78. [6 [3 0 30] [0 0] 4 0 30]
  79. [6 [3 0 14] [0 0] 4 0 14]
  80. [6 [3 0 6] [0 0] 4 0 6]
  81. [6 [3 0 2] [0 0] 4 0 2]
  82. 1
  83. 0
  84. ]
  85. ::
  86. ++ new-pow-10
  87. [ [1 2 3 4 5 6 7 8 9 10 0]
  88. [6 [3 0 2.046] [0 0] 4 0 2.046]
  89. [6 [3 0 1.022] [0 0] 4 0 1.022]
  90. [6 [3 0 510] [0 0] 4 0 510]
  91. [6 [3 0 254] [0 0] 4 0 254]
  92. [6 [3 0 126] [0 0] 4 0 126]
  93. [6 [3 0 62] [0 0] 4 0 62]
  94. [6 [3 0 30] [0 0] 4 0 30]
  95. [6 [3 0 14] [0 0] 4 0 14]
  96. [6 [3 0 6] [0 0] 4 0 6]
  97. [6 [3 0 2] [0 0] 4 0 2]
  98. 1
  99. 0
  100. ]
  101. ::
  102. ++ test-all
  103. ^- ?
  104. %- levy
  105. :_ same
  106. %+ iturn test-nocks
  107. |= [i=@ n=^]
  108. ~& "testing #{<i>}: {<n>}"
  109. ?: (test n)
  110. ~& " result #{<i>}: PASS"
  111. %.y
  112. ~& " result #{<i>}: FAIL"
  113. !!
  114. ::
  115. ++ test-n
  116. ~/ %test-n
  117. |= id=@ud
  118. ^- ?
  119. =/ nock (snag id test-nocks)
  120. ~& "testing #{<id>}: {<nock>}"
  121. ?: (test nock)
  122. ~& " #{<id>} {<nock>} passed"
  123. %.y
  124. ~& " #{<id>} {<nock>} failed"
  125. %.n
  126. ::
  127. ++ test
  128. ~/ %test
  129. |= nock=^
  130. ^- ?
  131. =/ ext-chals
  132. (turn (gulf 1 num-chals-rd1:chal) |=(n=@ (mod (digest-to-atom:tip5 (hash-leaf:tip5 n)) p)))
  133. =/ mega-ext-chals
  134. (turn (gulf 1 (lent chal-names-basic:chal)) |=(n=@ (mod (digest-to-atom:tip5 (hash-leaf:tip5 n)) p)))
  135. =/ dat (fink:fock nock)
  136. =/ base-table=table-mary (pad:funcs (build:funcs q.dat))
  137. =/ ext-table (extend:funcs base-table ext-chals q.dat)
  138. =/ mid-table (weld-exts:tlib base-table ext-table)
  139. =/ mega-ext-table (mega-extend:funcs mid-table mega-ext-chals q.dat)
  140. ::
  141. =/ num-rows len.array.p.base-table
  142. =/ tab=table-mary
  143. :: %- print-table
  144. :(weld-exts:tlib base-table ext-table mega-ext-table)
  145. =/ terminals (terminal:funcs tab)
  146. %- (test:zkvm-debug tab nock)
  147. :* mega-ext-chals
  148. terminals
  149. (table-to-verifier-funcs:tlib funcs)
  150. ==
  151. ::
  152. ++ print-table (print-table:zkvm-debug column-names:static:common)
  153. ++ print-row
  154. ~/ %print-row
  155. |= row=(list belt)
  156. ^- (list belt)
  157. =- row
  158. (print-row:zkvm-debug row ext-column-names:static:common)
  159. ::
  160. ++ print-full-row
  161. ~/ %print-full-row
  162. |= row=(list belt)
  163. ^- (list belt)
  164. =- row
  165. (print-row:zkvm-debug row column-names:static:common)
  166. ::
  167. ::
  168. :: gen-nock
  169. ::
  170. :: generates nock=[s f], parametrized by n, which evaluates to prod
  171. :: s.t. the Nock reduction rules only use Nock 2 and Nock 0's into
  172. :: the subject s
  173. ++ gen-nock
  174. ~/ %gen-nock
  175. |= [n=@ prod=*]
  176. |^
  177. =+ %+ roll (reap n 0)
  178. |= [i=@ accx=_2 axs=(list @)]
  179. =/ new-accx (mul 2 +(accx))
  180. :- new-accx
  181. [new-accx axs]
  182. :_ (sf 2)
  183. %+ roll axs
  184. |= [a=@ nock=_`*`[[0 +(accx)] prod]]
  185. ^- ^
  186. [(sf a) nock]
  187. ++ sf
  188. |= a=@
  189. ^- *
  190. [2 [0 1] [0 a]]
  191. --
  192. ::
  193. ++ bioz
  194. ~/ %bioz
  195. |= b=belt
  196. ^- belt
  197. ?:(=(b 0) 0 (binv b))
  198. ::
  199. ++ pioz
  200. ~/ %pioz
  201. |= p=pelt
  202. ^- pelt
  203. ?:(=(p pzero) pzero (pinv p))
  204. ::
  205. ++ ifp-compress
  206. ~/ %ifp-compress
  207. |= [ifp=ion-triple-alt a=pelt b=pelt c=pelt]
  208. ^- pelt
  209. :(padd (pmul a size.ifp) (pmul b dyck.ifp) (pmul c leaf.ifp))
  210. ::
  211. ++ variable-indices
  212. ^- (map col-name @) ^~
  213. %- ~(gas by *(map term @))
  214. (zip-up column-names:static:common (range (lent column-names:static:common)))
  215. ::
  216. ++ grab
  217. ~/ %grab
  218. |= [idx=@ =row]
  219. ^- belt
  220. (~(snag bop row) idx)
  221. ::
  222. ++ grab-pelt
  223. ~/ %grab-pelt
  224. |= [idx=@ =row]
  225. ^- pelt
  226. dat:(~(swag bop row) idx 3)
  227. ::
  228. :: bft: breadth-first traversal
  229. ++ bft
  230. ~/ %bft
  231. |= tres=(list *)
  232. ^- (list *)
  233. =/ qu=(list *) tres
  234. =| out=(list *)
  235. |-
  236. ?~ qu
  237. (flop out)
  238. =+ %+ roll `(list *)`qu
  239. |= [q=* nu-qu=(list *) nu-out=_out]
  240. ^- [(list *) (list *)]
  241. ?@ q [nu-qu [q nu-out]]
  242. [[+:q -:q nu-qu] [q nu-out]]
  243. $(qu (flop nu-qu), out nu-out)
  244. ::
  245. :: na-bft: non-atomic breadth-first traversal
  246. ::
  247. :: i.e. only internal nodes are counted, not atoms.
  248. ++ na-bft
  249. ~/ %na-bft
  250. |= tres=(list *)
  251. ^- (list ^)
  252. =/ qu=(list ^)
  253. %- flop
  254. %+ roll tres
  255. |= [n=* acc=(list ^)]
  256. ?@ n acc [n acc]
  257. =| out=(list ^)
  258. |-
  259. ?~ qu
  260. (flop out)
  261. =- $(qu (flop nu-qu), out nu-out)
  262. %+ roll `(list ^)`qu
  263. |= [q=^ nu-qu=(list ^) nu-out=_out]
  264. ^- [(list ^) (list ^)]
  265. ?@ -.q
  266. ?@ +.q
  267. [nu-qu [q nu-out]]
  268. [[+.q nu-qu] [q nu-out]]
  269. ?@ +.q
  270. [[-.q nu-qu] [q nu-out]]
  271. [[+.q -.q nu-qu] [q nu-out]]
  272. ::
  273. :: bfta: breadth-first traversal w/ axis labelling
  274. ++ bfta
  275. ~/ %bfta
  276. |= tres=(list *)
  277. ^- (list [* @])
  278. =/ qu=(list [* @]) (turn tres |=(n=* [n 1]))
  279. =| out=(list [* @])
  280. |-
  281. ?~ qu
  282. (flop out)
  283. =+ %+ roll `(list [* @])`qu
  284. |= [q=[n=* a=@] nu-qu=(list [* @]) nu-out=_out]
  285. ^- [(list [* @]) (list [* @])]
  286. ?@ n.q [nu-qu [q nu-out]]
  287. [[[+.n.q (succ (mul 2 a.q))] [-.n.q (mul 2 a.q)] nu-qu] [q nu-out]]
  288. $(qu (flop nu-qu), out nu-out)
  289. ::
  290. ++ go-left
  291. ~/ %go-left
  292. |= a=@
  293. (mul 2 a)
  294. ::
  295. ++ go-right
  296. ~/ %go-right
  297. |= a=@
  298. ?:(=(a 0) 0 (succ (mul 2 a)))
  299. ::
  300. :: rna-bfta: reversed non-atomic breadth-first traversal w axes
  301. ::
  302. :: Returns the breadth-first traversal in reverse order bc the output is
  303. :: piped to add-ions, which is most efficient if constructed from the bottom
  304. :: of the tree to the top.
  305. ++ rna-bfta
  306. ~/ %rna-bfta
  307. |= tres=(list [* ?])
  308. ^- (list memory-bank)
  309. =/ qu=(list [^ @])
  310. %- flop
  311. %+ roll tres
  312. |= [[n=* f=?] acc=(list [^ @])]
  313. ?@ n acc
  314. ?:(f [[n 1] acc] [[n 0] acc])
  315. =| mbl=(list memory-bank)
  316. |-
  317. ?~ qu
  318. mbl
  319. =- $(qu (flop nu-qu), mbl nu-mbl)
  320. %+ roll `(list [^ @])`qu
  321. |= [[n=^ a=@] nu-qu=(list [^ @]) nu-mbl=_mbl]
  322. ^- [(list [^ @]) (list memory-bank)]
  323. ?@ -.n
  324. ?@ +.n
  325. [nu-qu [[n a 0 0] nu-mbl]]
  326. [[[+.n (go-right a)] nu-qu] [[n a 0 1] nu-mbl]]
  327. ?@ +.n
  328. [[[-.n (go-left a)] nu-qu] [[n a 1 0] nu-mbl]]
  329. [[[+.n (go-right a)] [-.n (go-left a)] nu-qu] [[n a 1 1] nu-mbl]]
  330. ::
  331. :: add-ions: adds ions to the output of rna-bfta
  332. ++ add-ions
  333. ~/ %add-ions
  334. |= $: rna-bfta-lst=(list memory-bank)
  335. alf=pelt
  336. a=pelt b=pelt c=pelt
  337. d=pelt
  338. e=pelt f=pelt g=pelt
  339. ==
  340. ^- (list memory-bank-ex)
  341. =- ion-list
  342. %+ roll rna-bfta-lst
  343. |= $: mb=memory-bank
  344. ion-map=(map * ion-triple-alt)
  345. ion-list=(list memory-bank-ex)
  346. ==
  347. =/ left=ion-triple-alt
  348. ?@ -.n.mb (atom-ion -.n.mb alf)
  349. (~(got by ion-map) -.n.mb)
  350. =/ right=ion-triple-alt
  351. ?@ +.n.mb (atom-ion +.n.mb alf)
  352. (~(got by ion-map) +.n.mb)
  353. =/ parent (cons-ion alf left right)
  354. :* (~(put by ion-map) [n.mb parent])
  355. :_ ion-list
  356. [parent left right]
  357. ==
  358. ::
  359. ++ atom-ion
  360. ~/ %atom-ion
  361. |= [atom=@ alf=pelt]
  362. ^- ion-triple-alt
  363. :+ alf
  364. pzero
  365. (pelt-lift atom)
  366. ::
  367. :: +cons-ion: cons of 2 ion triples of nouns.
  368. ++ cons-ion
  369. ~/ %cons-ion
  370. |= [alf=pelt left=ion-triple-alt right=ion-triple-alt]
  371. ^- ion-triple-alt
  372. =/ alfinv=pelt (pinv alf)
  373. :+ (pmul size.left size.right)
  374. ::
  375. ;: padd
  376. :(pmul size.right size.right alfinv dyck.left)
  377. :(pmul size.right size.right alfinv alfinv)
  378. dyck.right
  379. ==
  380. ::
  381. (padd (pmul size.right leaf.left) leaf.right)
  382. ::
  383. ++ header
  384. ^- header:table ^~
  385. :* name:static:common
  386. p
  387. (lent basic-column-names:static:common)
  388. (lent ext-column-names:static:common)
  389. (lent mega-ext-column-names:static:common)
  390. (lent column-names:static:common)
  391. num-randomizers
  392. ==
  393. ::
  394. ++ num-randomizers 1
  395. ::
  396. ++ funcs
  397. ^- table-funcs
  398. ~% %funcs ..grab ~
  399. |%
  400. ::
  401. ++ build
  402. ~/ %build
  403. |= return=fock-return
  404. ^- table-mary
  405. =/ in [s.return f.return]
  406. =/ mult-mp=(map [* *] @) (~(gut by zeroes.return) -.in *(map [* *] @))
  407. =/ traversal (rna-bfta ~[[s.return %.y] [f.return %.n]])
  408. =/ len-traversal (lent traversal)
  409. =/ end
  410. (init-bpoly ~[0 0 0 0 0 0 0 0 +(len-traversal) (binv +(len-traversal)) 0 0 0 0])
  411. =- [header (zing-bpolys mtx)]
  412. %+ roll traversal
  413. |= [mb=memory-bank ct=_len-traversal mtx=_`matrix`~[end]]
  414. ^- [belt matrix]
  415. :- (dec ct)
  416. :_ mtx
  417. %- init-bpoly
  418. :~ 1 ax.mb (bioz ax.mb) ?:(=(ax.mb 0) 0 1)
  419. ::
  420. ?:(?=(@ -.n.mb) -.n.mb 0) ?:(?=(@ +.n.mb) +.n.mb 0)
  421. ::
  422. op-l.mb op-r.mb ct (binv ct)
  423. ::
  424. ?: !=(ax.mb 0) 0
  425. ?:((~(has by decodes.return) [n.mb -:n.mb +:n.mb]) 1 0)
  426. ::
  427. ?: =(ax.mb 1) 0
  428. (~(gut by mult-mp) [ax.mb -.in] 0)
  429. ::
  430. ?. ?=(@ -.n.mb) 0
  431. (~(gut by mult-mp) [(go-left ax.mb) -.in] 0)
  432. ::
  433. ?. ?=(@ +.n.mb) 0
  434. (~(gut by mult-mp) [(go-right ax.mb) -.in] 0)
  435. ==
  436. ::
  437. ++ pad
  438. ~/ %pad
  439. |= table=table-mary
  440. ^- table-mary
  441. =/ height (height-mary:tlib p.table)
  442. ?: =(height len.array.p.table)
  443. table
  444. =/ rows p.table
  445. =/ len len.array.rows
  446. ?: =(height len) table
  447. =; padding=mary
  448. table(p (~(weld ave rows) padding))
  449. %- zing-bpolys
  450. %- head
  451. %^ spin (range (sub height len)) (sub len 1)
  452. |= [i=@ ct=@]
  453. :_ (bsub ct 1)
  454. (init-bpoly ~[0 0 0 0 0 0 0 0 ct (binv ct) 0 0 0 0])
  455. ::
  456. ++ extend
  457. ~/ %extend
  458. |= [t=table-mary chals-rd1=(list belt) return=fock-return]
  459. ^- table-mary
  460. :- header
  461. =/ pr print-pelt
  462. =/ tr print-tri-mset:constraint-util
  463. =/ chals=ext-chals:chal (init-ext-chals:chal chals-rd1)
  464. =/ len len.array.p.t
  465. =/ build-and-bft=(list memory-bank-ex)
  466. =+ (add-ions (rna-bfta ~[[s.return %.y] [f.return %.n]]) [alf a b c d e f g]:chals)
  467. %+ weld -
  468. %+ reap (sub len (lent -))
  469. ^- memory-bank-ex
  470. :* *ion-triple-alt
  471. *ion-triple-alt
  472. *ion-triple-alt
  473. ==
  474. =/ subj-info=memory-bank-ex
  475. ?@ s.return *memory-bank-ex
  476. (snag 0 build-and-bft)
  477. =/ subj-pc1
  478. (ifp-compress parent.subj-info [a b c]:chals)
  479. %- zing-bpolys
  480. %+ turn build-and-bft
  481. |= mb=memory-bank-ex
  482. %- init-bpoly
  483. %+ pr subj-pc1
  484. %+ pr size.parent.mb
  485. %+ pr dyck.parent.mb
  486. %+ pr leaf.parent.mb
  487. %+ pr size.left.mb
  488. %+ pr dyck.left.mb
  489. %+ pr leaf.left.mb
  490. %+ pr size.right.mb
  491. %+ pr dyck.right.mb
  492. %+ pr leaf.right.mb
  493. %+ pr
  494. %- pinv
  495. ;: pmul
  496. (psub size.parent.mb pone)
  497. (psub size.left.mb pone)
  498. (psub size.right.mb pone)
  499. ==
  500. ~
  501. ::
  502. ++ mega-extend
  503. ~/ %mega-extend
  504. |= [table=table-mary all-chals=(list belt) return=fock-return]
  505. ^- table-mary
  506. :- header
  507. %- zing-bpolys
  508. =/ pr print-pelt
  509. =/ tr print-tri-mset:constraint-util
  510. =/ chals=mega-ext-chals:chal (init-mega-ext-chals:chal all-chals)
  511. =/ [first-row=row second-row=row]
  512. :- (~(snag-as-bpoly ave p.table) 0)
  513. (~(snag-as-bpoly ave p.table) 1)
  514. =/ first-row-ax (grab axis-idx:ids first-row)
  515. =/ first-row-fp
  516. %- ifp-compress
  517. :* :+ (grab-pelt parent-size-idx:ids first-row)
  518. (grab-pelt parent-dyck-idx:ids first-row)
  519. (grab-pelt parent-leaf-idx:ids first-row)
  520. a.chals b.chals c.chals
  521. ==
  522. =/ second-row-ax (grab axis-idx:ids second-row)
  523. =/ second-row-fp
  524. %- ifp-compress
  525. :* :+ (grab-pelt parent-size-idx:ids second-row)
  526. (grab-pelt parent-dyck-idx:ids second-row)
  527. (grab-pelt parent-leaf-idx:ids second-row)
  528. a.chals b.chals c.chals
  529. ==
  530. =/ subj-info=[ax=belt fp=pelt]
  531. ?@ s.return [0 pzero]
  532. [first-row-ax first-row-fp]
  533. =/ form-info=[ax=belt fp=pelt]
  534. ?@ s.return
  535. [first-row-ax first-row-fp]
  536. [second-row-ax second-row-fp]
  537. =/ [input-subj-fp=pelt input-form-fp=pelt]
  538. :- (padd fp.subj-info (pscal ax.subj-info d.chals))
  539. (padd fp.form-info (pscal ax.form-info d.chals))
  540. %- head
  541. %^ spin (range len.array.p.table)
  542. :* z.chals
  543. ::
  544. ?@(s.return z.chals (pmul z.chals z.chals))
  545. ::
  546. (init-ld-mset-pelt:constraint-util gam.chals)
  547. ::
  548. (init-ld-mset-pelt:constraint-util bet.chals)
  549. ::
  550. ?@ s.return
  551. (pmul z.chals input-form-fp)
  552. %+ padd (pmul z.chals input-subj-fp)
  553. :(pmul z.chals z.chals input-form-fp)
  554. ==
  555. |= $: i=@
  556. line-ct=pelt
  557. node-ct=pelt
  558. decode-mset=ld-mset-pelt:constraint-util
  559. op0-mset=ld-mset-pelt:constraint-util
  560. kvs=pelt
  561. ==
  562. =/ =row (~(snag-as-bpoly ave p.table) i)
  563. =/ parent=ion-triple-alt
  564. [(grab-pelt parent-size-idx:ids row) (grab-pelt parent-dyck-idx:ids row) (grab-pelt parent-leaf-idx:ids row)]
  565. =/ left=ion-triple-alt
  566. [(grab-pelt lc-size-idx:ids row) (grab-pelt lc-dyck-idx:ids row) (grab-pelt lc-leaf-idx:ids row)]
  567. =/ right=ion-triple-alt
  568. [(grab-pelt rc-size-idx:ids row) (grab-pelt rc-dyck-idx:ids row) (grab-pelt rc-leaf-idx:ids row)]
  569. =/ left-is-atom ?:(=((grab op-l-idx:ids row) 0) %.y %.n)
  570. =/ right-is-atom ?:(=((grab op-r-idx:ids row) 0) %.y %.n)
  571. =/ ax (grab axis-idx:ids row)
  572. =/ [pc1=pelt wt-pax=pelt pc2=pelt]
  573. :+ (ifp-compress parent [a b c]:chals)
  574. (pscal ax d.chals)
  575. (ifp-compress parent [e f g]:chals)
  576. =/ [lc1=pelt wt-lax=pelt lc2=pelt]
  577. :+ (ifp-compress left [a b c]:chals)
  578. (pscal (go-left ax) d.chals)
  579. (ifp-compress left [e f g]:chals)
  580. =/ [rc1=pelt wt-rax=pelt rc2=pelt]
  581. :+ (ifp-compress right [a b c]:chals)
  582. (pscal (go-right ax) d.chals)
  583. (ifp-compress right [e f g]:chals)
  584. =/ new-line-ct (pmul line-ct z.chals)
  585. =/ new-node-ct
  586. ?: left-is-atom
  587. ?: right-is-atom
  588. node-ct
  589. (pmul node-ct z.chals)
  590. ?: right-is-atom
  591. (pmul node-ct z.chals)
  592. :(pmul node-ct z.chals z.chals)
  593. =/ new-kvs
  594. %+ psub
  595. ;: padd
  596. kvs
  597. ::
  598. ?: left-is-atom
  599. pzero
  600. ;: pmul
  601. z.chals
  602. node-ct
  603. (padd lc1 wt-lax)
  604. ==
  605. ::
  606. ?. ?&(left-is-atom !right-is-atom)
  607. pzero
  608. ;: pmul
  609. z.chals
  610. node-ct
  611. (padd rc1 wt-rax)
  612. ==
  613. ::
  614. ?. ?&(!left-is-atom !right-is-atom)
  615. pzero
  616. ;: pmul
  617. z.chals z.chals
  618. node-ct
  619. (padd rc1 wt-rax)
  620. ==
  621. ==
  622. (pmul (padd pc1 wt-pax) line-ct)
  623. =/ new-decode-mset
  624. %- rear
  625. %- ~(add-all ld-pelt:constraint-util decode-mset)
  626. :_ ~
  627. :_ (grab dmult-idx:ids row)
  628. ;: padd
  629. (pmul j.chals (grab-pelt parent-size-idx:ids row))
  630. (pmul k.chals (grab-pelt parent-dyck-idx:ids row))
  631. (pmul l.chals (grab-pelt parent-leaf-idx:ids row))
  632. (pmul m.chals (grab-pelt lc-size-idx:ids row))
  633. (pmul n.chals (grab-pelt lc-dyck-idx:ids row))
  634. (pmul o.chals (grab-pelt lc-leaf-idx:ids row))
  635. (pmul w.chals (grab-pelt rc-size-idx:ids row))
  636. (pmul x.chals (grab-pelt rc-dyck-idx:ids row))
  637. (pmul y.chals (grab-pelt rc-leaf-idx:ids row))
  638. ==
  639. =/ new-op0-mset
  640. %- rear
  641. %- ~(add-all ld-pelt:constraint-util op0-mset)
  642. ;: weld
  643. ~[[:(padd fp.subj-info wt-pax pc2) (grab mult-idx:ids row)]]
  644. ::
  645. ?. left-is-atom ~
  646. ~[[:(padd fp.subj-info wt-lax lc2) (grab mult-lc-idx:ids row)]]
  647. ::
  648. ?. right-is-atom ~
  649. ~[[:(padd fp.subj-info wt-rax rc2) (grab mult-rc-idx:ids row)]]
  650. ==
  651. :_ [new-line-ct new-node-ct new-decode-mset new-op0-mset new-kvs]
  652. %- init-bpoly
  653. %+ pr line-ct
  654. %+ pr node-ct
  655. %+ pr kvs
  656. %+ pr (pioz kvs) :: %kvs-ioz
  657. %+ pr (pmul kvs (pioz kvs)) :: %kvsf
  658. %+ pr dat.decode-mset
  659. %+ pr dat.op0-mset
  660. ~
  661. ::
  662. ++ terminal
  663. ~/ %terminal
  664. |= =table-mary
  665. ^- bpoly
  666. =/ pr print-pelt
  667. =/ first-row (~(snag-as-bpoly ave p.table-mary) 0)
  668. =/ last-row [step.p.table-mary ~(rear ave p.table-mary)]
  669. %- init-bpoly
  670. %+ pr (grab-pelt nc-idx:ids first-row)
  671. %+ pr (grab-pelt kvs-idx:ids first-row)
  672. %+ pr (grab-pelt decode-mset-idx:ids last-row)
  673. %+ pr (grab-pelt op0-mset-idx:ids last-row)
  674. ~
  675. ::
  676. ++ boundary-constraints boundary-constraints:funcs:engine:verifier-memory
  677. ++ row-constraints row-constraints:funcs:engine:verifier-memory
  678. ++ transition-constraints transition-constraints:funcs:engine:verifier-memory
  679. ++ terminal-constraints terminal-constraints:funcs:engine:verifier-memory
  680. --
  681. --