memory.hoon 18 KB

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