diff --git a/research/production-low-code-compiler/PROOF.md b/research/production-low-code-compiler/PROOF.md new file mode 100644 index 0000000000..34b3c24780 --- /dev/null +++ b/research/production-low-code-compiler/PROOF.md @@ -0,0 +1,173 @@ +# Exact direct selection for the production low-code compiler + +## Claim and source boundary + +For every admitted odd prime q, 1≤d≤64 and positive integer R, the new +`LowCodes` returns exactly the same radices, size, code width, GL_d(F_q) +lexicographic ranks, inverse ranks and `(request, common, matrix)` codes as +the retained source, on its well-typed valid domain. The public `rank`, +`unrank`, `encode` and `decode` methods and the `Constraints` class execute +unchanged source bytes; only constructor admission and the two row methods +are replaced. The proof below applies to every prime, although the executable +constructor accepts only primes≤257 or a verified power-of-two certificate. +The actual selected q*=213·2^80+1 is admitted without trial division. + +This is an **offline finite compilation** result. Python integer arithmetic, +source extraction and array access are charged in the compilation model below; +they are not free operations on runtime tapes. No recursive call, rank, +label, payload operation, paid histogram, source count or selected frontier +changes. No new κ follows, and no signed-invoice edit is proposed. + +The exact live consumer ancestry is `production_native.build_native` → +`Catalogue(q)` → `LowCodes(q,64,len(requests))`. The physical controller's +cohort loads the Gaussian leaf's PR3087 archive; its nested PR3055, PR2899 and +PR2809 archives contain the low-code module and actual catalogue/route +consumers. `source_binding.py` authenticates the declared inputs, opens only +regular uniquely named archive members, and compares the low-code, +catalogue, route and oracle bytes against separately declared live pins. +It compiles authenticated source bytes, so a stale `.pyc` is not evidence. + +The `Catalogue.low_classes` and `compile_route` definitions used by the +verifier are AST-extracted **unchanged complete definitions** from those +source bytes. The route uses the original oracle arithmetic; no payload +engine is replaced by a mock. The fixture instantiates a legitimate fixed +integral shear, not the entire selected chart catalogue. This demonstrates +real consumer compatibility at the exact q* and d=64, but does not execute +`build_native`, compile its complete macro tuple, or run a physical payload. +The historical R480/T16 controller is not the newer selected PR5413 supplier. + +## Retained counting invariant + +This paragraph recalls Jose Manuel's `selected-source-packets/PROOF.md`, +“Finite low codes without a GL64 lookup table”, rather than claiming a new +GL ranking construction. Suppose r0; a zero c cannot contain the +supplied admissible rank. In the no-pivot case q^E≤T: the remaining d-j-1 +coordinates must distinguish the q^E coefficient solutions. These facts +justify every division in `select_symbol` on valid inputs. + +## Closed prefix counts and direct inverse + +Let P(v)=Σ_{uh]. + +Thus `vector_rank` adds exactly the same source summand that its old +`for smaller in range(value)` loop accumulated, before calling the unchanged +`choose`. Induction over columns gives identical state and row rank. + +To select the unique nonempty interval containing a residual rank k, the +first two cases use `divmod(k,T)` and `divmod(k,T-q^(E-1))`. The quotient is +the symbol and the remainder is its interval offset. + +For the third case put e=q^E. The exceptional interval is +[hT,(h+1)T-e), possibly empty. For k<(h+1)T-e, ordinary `divmod(k,T)` selects +the correct symbol: this includes all intervals before h and the retained +part of h. For k≥(h+1)T-e, add e before `divmod`; this restores the deleted +e positions and selects exactly one of the symbols h+1,…,q-1. This also +works when T=e, when the h interval is empty and must be skipped. The +result always satisfies P(v)≤kq, 1√q. A composite positive q has a prime +divisor≤√q, a contradiction. Hence the checks prove q prime. For the selected +q, the retained congruence 7^((q-1)/2)=-1 mod q implies both witness checks; +213<2^80 gives F²>q. The verifier evaluates the integer equalities directly. +No probable-prime assumption, floating-point computation or trial scan up +to q is used for this case. Small-field admission trial-divides only to +floor(√q), under the explicit q≤257 bound. The certificate object type and +its requested-q binding are checked; a caller-supplied object returning q +cannot substitute for a certificate. + +## Compilation work and storage + +Use a classical arbitrary-precision bit model. Set L=ceil(log2(q+1)) and +B=d²L+ceil(log2(2R+1))+2, which bounds the whole code and mixed-radix +intermediates. This is a model upper bound, not a measured CPython CPU bill. +With schoolbook multiplication/division of b-bit integers costing O(b²), +modular inverse by Euclid may conservatively be bounded by O(L³). + +There are exactly d² next-symbol positions per full rank or unrank. At a +position with r preceding rows, `Constraints.next` scans at most r basis +rows, each of length r, costing O(r²) field operations. `choose` normalizes +one r-entry row using a modular inverse and sorts at most r pivots. Summed +over positions this is O(d^4 L³) bit work. Powers q^e with e≤d at O(d²) +positions can be recomputed by repeated squaring in +O(d^4 L² log(d+1)) bit work. The unchanged mixed-radix loop performs O(d) +multiplications/divisions on at most B-bit integers, costing O(dB²). +Constructor radices/product fit within these bounds. Thus the deliberately +conservative total is + + O(d^4 L³ log(d+1) + d B²) + +per constructor/rank/unrank/encode/decode operation, with the certificate +adding O(L³) bit work. The return code itself can require Θ(d²L+log R) bits; +we do not charge it as one fixed-size machine word. The inequality covers +the original d≤64 domain and also states the natural dimension dependence. + +The retained rows, constraint basis, radices and temporary coefficient +vectors occupy O(d²L) bits; the full code/product occupies O(B). Schoolbook +arithmetic can use O(B) temporary bits, giving O(d²L+B) peak mathematical +working storage, including input/output matrices. No cache grows with the +number of calls. This is not Python allocator/RSS reclamation or a literal +fixed-tape space bound. + +In contrast the source constructor tests q-2 trial divisors for a prime. +Its old vector rank loops Σ_{ij}m_ij times and unrank inspects +Σ_{ij}(m_ij+1) symbols for a returned matrix m. These are source-loop +counts, not timings or field-operation counts. Dense selected-field codes +make them field-sized; the new exact interval formulas still visit only +d² positions. The verifier reports both old counts and instrumented new +position counts for actual q*GL64 examples. Source interval counting, +Gaussian elimination and big-integer costs are all still paid above. + +## Remaining obligations + +The compiler does not enumerate or store all GL64 classes, remove +`compile_node`'s eager outer macro tuple, prove a regional instruction +emitter, discharge every selected denominator/chart condition, change the +finite-control runtime into a uniform RAM, or prove its tape-cost refinement. +The full `Catalogue` request preparation, complete factory, runtime directory +producer, recursive parking, error/precision and outer multiplication +contracts remain separate. Finite source equivalence does not by itself +make the complete source factory practical. No independent human or +formal-kernel review is claimed. diff --git a/research/production-low-code-compiler/README.md b/research/production-low-code-compiler/README.md new file mode 100644 index 0000000000..362214ecba --- /dev/null +++ b/research/production-low-code-compiler/README.md @@ -0,0 +1,80 @@ +# Direct production low-code compilation + +The actual historical physical complex controller fixes +`q*=213*2^80+1`, but its retained `LowCodes` trial-divides through q and +scans up to q symbols at every coordinate. This package replaces those +scans with exact closed-form prefix counts and inverse interval selection. +It preserves the source's complete lexicographic GL codes, mixed-radix +encoding, request/view tags and code width. + +The all-size source-equivalence proof and conservative compilation bound are +in [PROOF.md](PROOF.md). For dimension d, L=ceil(log2(q+1)) and +B=d²L+ceil(log2(2R+1))+2, the bit-work upper bound is +`O(d^4 L³ log(d+1)+d B²)` and mathematical working storage is `O(d²L+B)`. +These are offline compilation costs, not a fixed-tape runtime tariff. +The existing PR2234/controller witness7 certifies the selected prime; this +package reuses that certificate in constructor admission. + +The verifier compares all48 GL2(F3),480 GL2(F5) and11,232 GL3(F3) matrices +with the unchanged source. A separate determinant enumeration checks the +complete GL2 ordering. Every reachable small prefix checks the interval +formula, including a zero-length exceptional interval. Three genuine +q*GL64 classes exercise endpoints and a seeded dense ordinal. Each rank/unrank +pair uses8,192 direct coordinate visits; the receipt also records the +field-sized alphabet counts that the old source would perform. + +The actual nested production archive chain is authenticated through +PR3087→PR3055→PR2899→PR2809. Unchanged `Catalogue.low_classes` and +`compile_route` source definitions consume the new codes at q*, d=64; +the latter compiles a fixed integral shear and its complete target code. +These are bounded source-slice consumer checks. They do not instantiate +all requests, construct the complete factory or execute a production payload. + +```sh +python3.12 -B scripts/research_package.py --package research/production-low-code-compiler --check-only +python3.12 -B scripts/research_package.py --package research/production-low-code-compiler +# Direct replay also works in a checked Git-free declared-input export: +python3.12 -I -O -B research/production-low-code-compiler/verify.py +``` + +Default replay is read-only and requires byte-exact typed RESULT equality. +`--write-result` writes only a missing result. Scientific controls reject +invalid certificates, composite/uncertified fields, invalid codes and dependent +matrices; an omitted exceptional subtraction and Fermat-only primality test +have explicit falsifiers. Separate CLI controls reject missing/changed +sources and altered typed receipt bytes. Assertions are not used for gates. + +The eager outer macro tuple and complete GL64 execution remain open. This +historical R480/T16 controller is not the newer selected PR5413 native +supplier. No recursive invoice or runtime arithmetic is changed; no new κ, +full multiplication theorem, practical complete factory or tape-space +reclamation is claimed. + +## Open next questions + +Can the outer macro schedule be compiled without complete materialization +while preserving exact PCs and chronological dispatch? Start from actual +`compile_node`, its low-class loops and the separately investigated regional +Cursor emitter. Variable residual lengths and complete runtime/header costs +remain the blockers. + +Can the full source request/chart preparation be built at q*? First isolate +and authenticate that phase, then identify every remaining eager construction +site. The current compiler closes only its low-code prerequisite. Structured +questions and the changed task scope are in [TASK.json](TASK.json). + +## Attribution + +JoyboyBrian, with substantial OpenAI Codex assistance. Apache-2.0. +Jose Manuel supplies the GL lexicographic ranking and source packet proof, +`Constraints`, original low-code and physical caller/ordinary/complex engines; +all unchanged source notices remain in their pinned archives. The current +work adds closed prefix formulas, direct selection, certified admission and +source-equivalence/cost evidence, not a new GL ranking construction or prime. +PR2234 supplies the fixed prime certificate. The physical caller retains +Douglas Colkitt's selected source, David Arias, Nick Petalas, Adam Gall, +Aakash Thakkar and the predecessor authors credited in the retained archives. +No independent human or formal-kernel review is claimed. + +Canonical investigation: +[Discussion2238](https://github.com/CrocSwap/integer-mult-bounds/discussions/2238#discussioncomment-19173180). diff --git a/research/production-low-code-compiler/RESULT.json b/research/production-low-code-compiler/RESULT.json new file mode 100644 index 0000000000..b517d4551f --- /dev/null +++ b/research/production-low-code-compiler/RESULT.json @@ -0,0 +1,88 @@ +{ + "ancestry": [ + { + "member": "inputs/pr3055.tar", + "sha256": "c76e11cce0696db643715a362631b60fb14f26ba66c1e3bb5b5b0389eb52e95d" + }, + { + "member": "inputs/pr2899.tar", + "sha256": "fc4a2e07423835737c8fb3872664b16ff12aa4cf83b1e26e49878debef40c531" + }, + { + "member": "inputs/pr2809.tar", + "sha256": "ee1d4ec05e3c872d264be3b38f71a8c153acf37427f5d3ba87f8e15440c9ccf0" + } + ], + "controls": [ + "wrong_prime_witness", + "incomplete_factor", + "composite_large_factor", + "forged_certificate_object", + "wrong_requested_prime", + "large_uncertified_prime", + "negative_rank", + "rank_at_size", + "code_at_limit", + "dependent_matrix", + "wrong_dimension", + "omitted_exceptional_subtraction_falsified", + "Fermat_only_false_positive" + ], + "prefix_states": 1412, + "schema_version": 1, + "scope": "offline exact low-code compiler; no production payload", + "selected": { + "cases": [ + { + "direct_rank_and_unrank_positions": 8192, + "matrix_sha256": "d8a6d1ba39176e1f2ec39e260b4cc3a4354df7dcd5d6c2af30c84b620c376d0c", + "old_rank_symbol_iterations": 64, + "old_unrank_symbol_iterations": 4160, + "ordinal_sha256": "7c1a1cd0173a5a089799beb41aa9a0f4893e487f1eb1afc416e9605d6a7bd47b" + }, + { + "direct_rank_and_unrank_positions": 8192, + "matrix_sha256": "d2445ea8e3d12493db695a58f85079bf86457c12d7e4b1fcc5b103fcf5a5c7bf", + "old_rank_symbol_iterations": 1054724913471143994214053838785, + "old_unrank_symbol_iterations": 1054724913471143994214053842881, + "ordinal_sha256": "e7d445a305393f88414f6d821788589e1df64ca077f24a006a2970159fe8b71f" + }, + { + "direct_rank_and_unrank_positions": 8192, + "matrix_sha256": "572cd694516e8d5c2a09a7ef17d3f3e2562a6733002edb0e3abe282d0028c26b", + "old_rank_symbol_iterations": 523322491067770214987702649645, + "old_unrank_symbol_iterations": 523322491067770214987702653741, + "ordinal_sha256": "16991cbd6b29b0f10e2bd1ac22780562ef96445f1f2643fbd77cc2aced50b352" + } + ], + "code_bits": 359378, + "dimension": 64, + "old_constructor_trial_divisors": 257501199577916014212415487, + "prime_factor": 1208925819614629174706176, + "prime_witness": 7, + "q": 257501199577916014212415489, + "requests": 28278, + "route_code_sha256": "90e7b9ce12ab0677965250677600239b35c5821c828935c52c6afb02179cef62", + "route_target_sha256": "af44baf2aa68f05b5baab027d2b2ea69e42eb74e64dd5279cbbc7af7bfabcf20" + }, + "small": [ + { + "dimension": 2, + "matrices": 48, + "q": 3, + "sha256": "732e7ef15185deaa2e9a800dbc472504e9cebea6dd8305887c2b9866e376f323" + }, + { + "dimension": 2, + "matrices": 480, + "q": 5, + "sha256": "f1dfad5c006fda335531c31e2c84f1fb3a6d23155164e6d349fa4636b1a61a6f" + }, + { + "dimension": 3, + "matrices": 11232, + "q": 3, + "sha256": "ae67533d8418e86ca862e756739cb3c379f203a5982c0fd9fb3b234101f260c2" + } + ] +} diff --git a/research/production-low-code-compiler/SOURCES.json b/research/production-low-code-compiler/SOURCES.json new file mode 100644 index 0000000000..b4af967d88 --- /dev/null +++ b/research/production-low-code-compiler/SOURCES.json @@ -0,0 +1,90 @@ +{ + "schema_version": 1, + "base_commit": "32890bc5de034ab8fc93ac88ead7279a6a416d04", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "fc3d4ba105e1f097d0d7d051a308281e86ab1446", + "sha256": "66974efdced4083c00025f97d95d83909a226cdf801edb9301c195c6641f6903" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "f126dd2e2dad2b669e75d1d0d0bd05c600725602", + "sha256": "f7a48bfa2659b88378282a8eee7d9fe52cdf505594124c4d1686b58510fffd72" + }, + { + "path": "research/physical-complex-controller/README.md", + "usage": "input", + "git_blob": "4ac8b4effb1381aa06aadd1716f53a4c4849a306", + "sha256": "1ecf61d038679d5358682ea979083a7b28f378f7b002085e7f2efb1f5a4c229a" + }, + { + "path": "research/physical-complex-controller/check_prime.py", + "usage": "input", + "git_blob": "a19b07762d064b8fc0cd1d81cfabd2d22a4c9096", + "sha256": "791a0233fa704eafa634b6968c68f81a83b95170b30c527ba93599b8b8e76643" + }, + { + "path": "research/physical-complex-controller/cohort.py", + "usage": "input", + "git_blob": "3876ab737f3c2a90100749e4ba141f1923caff79", + "sha256": "8fb650c0cc3dfaad94811149b0c0e725777a8cff195c5f21e21a7576494e84f1" + }, + { + "path": "research/physical-complex-controller/production_native.py", + "usage": "input", + "git_blob": "045b0dd1aa6ec47051730fc01fa8b3c6a825ab72", + "sha256": "4c1f8f69212162bd297010c6e21a32e31755cbfe2e40f9935b8d87a9e4260d46" + }, + { + "path": "research/physical-gaussian-leaf/inputs/pr3087.tar", + "usage": "input", + "git_blob": "6daedf70a927fa1359caec68d56fc0cbdaeb54dd", + "sha256": "d7e9c04a5e6d3f76158555d84080786c7cd8028ca31a61c9399de2b2c67bfd53" + }, + { + "path": "research/physical-gaussian-leaf/leaf_sources.py", + "usage": "input", + "git_blob": "31c33dbed6061ca7c0455a9170fd05fb388f4607", + "sha256": "e0f958a0169257ba08eac5e025a3fc7ce99009efc18974cdd231f16758004014" + }, + { + "path": "research/selected-bit-node/catalogue.py", + "usage": "input", + "git_blob": "0efc0575a7623ac41c094d2e8772beda5a9fdc29", + "sha256": "83ea88f82d4a83c5f889774bfe3519b7ebaa24b6a0e2a969dafff012107a89bf" + }, + { + "path": "research/selected-bit-physical-caller/inputs/pr2753/predecessor/vendor/low_codes.py", + "usage": "input", + "git_blob": "737edfc4a10f4b7b3b97a7cef4b40864efd806e6", + "sha256": "f657e17f6088c840e3f7783e662257630f6d2c1e71c217721ffbca4d6ac93e87" + }, + { + "path": "research/selected-bit-physical-caller/inputs/pr2753/predecessor/vendor/oracle.py", + "usage": "input", + "git_blob": "244f131466698a3ace10b657242fe1f65c07fd1f", + "sha256": "7bd18089e32ce48085b5e3a75159f6a82cdb2649ec682c53db05e399d97aef67" + }, + { + "path": "research/selected-bit-physical-caller/inputs/pr2753/predecessor/vendor/routes.py", + "usage": "input", + "git_blob": "35531201dc349a811dfabc6f1f6e64697d665194", + "sha256": "ed7dc3679451696ab1dd841146b215c9515a3eec5e4ff3763f33c315f1696ada" + }, + { + "path": "research/selected-source-packets/PROOF.md", + "usage": "input", + "git_blob": "8f7d9eecd576f55e4aa194e58155ec29dc8893a6", + "sha256": "b5d3c1329570a7ec2aaf793319f07784f3ccf5a4bda8c43ee43ad65b972cbd53" + }, + { + "path": "research/selected-source-packets/README.md", + "usage": "input", + "git_blob": "a623e81257247b4628d863872917bc210b72233d", + "sha256": "9e5df87184bed8e836a95c5b94a68b7a4dde813d0e75c4a6a8f1c41ba2fcd51d" + } + ] +} diff --git a/research/production-low-code-compiler/TASK.json b/research/production-low-code-compiler/TASK.json new file mode 100644 index 0000000000..0e52faac29 --- /dev/null +++ b/research/production-low-code-compiler/TASK.json @@ -0,0 +1,94 @@ +{ + "schema_version": 1, + "task_id": "uniform-transfer-audit", + "priority_revision": 7, + "base_commit": "32890bc5de034ab8fc93ac88ead7279a6a416d04", + "original_card": { + "id": "uniform-transfer-audit", + "question": "Does one quantified step of the proposed #4100 all-size construction hold at its actual caller?", + "starting_points": [ + "docs/research/research-family-status.md", + "certificates/selected-result.json", + "research/unconditional-batched-crt/README.md" + ], + "methods": [ + "Prove one missing implication with explicit quantified hypotheses.", + "Find an exact counterexample at the claimed interface boundary." + ], + "acceptance_gate": "Identify the proposition and what would change downstream; do not equate a finite replay with a universal proof.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read PROOF.md and AUDIT.md in #4100. Select one distinct obligation: CRT total repair, native/free-algebra lifting, precision/conditioning, or complete fixed-tape cost. This is an author-submitted proof, not an accepted unconditional theorem.", + "scope": "Source-binding orientation only; no scientific replay, theorem acceptance or supplier admission. Budget any heavy replay separately." + }, + "first_experiment": "Check live handoffs; name one proposition, its caller, quantified domain and dependency closure. Independently prove the implication or exhibit a precise gap/counterexample. Prioritize CRT.md total repair or COMPLEX.md free-algebra lift only if unclaimed. Stop at the chosen obligation; do not substitute finite samples or root arithmetic for an all-size proof, or launch the complete package by default.", + "bottleneck_link": "Finite supplier improvements are useful only under the retained transfer obligations.", + "allowed_variations": [ + "One CRT repair, native lift, precision/conditioning or tape-cost proposition, with its exact caller." + ], + "scope_change_triggers": [ + "Replacing a quantified obligation with another finite smoke test.", + "Treating archive intake, an author PASS receipt or a finite composed fixture as discharge of the universal hypotheses." + ], + "overlap_terms": [ + "uniform transfer", + "all-size", + "precision", + "4100", + "unconditional-batched-crt" + ], + "existing_checks": [ + { + "scope": "PR #4100: proposed unconditional construction and finite checks, without independent acceptance.", + "evidence": "research/unconditional-batched-crt/README.md", + "remaining": "Independent proof audit of one caller-bound all-size implication; all other premises remain explicit.", + "status": "author-checked", + "source_commit": "337d04939571a637aeab54a0f58f54fde811663a", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + } + ] + }, + "scope_status": "changed", + "actual_scope": "Replace field-sized alphabet scans in the actual historical physical controller low-code compiler by exact direct interval selection, preserving every GL code; certify the existing selected prime at admission.", + "scope_change_reason": "Explicit director assignment follows the physical-complex-controller practical finite-compilation handoff. This is a source compiler side result, not the card default #4100 whole multiplier claim.", + "bottleneck_link": "The production native factory fixes q*=213*2^80+1 but retained LowCodes trial-divides through q and rank/select scans alphabet symbols; eliminating those loops makes a necessary GL64 code prerequisite directly executable.", + "budget_minutes": 60, + "stop_rule": "20-minute gate required exact source equivalence, original consumer binding and actual selected-field GL64 examples; no generic lazy wrapper or free runtime arithmetic.", + "outcome": "completed", + "evidence": "PROOF.md, RESULT.json, source archive chain and registered normal/optimized/integrity checks", + "author": "JoyboyBrian, with substantial OpenAI Codex assistance", + "ai_assistance": "Substantial OpenAI Codex assistance for source investigation, proof, implementation and controls; root coordinates a separate AI peer review. No human or formal-kernel verification.", + "open_questions": [ + { + "question": "Can the complete macro tuple be replaced by a bounded-storage finite-program representation without changing continuation PCs?", + "why_it_matters": "Low-code generation alone does not make build_native practical.", + "first_step": "Join actual compile_node outer low-class loops to exact region lengths, retaining the separately investigated residual Cursor emitter.", + "blocked_by": "Full outer-schedule compilation, variable residual lengths and runtime/header cost refinement remain." + }, + { + "question": "Can the complete actual selected chart catalogue and ordinary factory be instantiated without further field-sized construction?", + "why_it_matters": "The current selected-prime demo executes genuine consumer definitions but not every source request or production payload.", + "first_step": "Authenticate and time the finite request/chart phase independently, then map remaining eager construction sites.", + "blocked_by": "Do not run full GL64 enumeration or infer supplier admission from this prerequisite." + } + ], + "coordination": { + "claim": "https://github.com/CrocSwap/integer-mult-bounds/discussions/2238#discussioncomment-19173180", + "overlap": { + "open_prs": 352, + "discussion_records": 4747, + "refreshed_at": "2026-10-25T04:14:44.963072+00:00", + "limits": "Bodies and current local sources; unpublished work excluded." + }, + "distinct_scope": "Formal lead owns inner residual Cursor emission; this package only changes finite low-code compilation." + }, + "invoice": { + "changed": false, + "reason": "Identical GL order, request/view labels, runtime operations and recursive calls; compilation side result only." + } +} diff --git a/research/production-low-code-compiler/VALIDATION.md b/research/production-low-code-compiler/VALIDATION.md new file mode 100644 index 0000000000..363142f6cd --- /dev/null +++ b/research/production-low-code-compiler/VALIDATION.md @@ -0,0 +1,23 @@ +# Validation record + +Python3.12, standard library, macOS. Each final registered command was run +individually and passed; the aggregate launcher was not redundantly rerun. + +- `python3.12 -B research/production-low-code-compiler/verify.py --write-result`: regenerated the sole local draft receipt after implementation/control changes. +- `python3.12 -I -O -B research/production-low-code-compiler/verify.py`: PASS, same typed receipt. +- `python3.12 -I -O -B research/production-low-code-compiler/test_integrity.py`: PASS; a fresh declared-input tree with PATH excluding Git replays the science, then missing/changed sources, archive corruption and bool-for-int receipt substitution reject. +- `python3.12 -B scripts/research_package.py --package research/production-low-code-compiler --check-only`: PASS metadata and pins; not mathematical acceptance. + +Receipt SHA label printed by verifier: `2b36ebdbda7f7d7e59cf5dbb6191c72455d9721a2583bc5959bfc2b2494cdc9c`. +This is its canonical structured-result digest, not the file SHA. + +A separate AI reviewer independently reran normal/optimized checks and checked +9,688 additional exceptional-interval cases over q3,5,7, including empty +intervals, without finding a blocking proof/code issue. This is not human or +formal-kernel verification. Final source-history, committed-byte and official +export results are recorded in the external delivery record against its exact +publication head, so this file does not assert a future self-referential head. + +Unrun: complete production factory, all GL64 enumeration, physical payload, +full selected caller/frontier replay and formal proof assistant. The new result +is finite offline compilation with a written all-size source-equivalence proof. diff --git a/research/production-low-code-compiler/VERIFY.json b/research/production-low-code-compiler/VERIFY.json new file mode 100644 index 0000000000..ee2539abc7 --- /dev/null +++ b/research/production-low-code-compiler/VERIFY.json @@ -0,0 +1,54 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/physical-complex-controller/README.md", + "research/physical-complex-controller/check_prime.py", + "research/physical-complex-controller/cohort.py", + "research/physical-complex-controller/production_native.py", + "research/physical-gaussian-leaf/inputs/pr3087.tar", + "research/physical-gaussian-leaf/leaf_sources.py", + "research/selected-bit-node/catalogue.py", + "research/selected-bit-physical-caller/inputs/pr2753/predecessor/vendor/low_codes.py", + "research/selected-bit-physical-caller/inputs/pr2753/predecessor/vendor/oracle.py", + "research/selected-bit-physical-caller/inputs/pr2753/predecessor/vendor/routes.py", + "research/selected-source-packets/PROOF.md", + "research/selected-source-packets/README.md" + ], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 30, + "checks": "source-equivalence-and-selected-prime" + }, + { + "argv": [ + "{python}", + "-I", + "-O", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 30, + "checks": "optimized-source-equivalence" + }, + { + "argv": [ + "{python}", + "-I", + "-O", + "-B", + "{package}/test_integrity.py" + ], + "timeout_seconds": 30, + "checks": "Git-free optimized replay, missing/changed source, altered archive and typed-receipt corruption" + } + ] +} diff --git a/research/production-low-code-compiler/low_codes.py b/research/production-low-code-compiler/low_codes.py new file mode 100644 index 0000000000..9ca1a83342 --- /dev/null +++ b/research/production-low-code-compiler/low_codes.py @@ -0,0 +1,110 @@ +# SPDX-License-Identifier: Apache-2.0 +"""Closed-form fixed-field compiler, retaining the exact source GL ordering. + +JoyboyBrian with OpenAI Codex assistance. Constraints and mixed-radix methods +are executed unchanged from Jose Manuel's retained PR2501/PR2569 lineage. +This is offline finite compilation, not a new physical tape tariff. +""" +from dataclasses import dataclass +from math import gcd, prod, isqrt +from source_binding import OLD, need + +PRIME = 213 * (1 << 80) + 1 + + +@dataclass(frozen=True) +class PowerTwoCertificate: + q: int + exponent: int + witness: int + + def check(self): + q, k, a = self.q, self.exponent, self.witness + need(type(q) is type(k) is type(a) is int and q >= 3 and 1 <= k < q.bit_length(), + "typed odd-prime certificate") + factor = 1 << k + need((q - 1) % factor == 0 and ((q - 1) // factor) % 2 == 1 and factor * factor > q, + "complete large power-of-two factor") + need(1 < a < q and pow(a, q - 1, q) == 1 and + gcd(pow(a, (q - 1) // 2, q) - 1, q) == 1, "prime order witness") + return q + + +SELECTED_CERTIFICATE = PowerTwoCertificate(PRIME, 80, 7) + + +def admit_prime(q, certificate=None): + need(type(q) is int and q >= 3, "odd prime") + if certificate is not None: + need(type(certificate) is PowerTwoCertificate and certificate.check() == q, + "typed certificate binds requested q") + elif q == PRIME: + SELECTED_CERTIFICATE.check() + else: + # Bounded reference-domain admission, never a selected-field trial loop. + need(q <= 257 and all(q % a for a in range(2, isqrt(q) + 1)), + "larger primes require a power-two certificate") + + +def prefix_count(constraints, reduced, total, value): + """Number of admissible completions with next symbol strictly below value.""" + if constraints.inconsistent: + return value * total + _row, rhs, pivot = reduced + exponent = len(constraints.rows) - len(constraints.basis) + if pivot is not None: + return value * (total - constraints.q ** (exponent - 1)) + return value * total - (constraints.q ** exponent if value > rhs else 0) + + +def select_symbol(constraints, reduced, total, rank): + """Inverse prefix selection; at most one exceptional symbol, no q-loop.""" + if constraints.inconsistent: + return divmod(rank, total) + _row, rhs, pivot = reduced + exponent = len(constraints.rows) - len(constraints.basis) + if pivot is not None: + count = total - constraints.q ** (exponent - 1) + need(count > 0, "nonempty independent completion") + return divmod(rank, count) + excluded = constraints.q ** exponent + need(excluded <= total, "source independent-row completion bound") + # The exceptional interval ends here, including its possible zero length. + if rank >= (rhs + 1) * total - excluded: + rank += excluded + return divmod(rank, total) + + +class LowCodes(OLD.LowCodes): + """Same GL labels and inherited public methods; direct row rank/select.""" + def __init__(self, q, dimension, requests=1, certificate=None): + admit_prime(q, certificate) + need(type(dimension) is int and 1 <= dimension <= 64 and + type(requests) is int and requests > 0, "fixed source vocabulary") + self.q, self.dimension, self.requests = q, dimension, requests + self.radices = tuple(q ** dimension - q ** k for k in range(dimension)) + self.size = prod(self.radices) + self.limit = 2 * requests * self.size + self.bits = max(1, (self.limit - 1).bit_length()) + + def vector_rank(self, rows, vector): + constraints, rank = OLD.Constraints(rows, self.q), 0 + for column, value in enumerate(vector): + reduced = constraints.next(column) + total = self.q ** (self.dimension - column - 1) + rank += prefix_count(constraints, reduced, total, value) + constraints.choose(reduced, value) + need(constraints.inconsistent, "independent low row") + return rank + + def vector_unrank(self, rows, rank): + constraints, vector = OLD.Constraints(rows, self.q), [] + for column in range(self.dimension): + reduced = constraints.next(column) + total = self.q ** (self.dimension - column - 1) + value, rank = select_symbol(constraints, reduced, total, rank) + need(0 <= value < self.q, "low-row rank range") + vector.append(value) + constraints.choose(reduced, value) + need(rank == 0 and constraints.inconsistent, "complete independent low row") + return tuple(vector) diff --git a/research/production-low-code-compiler/source_binding.py b/research/production-low-code-compiler/source_binding.py new file mode 100644 index 0000000000..d44978250f --- /dev/null +++ b/research/production-low-code-compiler/source_binding.py @@ -0,0 +1,95 @@ +# SPDX-License-Identifier: Apache-2.0 +"""Authenticate actual production ancestry; execute source bytes, never pyc.""" +import ast +import builtins +import io +import json +import math +import tarfile +import types +from dataclasses import dataclass +from fractions import Fraction +from hashlib import sha256 +from pathlib import Path + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] + + +def need(ok, message): + if not ok: + raise ValueError(message) + + +def authenticate(root=ROOT): + manifest = json.loads((HERE / "SOURCES.json").read_text()) + result = {} + for row in manifest["files"]: + if row["usage"] == "input": + raw = (root / row["path"]).read_bytes() + need(sha256(raw).hexdigest() == row["sha256"], "input changed: " + row["path"]) + result[row["path"]] = raw + return result + + +def member(raw, path): + with tarfile.open(fileobj=io.BytesIO(raw), mode="r:") as archive: + hits = [m for m in archive.getmembers() if m.name == path] + need(len(hits) == 1 and hits[0].isfile(), "one regular source archive member: " + path) + return archive.extractfile(hits[0]).read() + + +def module(name, raw, imports=None): + result = types.ModuleType(name) + imports = {} if imports is None else imports + def importing(key, *args, **kwargs): + if key in imports: + return imports[key] + raise ImportError("undeclared source import: " + key) + result.__dict__["__builtins__"] = dict(vars(builtins), __import__=importing) + exec(compile(raw, "", "exec"), result.__dict__) + return result + + +def extract(raw, names, namespace): + tree = ast.parse(raw) + nodes = [node for node in tree.body if getattr(node, "name", None) in names] + need({node.name for node in nodes} == set(names), "exact source extraction") + exec(compile(ast.Module(body=nodes, type_ignores=[]), "", "exec"), namespace) + return namespace + + +def load(): + inputs = authenticate() + raw = inputs["research/physical-gaussian-leaf/inputs/pr3087.tar"] + ancestry = [] + for path in ("inputs/pr3055.tar", "inputs/pr2899.tar", "inputs/pr2809.tar"): + raw = member(raw, path) + ancestry.append({"member": path, "sha256": sha256(raw).hexdigest()}) + prefix = "inputs/pr2753/predecessor/" + low_raw = member(raw, prefix + "vendor/low_codes.py") + catalogue_raw = member(raw, prefix + "catalogue.py") + routes_raw = member(raw, prefix + "vendor/routes.py") + oracle_raw = member(raw, prefix + "vendor/oracle.py") + pairs = ((low_raw, "research/selected-bit-physical-caller/inputs/pr2753/predecessor/vendor/low_codes.py"), + (catalogue_raw, "research/selected-bit-node/catalogue.py"), + (routes_raw, "research/selected-bit-physical-caller/inputs/pr2753/predecessor/vendor/routes.py"), + (oracle_raw, "research/selected-bit-physical-caller/inputs/pr2753/predecessor/vendor/oracle.py")) + for value, path in pairs: + need(value == inputs[path], "production archive agrees with declared source: " + path) + words = module("original_words", member(raw, prefix + "vendor/words.py")) + old = module("original_low_codes", low_raw, {"math": math, "words": words}) + oracle = module("original_oracle", oracle_raw, {"math": math, "words": words}) + # Extract two complete source definitions; no payload engine or stub is run. + env = {"dataclass": dataclass, "Fraction": Fraction, "need": words.need, + "__name__": __name__, "__builtins__": dict(vars(builtins), + __import__=lambda name, *a, **k: oracle if name == "oracle" else builtins.__import__(name, *a, **k))} + extract(routes_raw, {"Route", "compile_route"}, env) + tree = ast.parse(catalogue_raw) + cls = next(n for n in tree.body if isinstance(n, ast.ClassDef) and n.name == "Catalogue") + low = next(n for n in cls.body if isinstance(n, ast.FunctionDef) and n.name == "low_classes") + low_env = {} + exec(compile(ast.Module(body=[low], type_ignores=[]), "", "exec"), low_env) + return old, env["compile_route"], low_env["low_classes"], ancestry + +OLD, compile_route, low_classes, ANCESTRY = load() diff --git a/research/production-low-code-compiler/test_integrity.py b/research/production-low-code-compiler/test_integrity.py new file mode 100644 index 0000000000..a28fee9ff9 --- /dev/null +++ b/research/production-low-code-compiler/test_integrity.py @@ -0,0 +1,62 @@ +# SPDX-License-Identifier: Apache-2.0 +"""Git-free cold replay and failures before source execution, under -O.""" +import json +import os +from pathlib import Path +import shutil +import subprocess +import sys +import tempfile + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +PACKAGE = HERE.relative_to(ROOT) + + +def need(ok, message): + if not ok: + raise ValueError(message) + + +def main(): + inputs = json.loads((HERE / "VERIFY.json").read_text())["inputs"] + with tempfile.TemporaryDirectory(prefix="production-low-codes-controls-") as temp: + root = Path(temp) + target = root / PACKAGE + shutil.copytree(HERE, target, ignore=shutil.ignore_patterns("__pycache__", "*.pyc")) + for name in inputs: + out = root / name + out.parent.mkdir(parents=True, exist_ok=True) + shutil.copyfile(ROOT / name, out) + env = dict(os.environ, PATH=str(root / "no-tools"), PYTHONDONTWRITEBYTECODE="1") + def call(script, succeeds, marker): + result = subprocess.run([sys.executable, "-I", "-O", "-B", str(target / script)], + cwd=root, env=env, capture_output=True, text=True, timeout=25) + need((result.returncode == 0) == succeeds and marker in result.stdout + result.stderr, + "CLI control " + marker + ": " + result.stdout + result.stderr) + # Actual standalone cold replay with no Git or third-party dependency. + call("verify.py", True, "PASS_PRODUCTION_LOW_CODE_COMPILER") + probe = target / "import_probe.py" + probe.write_text("import sys\nfrom pathlib import Path\nsys.path.insert(0,str(Path(__file__).resolve().parent))\nimport source_binding\n") + name = "research/selected-bit-physical-caller/inputs/pr2753/predecessor/vendor/low_codes.py" + source = root / name + raw = source.read_bytes() + source.unlink() + call("import_probe.py", False, "FileNotFoundError") + source.write_bytes(raw + b"\n# changed source\n") + call("import_probe.py", False, "input changed") + source.write_bytes(raw) + archive = root / "research/physical-gaussian-leaf/inputs/pr3087.tar" + raw_archive = archive.read_bytes() + archive.write_bytes(raw_archive[:-1] + bytes([raw_archive[-1] ^ 1])) + call("import_probe.py", False, "input changed") + archive.write_bytes(raw_archive) + receipt = target / "RESULT.json" + content = json.loads(receipt.read_text()) + content["schema_version"] = True + receipt.write_text(json.dumps(content, indent=2, sort_keys=True) + "\n") + call("verify.py", False, "typed deterministic result equality") + print("PASS_LOW_CODE_INTEGRITY Git-free replay; missing/changed source; changed archive; typed receipt") + +if __name__ == "__main__": + main() diff --git a/research/production-low-code-compiler/verify.py b/research/production-low-code-compiler/verify.py new file mode 100644 index 0000000000..f9e79f6fca --- /dev/null +++ b/research/production-low-code-compiler/verify.py @@ -0,0 +1,173 @@ +# SPDX-License-Identifier: Apache-2.0 +"""Complete small-field differential tests and actual selected-prime compilation.""" +import argparse +from hashlib import sha256 +from itertools import product, islice +import json +from pathlib import Path +import random +import sys +from types import SimpleNamespace + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import low_codes as compiled +from low_codes import LowCodes, PRIME, PowerTwoCertificate, SELECTED_CERTIFICATE, prefix_count, select_symbol +from source_binding import OLD, ANCESTRY, compile_route, low_classes, need + +HERE = Path(__file__).resolve().parent + + +def digest(value): + if type(value) is int: + value = {"integer_hex": hex(value)} + return sha256(json.dumps(value, sort_keys=True, separators=(",", ":")).encode()).hexdigest() + + +def reject(fn): + try: + fn() + except (ValueError, TypeError): + return + raise ValueError("invalid case accepted") + + +def run(): + small, branch_states = [], 0 + # Complete independent determinant oracle, distinct from source counting. + for q in (3, 5): + expected = [((a, b), (c, d)) for a, b, c, d in product(range(q), repeat=4) + if (a*d-b*c) % q] + fast, old = LowCodes(q, 2, 3), OLD.LowCodes(q, 2, 3) + got = [] + for ordinal in range(fast.size): + matrix = fast.unrank(ordinal) + need(matrix == old.unrank(ordinal) and fast.rank(matrix) == old.rank(matrix) == ordinal, + "complete source differential") + got.append(matrix) + for request in (0, 2): + for view in (False, True): + code = fast.encode(request, view, matrix) + need(code == old.encode(request, view, matrix) and fast.decode(code) == (request, view, matrix), + "exact complete tag and low-class code") + # Source order is lexicographic within row-completion mixed radices. + need(got == expected, "independent determinant/lexicographic enumeration") + small.append({"q": q, "dimension": 2, "matrices": len(got), "sha256": digest(got)}) + # All GL3(F3) codes cover genuinely dependent and independent prefix systems. + fast, old = LowCodes(3, 3), OLD.LowCodes(3, 3) + whole = sha256() + for ordinal in range(fast.size): + matrix = fast.unrank(ordinal) + need(matrix == old.unrank(ordinal) and fast.rank(matrix) == ordinal, "complete GL3 source differential") + whole.update(bytes(x for row in matrix for x in row)) + small.append({"q": 3, "dimension": 3, "matrices": fast.size, "sha256": whole.hexdigest()}) + # Test closed formulas against literal sums at every reachable prefix of all + # two-dimensional completions, including zero-length exceptional intervals. + kinds = set() + for q in (3, 5): + rows_options = [()] + [(v,) for v in product(range(q), repeat=2) if any(v)] + for rows in rows_options: + for vector in product(range(q), repeat=2): + c = OLD.Constraints(rows, q) + for column, value in enumerate(vector): + reduced = c.next(column) + total = q ** (1-column) + counts = [total-c.excluded(reduced, x) for x in range(q)] + need(min(counts) >= 0, "nonnegative source completion counts") + for v in range(q+1): + need(prefix_count(c, reduced, total, v) == sum(counts[:v]), "literal prefix sum") + for rank in range(sum(counts)): + symbol, tail = select_symbol(c, reduced, total, rank) + need(sum(counts[:symbol]) + tail == rank and 0 <= tail < counts[symbol], + "literal interval inverse") + kind = "inconsistent" if c.inconsistent else ("pivot" if reduced[2] is not None else "exceptional") + kinds.add(kind) + branch_states += 1 + c.choose(reduced, value) + need(kinds == {"inconsistent", "pivot", "exceptional"}, "all structural branches") + SELECTED_CERTIFICATE.check() + # This is the actual field and complete dimension, not a surrogate q=2. + codes = LowCodes(PRIME, 64, 28278) + need(all(getattr(LowCodes, name) is getattr(OLD.LowCodes, name) + for name in ("rank", "unrank", "encode", "decode")), "unchanged mixed-radix public methods") + position_count = [0] + def count(fn): + def wrapped(*args): + position_count[0] += 1 + return fn(*args) + return wrapped + compiled.prefix_count = count(prefix_count) + compiled.select_symbol = count(select_symbol) + rng = random.Random(19173180) + ranks = (0, codes.size-1, rng.randrange(codes.size)) + selected = [] + for ordinal in ranks: + before = position_count[0] + matrix = codes.unrank(ordinal) + need(codes.rank(matrix) == ordinal, "selected GL64 inverse") + need(position_count[0]-before == 2*64*64, "exact direct row-position count") + selected.append({"ordinal_sha256": digest(ordinal), "matrix_sha256": digest(matrix), + "old_rank_symbol_iterations": sum(map(sum, matrix)), + "old_unrank_symbol_iterations": sum(map(sum, matrix))+64*64, + "direct_rank_and_unrank_positions": position_count[0]-before}) + compiled.prefix_count, compiled.select_symbol = prefix_count, select_symbol + # Real Catalogue iterator body; consume only its first source classes. + iterator = low_classes(SimpleNamespace(codes=codes)) + prefix = list(islice(iterator, 2)) + need([codes.rank(m) for m in prefix] == [0, 1], "actual Catalogue low-class prefix") + # Real compile_route body and Route type from the factory's nested archive. + # A fixed integral shear is a legitimate chart; no runtime payload is run. + chart = tuple(tuple(int(i == j) + int(i == 0 and j == 1) for j in range(64)) for i in range(64)) + route = compile_route(matrix, chart, codes) + expected = tuple(tuple((row[j] + (row[0] if j == 1 else 0)) % PRIME for j in range(64)) for row in matrix) + need(route.low == matrix and route.target_low == expected and route.q == PRIME and route.dimension == 64, + "actual source route compiler accepts exact selected low codes") + code = codes.encode(28277, True, route.target_low) + need(codes.decode(code) == (28277, True, route.target_low), "actual route target request/view roundtrip") + controls = [] + cases = { + "wrong_prime_witness": lambda: PowerTwoCertificate(PRIME, 80, 1).check(), + "incomplete_factor": lambda: PowerTwoCertificate(PRIME, 79, 7).check(), + "composite_large_factor": lambda: PowerTwoCertificate(9, 3, 2).check(), + "forged_certificate_object": lambda: LowCodes(9, 2, certificate=SimpleNamespace(check=lambda: 9)), + "wrong_requested_prime": lambda: LowCodes(3, 2, certificate=SELECTED_CERTIFICATE), + "large_uncertified_prime": lambda: LowCodes(263, 2), + "negative_rank": lambda: codes.unrank(-1), + "rank_at_size": lambda: codes.unrank(codes.size), + "code_at_limit": lambda: codes.decode(codes.limit), + "dependent_matrix": lambda: codes.rank(tuple((0,)*64 for _ in range(64))), + "wrong_dimension": lambda: codes.rank(((1, 0), (0, 1))), + } + for name, fn in cases.items(): + reject(fn); controls.append(name) + # Falsify the tempting omission of the exceptional interval correction. + c = OLD.Constraints([], 3); reduced = c.next(0) + need(prefix_count(c, reduced, 3, 1) == 2 and 1*3 != 2, "exceptional subtraction discriminator") + controls.append("omitted_exceptional_subtraction_falsified") + # Prime-order proof needs a large factor; Fermat alone accepts this composite. + need(pow(2, 340, 341) == 1, "Fermat-only primality counterexample") + controls.append("Fermat_only_false_positive") + return {"schema_version": 1, "scope": "offline exact low-code compiler; no production payload", + "ancestry": ANCESTRY, "small": small, "prefix_states": branch_states, + "selected": {"q": PRIME, "dimension": 64, "requests": 28278, + "code_bits": codes.bits, "prime_factor": 1 << 80, "prime_witness": 7, + "old_constructor_trial_divisors": PRIME-2, "cases": selected, + "route_target_sha256": digest(route.target_low), "route_code_sha256": digest(code)}, + "controls": controls} + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--write-result", action="store_true") + args = parser.parse_args() + result = run() + target = HERE / "RESULT.json" + text = json.dumps(result, indent=2, sort_keys=True) + "\n" + if args.write_result: + need(not target.exists(), "do not overwrite a retained result") + target.write_text(text) + else: + need(target.read_text() == text, "typed deterministic result equality") + print("PASS_PRODUCTION_LOW_CODE_COMPILER", digest(result)) + +if __name__ == "__main__": + main()