{"id":50565277,"url":"https://github.com/velvetmonkey/trace-logic-lean","last_synced_at":"2026-06-04T14:01:03.417Z","repository":{"id":362167890,"uuid":"1257500156","full_name":"velvetmonkey/trace-logic-lean","owner":"velvetmonkey","description":"Lean 4 / Mathlib formalisation of Hoffman trace logic for finite Markov chains. Trace tower, semantic order transitivity, transient hidden blocks. 0 sorry.","archived":false,"fork":false,"pushed_at":"2026-06-02T23:34:49.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-03T01:16:15.455Z","etag":null,"topics":["formal-verification","lean4","markov-chains","mathlib","schur-complement","stochastic-matrices","trace-logic"],"latest_commit_sha":null,"homepage":null,"language":"Lean","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/velvetmonkey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-02T18:31:52.000Z","updated_at":"2026-06-02T23:35:48.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/velvetmonkey/trace-logic-lean","commit_stats":null,"previous_names":["velvetmonkey/trace-logic-lean"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/velvetmonkey/trace-logic-lean","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/velvetmonkey%2Ftrace-logic-lean","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/velvetmonkey%2Ftrace-logic-lean/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/velvetmonkey%2Ftrace-logic-lean/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/velvetmonkey%2Ftrace-logic-lean/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/velvetmonkey","download_url":"https://codeload.github.com/velvetmonkey/trace-logic-lean/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/velvetmonkey%2Ftrace-logic-lean/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33907694,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-04T02:00:06.755Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["formal-verification","lean4","markov-chains","mathlib","schur-complement","stochastic-matrices","trace-logic"],"created_at":"2026-06-04T14:01:02.066Z","updated_at":"2026-06-04T14:01:03.393Z","avatar_url":"https://github.com/velvetmonkey.png","language":"Lean","funding_links":[],"categories":[],"sub_categories":[],"readme":"# trace-logic-lean\n\n[![Lean 4](https://img.shields.io/badge/Lean-4.28.0-blue)](https://lean-lang.org/)\n[![Mathlib](https://img.shields.io/badge/Mathlib-v4.28.0-purple)](https://github.com/leanprover-community/mathlib4)\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)\n[![Proofs](https://img.shields.io/badge/proofs-Phase%205%20%2F%200%20sorry-brightgreen)](TraceLogic)\n\nLean 4 / Mathlib formalisation of Phase 5 Hoffman trace logic for finite Markov chains.\n\n## Mathematical Setting\n\nThe library works with finite row-stochastic Markov transition matrices over `ℝ`, decomposed into visible and hidden states. It defines the visible-visible, visible-hidden, hidden-visible, and hidden-hidden blocks, and the trace matrix\n\n```lean\nP_VV + P_VH * (1 - P_HH)⁻¹ * P_HV\n```\n\nas a Schur-complement-style effective transition matrix on visible states. It also includes nonnegativity predicates and a matrix operator norm wrapper via `Matrix.toEuclideanCLM`.\n\n## Theorems Proved\n\n| Name | Statement |\n| --- | --- |\n| `hidden_block_transient` | If `‖P_HH‖ \u003c 1`, then `I - P_HH` is invertible. |\n| `neumann_series` | Under `‖P_HH‖ \u003c 1`, the inverse `(I - P_HH)⁻¹` exists as the hidden-block resolvent. |\n| `row_stochastic_mulVec_ones` | A row-stochastic matrix maps the all-ones vector to the all-ones vector. |\n| `blockHV_mulVec_ones` | The hidden-visible and hidden-hidden blocks satisfy the hidden-row all-ones identity. |\n| `blockVV_blockVH_mulVec_ones` | The visible-visible and visible-hidden blocks satisfy the visible-row all-ones identity. |\n| `IsNonneg.mul` | Products of nonnegative matrices are nonnegative. |\n| `IsNonneg.add` | Sums of nonnegative matrices are nonnegative. |\n| `IsNonneg.submatrix` | Submatrices of nonnegative matrices are nonnegative. |\n| `trace_nonneg` | Under the stated Phase 1 hypotheses, the trace matrix is nonnegative. |\n| `inv_blockHV_mulVec_ones` | The hidden-block inverse identity used in the trace row-sum proof. |\n| `trace_row_sum` | Each row of the trace matrix sums to `1`. |\n| `trace_row_stochastic` | The trace matrix is row-stochastic. |\n| `trace_order_refl` | Trace order is reflexive in the Phase 1 skeleton. |\n| `trace_order` | Entrywise dominance order on matrices: `A \u003c= B` iff `A i j \u003c= B i j` for all entries. |\n| `trace_order_trans` | Transitivity of the entrywise dominance order, proved by `le_trans`. |\n| `trace_order_Trans` | `Trans` instance for the entrywise dominance order, enabling `calc` chains. |\n\n## Target 5 Scope\n\nTarget 5 proves transitivity of the **entrywise dominance order**:\n\n```lean\ntrace_order A B := forall i j, A i j \u003c= B i j\n```\n\nThis is not the Schur-complement / trace-quotient order. The deeper trace-quotient direction is handled separately in Phase 3 through identities such as\n\n```text\nTr_H2 (Tr_H1 P) = Tr_(H1+H2) P\n```\n\nrequires a block-matrix-inversion formalisation for nested hidden-state eliminations.\n\n## Phase 3: Trace Tower\n\nPhase 3 proves the **Trace Tower Property**, also called the Schur-complement composition law:\n\n```lean\ntrace_tower :\n  traceTwo P = traceMatrix P\n```\n\nThis states that tracing out `h1` and then `h2` agrees with tracing out the combined hidden block `h1 ⊕ h2` in one step. The theorem assumes the three invertibility conditions required for the Schur complements to be defined:\n\n- `IsUnit (1 - blockHH (reindexForTrace P))`\n- `IsUnit (1 - blockHH (traceMatrix (reindexForTrace P)))`\n- `IsUnit (1 - blockHH P)`\n\nThe proof is zero-sorry. Because Mathlib does not currently provide the full 2x2 block-matrix inversion formula needed here, the development proves roughly fifteen block-equation helper lemmas, including the reindexing block identities, the `Y1`/`Y2` elimination equations, the `Q_matrix` block identities, and the final correction identity used to assemble the tower law.\n\nPhase 3 also introduces the trace-semantic order:\n\n```lean\ntrace_sem_le A B\n```\n\nThis means that `B` is obtained from `A` by extending with finitely many hidden states and applying `traceMatrix`. Reflexivity is proved by the empty-hidden witness, and `trace_sem_le_implies_trace_order` proves that, under nonnegativity hypotheses on the witness matrix and hidden-block inverse, the trace-semantic order refines the entrywise dominance order.\n\n## Phase 4: Semantic Transitivity\n\nPhase 4 proves `trace_sem_le_trans`. The theorem composes a witness `P1` on `n ⊕ Fin k1` and a witness `P2` on `n ⊕ Fin k2` into a combined hidden-state witness, using six private helper lemmas for hidden-type reindexing, block-diagonal inverses, and Schur-correction splitting.\n\nThe transitivity result is unconditional modulo the pre-existing invertibility hypotheses inherent to the Schur complement. No definitions were changed and no positivity or nonnegativity assumptions were added.\n\n## Phase 5: Transient Hidden Blocks\n\nPhase 5 discharges the Schur-complement invertibility hypotheses for transient hidden blocks. It introduces:\n\n- `IsStrictlySubstochastic`: entrywise nonnegative square matrices whose row sums are all strictly less than `1`.\n- `IsTransientHidden`: entrywise nonnegative square matrices whose some power has all row sums strictly less than `1`.\n- `mulVec_one_sub_injective`: injectivity of `(1 - A).mulVec` for strictly substochastic `A`.\n- `isUnit_one_sub_of_strictly_substochastic`: `1 - A` is a unit for strictly substochastic `A`.\n- `isUnit_one_sub_of_transient`: `1 - A` is a unit for transient hidden blocks.\n- `trace_row_stochastic_substochastic`: trace row-stochasticity without a separate invertibility hypothesis.\n- `trace_tower_substochastic`: the trace tower law with invertibility discharged from strict substochasticity.\n- `trace_sem_le_trans_substochastic`: trace-semantic order transitivity with invertibility discharged from strict substochasticity.\n- `trace_tower_transient`: the trace tower law with invertibility discharged from transient-hidden-block hypotheses.\n- `trace_sem_le_trans_transient`: trace-semantic order transitivity with invertibility discharged from transient-hidden-block hypotheses.\n\nFor all transient Markov-chain hidden blocks in this formal sense, the trace tower and trace-semantic transitivity results are unconditional: the required inverses are proved from the finite-power row-sum escape condition rather than assumed separately. The proof avoids Perron-Frobenius by reducing the transient case to the same maximum-entry argument applied to `A^N`.\n\n## Future Work\n\nOptional future work is to connect this finite-power row-sum definition of transience to spectral-radius and Perron-Frobenius formulations once Mathlib has more infrastructure for nonnegative matrices.\n\n## Building\n\n```bash\nlake exe cache get\nlake build\n```\n\n## Verification\n\nThe Phase 5 source compiles cleanly with Mathlib v4.28.0 and contains no `sorry` or `admit`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvelvetmonkey%2Ftrace-logic-lean","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvelvetmonkey%2Ftrace-logic-lean","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvelvetmonkey%2Ftrace-logic-lean/lists"}