{"id":13993111,"url":"https://github.com/dwrensha/lean4-maze","last_synced_at":"2025-03-20T15:27:45.598Z","repository":{"id":43943814,"uuid":"372316708","full_name":"dwrensha/lean4-maze","owner":"dwrensha","description":"maze game encoded in Lean 4 syntax","archived":false,"fork":false,"pushed_at":"2024-12-03T02:52:31.000Z","size":62,"stargazers_count":50,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-25T14:42:10.470Z","etag":null,"topics":["lean4"],"latest_commit_sha":null,"homepage":"https://live.lean-lang.org/#url=https%3A%2F%2Fraw.githubusercontent.com%2Fdwrensha%2Flean4-maze%2Fmain%2FMaze.lean","language":"Lean","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dwrensha.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}},"created_at":"2021-05-30T21:16:32.000Z","updated_at":"2024-12-03T02:52:35.000Z","dependencies_parsed_at":"2023-10-17T03:13:48.787Z","dependency_job_id":"4004a70a-9b02-42e2-b3b4-cd99e29e4230","html_url":"https://github.com/dwrensha/lean4-maze","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwrensha%2Flean4-maze","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwrensha%2Flean4-maze/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwrensha%2Flean4-maze/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwrensha%2Flean4-maze/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dwrensha","download_url":"https://codeload.github.com/dwrensha/lean4-maze/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244639182,"owners_count":20485838,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["lean4"],"created_at":"2024-08-09T14:02:14.184Z","updated_at":"2025-03-20T15:27:45.567Z","avatar_url":"https://github.com/dwrensha.png","language":"Lean","funding_links":[],"categories":["Lean"],"sub_categories":[],"readme":"# lean4-maze\n\nThis repo shows how maze solving\ncan be encoded as theorem proving\nusing the Lean 4 programming language.\n\nIt draws inspiration from https://github.com/kbuzzard/maze-game.\n\n\n## Setup\n\n### On The Web\n\n[Try it in your browser on the Lean 4 Playground.](https://live.lean-lang.org/#url=https%3A%2F%2Fraw.githubusercontent.com%2Fdwrensha%2Flean4-maze%2Fmain%2FMaze.lean)\n\n### Locally\n\nFirst, install Lean 4 on your computer: https://leanprover.github.io/lean4/doc/setup.html\n\nThen open `Maze.lean` in emacs or VSCode.\n\n## Playing\n\nYou can define a maze like this:\n\n```lean\ndef maze := ┌────────┐\n            │▓▓▓▓▓▓▓▓│\n            │▓░▓@▓░▓▓│\n            │▓░▓░░░▓▓│\n            │▓░░▓░▓▓▓│\n            │▓▓░▓░▓░░│\n            │▓░░░░▓░▓│\n            │▓░▓▓▓▓░▓│\n            │▓░░░░░░▓│\n            │▓▓▓▓▓▓▓▓│\n            └────────┘\n```\n\nThe `@` symbol denotes your current location.\nYou are free to move within the `░` cells.\nThe `▓` cells are walls.\n\nYour goal is to escape the maze at any of its borders.\n\nYou can interactively solve a maze like this:\n\n\n```lean\nexample : Escapable maze :=\n by south\n    east\n    south\n    south\n```\n\nAs you make progress, Lean's goal view will display your current state.\nFor example, after the moves made above, the state is shown as:\n\n```lean\n⊢ Escapable\n    (\n        ┌────────┐\n        │▓▓▓▓▓▓▓▓│\n        │▓░▓░▓░▓▓│\n        │▓░▓░░░▓▓│\n        │▓░░▓░▓▓▓│\n        │▓▓░▓@▓░░│\n        │▓░░░░▓░▓│\n        │▓░▓▓▓▓░▓│\n        │▓░░░░░░▓│\n        │▓▓▓▓▓▓▓▓│\n        └────────┘\n        )\n```\n\nThe main moves available to you at any point are `north`, `south`, `east`, and `west`.\n\nWhen you reach the boundary, you can finish your proof with `out`.\n\n## how does it work?\n\nAs you traverse a maze, you are constructing a proof\nthat the maze satisfies an `Escapable` predicate, defined as\n\n```lean\ninductive Escapable : GameState → Prop where\n| Done (s : GameState) : IsWin s → Escapable s\n| Step (s : GameState) (m : Move) : Escapable (make_move s m) → Escapable s\n```\n\nThe mazes as drawn above are actual valid Lean 4 syntax!\n\nWe define new syntax categories and some `macro_rules` for elaborating\nthem into valid values.\n\nTo get Lean to render the values back in the above format,\nwe define a delaboration function and register it with the pretty printer.\n\nLean 4 lets us do all of this in-line, in ordinary Lean 4 code.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwrensha%2Flean4-maze","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdwrensha%2Flean4-maze","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwrensha%2Flean4-maze/lists"}