{"id":13831935,"url":"https://github.com/joom/hezarfen","last_synced_at":"2025-07-09T15:33:55.689Z","repository":{"id":77583453,"uuid":"106183529","full_name":"joom/hezarfen","owner":"joom","description":"a theorem prover for intuitionistic propositional logic in Idris, with metaprogramming features","archived":true,"fork":false,"pushed_at":"2018-09-12T20:32:05.000Z","size":50,"stargazers_count":118,"open_issues_count":0,"forks_count":3,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-08-04T10:08:04.861Z","etag":null,"topics":["automated-theorem-provers","idris","mathematical-logic","metaprogramming","theorem-prover"],"latest_commit_sha":null,"homepage":null,"language":"Idris","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/joom.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":"2017-10-08T14:40:45.000Z","updated_at":"2024-08-04T10:08:07.802Z","dependencies_parsed_at":null,"dependency_job_id":"3532660b-44de-4e9d-bf7c-3bd125da75a6","html_url":"https://github.com/joom/hezarfen","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/joom%2Fhezarfen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joom%2Fhezarfen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joom%2Fhezarfen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joom%2Fhezarfen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joom","download_url":"https://codeload.github.com/joom/hezarfen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225565955,"owners_count":17489289,"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":["automated-theorem-provers","idris","mathematical-logic","metaprogramming","theorem-prover"],"created_at":"2024-08-04T10:01:44.825Z","updated_at":"2024-11-20T13:32:08.939Z","avatar_url":"https://github.com/joom.png","language":"Idris","funding_links":[],"categories":["Idris"],"sub_categories":[],"readme":"# Hezarfen\n\nAn Idris implementation of a theorem prover for [Roy Dyckhoff's\nLJT](https://scholar.google.com/scholar?cluster=14155439887209124225), a sequent\ncalculus for propositional intuitionistic logic that is decidable and does\n_not_ need loop checking. Initially ported from [Ayberk Tosun's Standard ML\nimplementation](https://github.com/ayberkt/sequents).\n\nThe main goal of the project is to make use of the [elaborator\nreflection](http://docs.idris-lang.org/en/latest/reference/elaborator-reflection.html).\nSimilar to [Lennart Augustsson's Djinn](https://github.com/augustss/djinn), a\ntheorem prover that generates Haskell expressions, Hezarfen generates Idris expressions.\nUnlike Djinn, Hezarfen is not a standalone program, it is a library that\ngenerates Idris expressions of the type `Raw`, one of the types used for the\ninner representation of the core language of Idris. This means these\nexpressions can easily be spliced into your programs. Hezarfen provides a\ntactic that lets you do this:\n\n```idris\nf2 : (a -\u003e b) -\u003e (b -\u003e c) -\u003e (c -\u003e d) -\u003e a -\u003e d\nf2 = %runElab hezarfenExpr\n```\n\nHowever, instead of creating proof terms, you can also create definitions that\nare more readable when you print their definitions.\n\n```idris\nf2 : (a -\u003e b) -\u003e (b -\u003e c) -\u003e (c -\u003e d) -\u003e a -\u003e d\n%runElab (hezarfen `{f2})\n```\n\nOr with the more readable syntax extension:\n\n```idris\ndemorgan3 : Either (Not p) (Not q) -\u003e Not (p, q)\nderive demorgan3\n\ncontrapositive : (p -\u003e q) -\u003e (Not q -\u003e Not p)\nderive contrapositive\n```\n\nIt can also make use of your existing lemmas:\n\n```idris\nevenOrOdd : (n : Nat) -\u003e Either (Even n) (Odd n)\n... -- some definition of an existing lemma\n\noddOrEven : (n : Nat) -\u003e Either (Odd n) (Even n)\n%runElab (hezarfen' `{oddOrEven} !(add [`{evenOrOdd}]))\n\n-- something more complex, but passing the constructors for Even and Odd\n-- using the more readable syntax\nevenOrOddSS : (n : Nat) -\u003e Either (Even (S (S n))) (Odd (S (S n)))\nobtain evenOrOddSS from [`{evenOrOdd}, `{EvenSS}, `{OddSS}]\n```\n\nWe also have a Coq-style hint database system that lets us keep a list of hint names that will be used to prove theorems. To use the hints in proofs, change `derive` to `derive'` and `obtain` to `obtain'`. Then the names in the hint database will be automatically added to the context in which the theorem prover runs.\n\n```idris\nhint evenOrOdd\nhint EvenSS\nhint OddSS\n\nevenOrOddSS : (n : Nat) -\u003e Either (Even (S (S n))) (Odd (S (S n)))\nderive' evenOrOddSS\n```\n\nThe even/odd example is beyond the logic Hezarfen is trying to decide. `Even n` and `Even (S (S n))` happen to be one function away, namely `EvenSS`.\n\nHezarfen attempts to prove a tiny bit more than propositional intuitionistic logic,\nespecially when it comes to equalities and `Dec`.\nEven though this part is a bit ad hoc, it can currently prove things of this nature:\n\n```idris\neqDec : x = y -\u003e Dec (y = x)\nderive eqDec\n\ndecCongB : x = y -\u003e Dec (not x = not y)\nderive decCongB\n```\n\nFor details, look at [Examples.idr](https://github.com/joom/hezarfen/blob/master/Examples.idr).\n\n## Edit-Time Tactics\n\nThe original purpose of Hezarfen was to be a part of a master's thesis on\n\"edit-time tactics\", meaning that we would be able to run it from the editor.\nThen it would be an alternative to the built-in proof search in Idris.\n[Here](http://cattheory.com/editTimeTacticsDraft.pdf) is the draft of the\nthesis. And below you can see how it works in the editor:\n\n[![Screencast of how Hezarfen works in Emacs](https://asciinema.org/a/rrwboxAr2VdiUQsZov0RDinJw.png)](https://asciinema.org/a/rrwboxAr2VdiUQsZov0RDinJw)\n\nThe feature that allows this has not landed on the Idris compiler or the Idris\nmode yet, but it should be merged soon!\n\n## Future Work\n\nSome support for deriving terms with type classes can be implemented, à la Djinn.\n\nOne of the end goals of Hezarfen is to generate proofs that are easy to read:\n\n* Fresh variable names should be readable. Currently there is a hacky `fresh` function in [Prover.idr](https://github.com/joom/hezarfen/blob/master/Hezarfen/Prover.idr) that does that.\n* There is [already some work on simplifying the proof terms](https://github.com/joom/hezarfen/blob/master/Hezarfen/Simplify.idr) generated by Hezarfen. There are some tricks Hezarfen can learn from Haskell's [pointfree](https://hackage.haskell.org/package/pointfree) package. ([web version](http://pointfree.io/))\n* Currently Hezarfen primarily generates expressions as proofs. However when we are writing functions, we often use function definitions instead of lambda terms, and we pattern match on pairs in the function definition, instead of writing `let a = fst p in let b = snd p in ...` or `case p of (x, y) =\u003e ...` to do projections. There is [some work](https://github.com/joom/hezarfen/blob/master/Hezarfen/FunDefn.idr) on translating these proof terms to readable function definitions.\n\nThe definition it generates looks like this:\n```idris\n\u003e :printdef contrapositive\ncontrapositive : (p -\u003e q) -\u003e Not q -\u003e Not p\ncontrapositive c d = void . d . c\n```\n\nAs opposed to proof term:\n```idris\ncontrapositive : (p -\u003e q) -\u003e Not q -\u003e Not p\ncontrapositive = \\i20, j20 =\u003e void . j20 . i20\n```\n\n***\n\n*hezarfen* (/hezaɾfæn/, sounds like \"has are fan\") is a Turkish word that means\npolymath, literally \"a thousand sciences\".\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoom%2Fhezarfen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoom%2Fhezarfen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoom%2Fhezarfen/lists"}