{"id":42436028,"url":"https://github.com/fraware/lean-cat-nf","last_synced_at":"2026-04-05T19:02:02.295Z","repository":{"id":315938151,"uuid":"1055696424","full_name":"fraware/lean-cat-nf","owner":"fraware","description":"Category Normal Form for Lean 4","archived":false,"fork":false,"pushed_at":"2026-04-04T08:25:39.000Z","size":154,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-04T10:17:57.982Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/fraware.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":"2025-09-12T16:53:18.000Z","updated_at":"2026-04-04T08:25:44.000Z","dependencies_parsed_at":"2025-09-21T19:26:18.879Z","dependency_job_id":"6d0722ae-2fc8-47d1-a8ba-76c681f0a962","html_url":"https://github.com/fraware/lean-cat-nf","commit_stats":null,"previous_names":["fraware/lean-cat-nf"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fraware/lean-cat-nf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fraware%2Flean-cat-nf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fraware%2Flean-cat-nf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fraware%2Flean-cat-nf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fraware%2Flean-cat-nf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fraware","download_url":"https://codeload.github.com/fraware/lean-cat-nf/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fraware%2Flean-cat-nf/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31446531,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T15:22:31.103Z","status":"ssl_error","status_checked_at":"2026-04-05T15:22:00.205Z","response_time":75,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2026-01-28T05:35:55.488Z","updated_at":"2026-04-05T19:02:02.290Z","avatar_url":"https://github.com/fraware.png","language":"Lean","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# CatNF\n\n### Category normal form for Lean 4\n\nNormalize category-theoretic morphism expressions inside Lean’s metaprogramming layer—composition, identities, functorial maps, monoidal structure, and more—behind a configurable, validated pipeline.\n\n\u003cbr/\u003e\n\n[![Lean 4.8](https://img.shields.io/badge/Lean-4.8.0-5c6bc0?style=flat-square)](https://leanprover.github.io/lean4/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-546e7a?style=flat-square)](LICENSE)\n[![CI](https://img.shields.io/badge/CI-GitHub_Actions-78909c?style=flat-square)](.github/workflows/ci.yml)\n\n\u003cbr/\u003e\n\n[Contributing](CONTRIBUTING.md) · [Documentation](docs/README.md) · [User guide](docs/UserGuide.md) · [Canonical forms](docs/WhatCountsAsCanonical.md) · [Versions](docs/Compatibility.md) · [Issues](https://github.com/fraware/lean-cat-nf/issues)\n\n\u003c/div\u003e\n\n---\n\n## Overview\n\nCatNF validates configuration, flattens and rewrites morphism structure (composition, functors, monoidal pieces, and related rules), and returns a normalized `Expr` plus optional trace data.\n\n```mermaid\nflowchart LR\n  subgraph in[\"Input\"]\n    E([\"Lean Expr\"])\n  end\n  subgraph pipe[\"Pipeline\"]\n    V[Validate]\n    N[Flatten \u0026 rules]\n    M[Monoidal]\n    C[Caches \u0026 limits]\n  end\n  subgraph out[\"Output\"]\n    R([\"Normalized Expr\"])\n  end\n  E --\u003e V --\u003e N --\u003e M --\u003e C --\u003e R\n  style E fill:#e3f2fd,stroke:#5c6bc0\n  style R fill:#e8f5e9,stroke:#43a047\n  style V fill:#f5f5f5,stroke:#9e9e9e\n  style N fill:#fff8e1,stroke:#ffa726\n  style M fill:#fce4ec,stroke:#ec407a\n  style C fill:#f3e5f5,stroke:#ab47bc\n```\n\n---\n\n## Quickstart\n\n### Docker\n\n```bash\ndocker run --rm ghcr.io/fraware/lean-cat-nf:latest --help\ndocker run --rm ghcr.io/fraware/lean-cat-nf:latest bench\ndocker run --rm ghcr.io/fraware/lean-cat-nf:latest test\ndocker run --rm ghcr.io/fraware/lean-cat-nf:latest test-final\n```\n\n### One-liner install\n\n```bash\n# Linux / macOS\ncurl -sSL https://raw.githubusercontent.com/fraware/lean-cat-nf/main/setup.sh | bash\n```\n\n```powershell\n# Windows\niwr -useb https://raw.githubusercontent.com/fraware/lean-cat-nf/main/setup.bat | iex\n```\n\n### From source\n\n```bash\ngit clone https://github.com/fraware/lean-cat-nf.git\ncd lean-cat-nf\nmake dev\nmake run\nmake test\nmake bench\n```\n\nAfter `make dev`, optional global install: `make install`, then `lean-cat-nf --help`.\n\n---\n\n## Add CatNF to a Lake project\n\nUse the package name from [`Lakefile.lean`](Lakefile.lean) (here `«lean-cat-nf»`). Prefer a **commit SHA** over `main` when you need reproducibility.\n\n```lean\nrequire «lean-cat-nf» from git\n  \"https://github.com/fraware/lean-cat-nf.git\" @ \"main\"\n```\n\n---\n\n## Usage\n\nThere is no shipped `cat_nf` tactic syntax yet. Call `normalizeGoalM` or `catNFImpl` on a `Lean.Expr` from ordinary metaprogramming code.\n\n```lean\nimport Mathlib.CategoryTheory.Category.Basic\nimport Lean.Meta\nimport CatNF.Core\n\nopen Lean Meta CatNF\n\ndef demoNormalize (e : Expr) : MetaM (Expr × List AppliedRewrite) := do\n  let config : Config := {\n    maxSteps := 100\n    timeoutMs := 2000\n    monoidal := true\n    trace := false\n    simpSet := none\n  }\n  normalizeGoalM e config\n```\n\nWorking examples live under `src/CatNF/Tests/`. For what “canonical” means in this project, see [What counts as canonical?](docs/WhatCountsAsCanonical.md). For entry points, limits, and common errors, see the [user guide](docs/UserGuide.md).\n\n### Configuration at a glance\n\n`Config` carries step and time limits, tracing, optional simp-set name, and resource knobs (caching, parallelism, cache size, memory budget). See [`src/CatNF/Core.lean`](src/CatNF/Core.lean) for the full structure and `validateConfig` / `createConfig`.\n\n```lean\ndef prodConfig : Config := {\n  maxSteps := 1000\n  timeoutMs := 3000\n  monoidal := true\n  trace := true\n  simpSet := some \"custom\"\n  enableCaching := true\n  enableParallel := true\n  enableEarlyTermination := true\n  maxWorkers := 4\n  cacheSize := 10000\n  maxMemoryBytes := 100000000\n}\n```\n\n| Field | Default | Typical bound |\n|-------|---------|----------------|\n| `maxSteps` | 500 | 1 – 10 000 |\n| `timeoutMs` | 1500 | 1 – 30 000 ms |\n| `simpSet` | `none` | 1 – 100 chars if set |\n| `maxWorkers` | 4 | 1 – 32 |\n| `cacheSize` | 10000 | 1 – 1 000 000 |\n| `maxMemoryBytes` | 100000000 | up to 1 GB (enforced by validator) |\n\n---\n\n## Design notes\n\n**Errors.** Failures use `CatNFError` (timeout, validation, normalization, configuration, internal) instead of silent corruption.\n\n**Validation.** Expressions and internal segment lists are checked before heavy work; bad configuration is rejected with explicit messages.\n\n**Performance.** The pipeline respects step and time limits, can stop early when nothing changes, and exposes caching and parallelism flags on `Config`.\n\n```lean\ninductive CatNFError where\n  | timeoutError (message : String) : CatNFError\n  | validationError (message : String) : CatNFError\n  | normalizationError (message : String) : CatNFError\n  | configurationError (message : String) : CatNFError\n  | internalError (message : String) : CatNFError\n```\n\n---\n\n## Testing\n\n| Command | What it does |\n|---------|----------------|\n| `lake test` / `lake exe test-runner` | Full suite |\n| `lake exe bench` | Benchmarks |\n| `make test` / `make bench` | Makefile wrappers |\n\nOn Windows, linking the test executable can fail when the toolchain command line is too long—see [CONTRIBUTING.md](CONTRIBUTING.md). CI runs the full suite on Linux and a compile check on Windows; scheduled jobs also scan the tree for disallowed `sorry`, `admit`, and unexpected `axiom` declarations where the project enforces none.\n\n| Area | Location |\n|------|----------|\n| Unit | `src/CatNF/Tests/Unit/` |\n| Integration | `src/CatNF/Tests/Integration/` |\n| Performance | `src/CatNF/Tests/Performance/` |\n| Determinism | `src/CatNF/Tests/Determinism/` |\n\n---\n\n## API reference\n\n\u003cdetails\u003e\n\u003csummary\u003eCore (\u003ccode\u003eCatNF.Core\u003c/code\u003e)\u003c/summary\u003e\n\n```lean\ndef normalizeGoal (goal : Expr) (config : Config) : CatNFM (Expr × List AppliedRewrite)\ndef normalizeGoalM (goal : Expr) (config : Config) : MetaM (Expr × List AppliedRewrite)\ndef validateConfig (config : Config) : CatNFM Unit\ndef flattenComposition (expr : Expr) (config : Config) : CatNFM (List ExprSegment)\ndef validateExprSegment (seg : ExprSegment) : CatNFM Unit\ndef validateExprSegments (segs : List ExprSegment) : CatNFM Unit\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eTactic layer (\u003ccode\u003eCatNF.Tactic\u003c/code\u003e)\u003c/summary\u003e\n\n```lean\ndef catNFImpl (goal : Expr) (config : Config) : MetaM Unit\ndef catNFAtImpl (hyp : FVarId) (config : Config) : MetaM Unit\ndef catNFTraceImpl (goal : Expr) (config : Config) : MetaM (List AppliedRewrite)\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRewrite registry\u003c/strong\u003e — \u003ccode\u003eCatNF.RewriteRules\u003c/code\u003e\u003c/summary\u003e\n\n```lean\ndef registerIsoRule (ruleName : Name) (schema : RewriteSchema)\n  (isUnsafe : Bool := false) (priority : Nat := 0)\n  (description : String := \"\") : CatNFM Unit\ndef getRegisteredRules : CatNFM (Array RuleEntry)\n/-- Not yet implemented: returns none for now. -/\ndef applyRewriteRule (_rule : RuleEntry) (_expr : Expr) : CatNFM (Option Expr)\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eAttribute helpers (\u003ccode\u003eCatNF.Attr\u003c/code\u003e)\u003c/summary\u003e\n\n```lean\ndef validateIsoDeclaration (decl : IsoDeclPreview) : MetaM Bool\ndef validateRule (nm : Name) : MetaM Bool\ndef extractRewriteSchema (decl : IsoDeclPreview) : MetaM RewriteSchema\n```\n\n\u003c/details\u003e\n\n### Registering an isomorphism rule\n\n```lean\nimport CatNF.RewriteRules\nimport CatNF.Core\n\ndef mySchema : RewriteSchema := {\n  homRule := `MyNamespace.MyIso.hom,\n  invRule := `MyNamespace.MyIso.inv,\n  homInvId := `MyNamespace.MyIso.hom_inv_id,\n  invHomId := `MyNamespace.MyIso.inv_hom_id\n}\n-- registerIsoRule `MyNamespace.MyIso mySchema  (inside CatNF’s error monad)\n```\n\n---\n\n## Contributing \u0026 license\n\nContributions are welcome. Start with [CONTRIBUTING.md](CONTRIBUTING.md) for build commands, Windows notes, and review expectations.\n\nLicensed under the [MIT License](LICENSE).\n\nThanks to the Lean 4 team, the Mathlib community, and everyone who has improved this project.\n\nFor questions, see the [documentation index](docs/README.md) and the links under the title, or open an [issue](https://github.com/fraware/lean-cat-nf/issues). Repository discussions are available when enabled.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffraware%2Flean-cat-nf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffraware%2Flean-cat-nf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffraware%2Flean-cat-nf/lists"}