{"id":14966269,"url":"https://github.com/ilya-klyuchnikov/ttlite","last_synced_at":"2025-10-25T16:30:46.777Z","repository":{"id":11198617,"uuid":"13581325","full_name":"ilya-klyuchnikov/ttlite","owner":"ilya-klyuchnikov","description":"A SuperCompiler for Martin-Löf's Type Theory","archived":false,"fork":false,"pushed_at":"2022-01-29T12:48:45.000Z","size":1574,"stargazers_count":119,"open_issues_count":12,"forks_count":9,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-01-31T07:51:29.858Z","etag":null,"topics":["agda","coq","dependent-types","idris","programming-language","supercompilation","type-theory"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ilya-klyuchnikov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-15T05:29:34.000Z","updated_at":"2024-11-20T20:30:22.000Z","dependencies_parsed_at":"2022-09-11T14:31:20.245Z","dependency_job_id":null,"html_url":"https://github.com/ilya-klyuchnikov/ttlite","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/ilya-klyuchnikov%2Fttlite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilya-klyuchnikov%2Fttlite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilya-klyuchnikov%2Fttlite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilya-klyuchnikov%2Fttlite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ilya-klyuchnikov","download_url":"https://codeload.github.com/ilya-klyuchnikov/ttlite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238174122,"owners_count":19428629,"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":["agda","coq","dependent-types","idris","programming-language","supercompilation","type-theory"],"created_at":"2024-09-24T13:36:07.841Z","updated_at":"2025-10-25T16:30:46.362Z","avatar_url":"https://github.com/ilya-klyuchnikov.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"## TT Lite\n\nTT Lite is an interpreter, type-checker and supercompiler for Martin-Löf's Type Theory (TT).\nIt is structured into two sub-projects:\n\n* TT Lite Core - lightweight and modular implementation of Martin-Löf's Type Theory\n(TT Lite was designed with supercompilation in mind)\n* TT Lite Supercompiler - a very simple supercompiler for TT Lite.\n\nThe main feature of the supercompiler is that for any transformation performed by\nthe supercompiler a proof of correctness is provided.\n\nTT Lite also supports exporting into Agda, Coq and Idris languages, which allows to verify\nperformed transformations and generated proofs independently of TT Lite.\n\nThe technical internals of TT Lite are described in the preprint:\n\n* Ilya Klyuchnikov, Sergei Romanenko. **TT Lite: a\n  supercompiler for Martin-Löf’s type theory**. Keldysh Institute preprints, 2013, No. 73, 28 p.\n  \u003chttp://library.keldysh.ru/preprint.asp?id=2013-73\u0026lg=e\u003e\n\nThe fundamental principles of our approach to certifying supercompilation are described in the following paper:\n\n* Ilya Klyuchnikov, Sergei Romanenko.\n  **Certifying supercompilation for Martin-Löf's type theory**. PSI14, preprint version.\n  \u003chttp://pat.keldysh.ru/~ilya/ttlite-psi2014.pdf\u003e\n\n## How to build / Test\n\nTT Lite is built using SBT. You need to install SBT first from [here](http://www.scala-sbt.org).\n\n    $ git clone git@github.com:ilya-klyuchnikov/ttlite.git\n    $ cd ttlite\n    $ sbt\n    \u003e test\n\nTTLite contains integration tests which invoke Agda, Coq and Idris compilers for generated proofs:\n\n    \u003e it:test\n\nIn order to run these test you should have `agda`, `coqc` and `idris` executables in path.\n\n## Quick Start\n\nThere are two sub-projects:\n\n* `core` - TT Lite Core\n* `sc` - TT Lite SC\n\n### TTLite Core\n\nTo launch TT Core REPL, type in sbt console `core/run`:\n\n    \u003e core/run\n\nLoad some definitions from examples:\n\n    TT\u003e import examples/nat;\n\nTry some simple computations:\n\n    TT\u003e plus Zero Zero;\n    Zero\n    :\n    Nat;\n\n    TT\u003e plus Zero (Succ Zero);\n    Succ Zero\n    :\n    Nat;\n\nYou can look into definitions by evaluating them:\n\n    TT\u003e plus;\n    \\ (a : Nat) -\u003e \\ (b : Nat) -\u003e\n        elim Nat (\\ (c : Nat) -\u003e Nat) b (\\ (c : Nat) -\u003e \\ (d : Nat) -\u003e Succ d) a\n    :\n    forall (a : Nat) (b : Nat) . Nat;\n\nYou can introduce new definitions directly in REPL:\n\n    TT\u003e z = Zero;\n    z\n    :\n    Nat;\n\n    TT\u003e z;\n    Zero\n    :\n    Nat;\n\nFor definitions you can optionally specify a type (type checker will check it):\n\n    TT\u003e m : Nat; m = Succ Zero;\n    m\n    :\n    Nat;\n\n(In REPL a declaration with a definition should fit a single line);\n\nYou can _assume_ a variable of a certain type (we will call it _assumed_ variable)\njust by specifying its type (a variable should start with `$`);\n\n    TT\u003e $n : Nat;\n    Nat\n\n    TT\u003e plus $n $n;\n    elim Nat (\\ (a : Nat) -\u003e Nat) $n (\\ (a : Nat) -\u003e \\ (b : Nat) -\u003e Succ b) $n\n    :\n    Nat;\n\nQuitting REPL:\n\n    TT\u003e quit;\n\n### Syntax and Semantics of TT\n\nTechnical details of this implementation are described in the preprint\n[TT Lite: a supercompiler for Martin-Löf's type theory](http://library.keldysh.ru/preprint.asp?id=2013-73\u0026lg=e).\nHowever, the preprint just translates code of the current implementation into mathematical notation.\n\nThe proposed way to get into this project is:\n\n* Sketch the preprint for grasping syntax and semantics (without details).\n* Look into examples of how functions are defined (dir [`examples`](examples/))\n* Sketch some modules ([`Function.scala`](ttlite-core/src/main/scala/ttlite/core/Function.scala),\n[`Nat.scala`](ttlite-core/src/main/scala/ttlite/core/Nat.scala),\n[`DProduct.scala`](ttlite-core/src/main/scala/ttlite/core/DProduct.scala))\nfor getting an idea how syntax and semantics are implemented.\n\nTutorial is on the way.\n\nA program in TT Lite consists of the following statements:\n\n* `id = term;` - definition\n* `id : term; id = term;` - typed definition;\n* `import \"file\";` - loading of definitions from file\n* `$id : term;` - assumption of a variable of a certain type\n* `term;` - just evaluating of a term;\n\n### TT Lite SC (supercompiler)\n\nTo launch TT Lite SC REPL, type in sbt console `ttlite-sc/run`:\n\n    \u003e sc/run\n\nLaunching examples:\n\n    TT-SC\u003e import examples/hosc/10;\n\nTT Lite SC REPL introduces a new statement:\n\n    (t1, t2) = sc t;\n\nThe meaning of the new statement is that `t1` is a result of transformation of a term `t` by the supercompiler,\n`t2` is a proof that transformation is correct (i.e. `t2 : Id A t t1` if `t : A`).\n\n`t1` and `t2` are put in the context as terms and available for further manipulations.\n\nHere is an example of proving the equivalence of two expressions with assumed variables (`examples/hosc/10.hs`):\n\n    import examples/nat;\n    import examples/id;\n\n    -- proof of the associativity of addition\n    -- plus x (plus y z) = plus (plus x y) z\n\n    $x : Nat;\n    $y : Nat;\n    $z : Nat;\n\n    e1 = (plus $x (plus $y $z));\n    e2 = (plus (plus $x $y) $z);\n    (res1, proof1) = sc e1;\n    (res2, proof2) = sc e2;\n\n    -- associativity of addition using combinators\n    -- check that t1 and t2 are supercompiled into the same expression\n    eq_res1_res2 : Id Nat res1 res2;\n    eq_res1_res2 = Refl Nat res1;\n    -- deriving equality\n    eq_e1_e2 : Id Nat e1 e2;\n    eq_e1_e2 = proof_by_sc Nat e1 e2 res1 proof1 proof2;\n\n`proof_by_sc` is a helper function defined in `examples/id.hs`. In this example correctness is checked by type-checker!\n\nYou can see input and output of supercompilation (as well as a proof):\n\n    TT-SC\u003e import examples/hosc/10;\n\n    TT-SC\u003e e2;\n    elim\n        Nat\n        (\\ (a : Nat) -\u003e Nat)\n        $z\n        (\\ (a : Nat) (b : Nat) -\u003e Succ b)\n        (elim Nat (\\ (a : Nat) -\u003e Nat) $y (\\ (a : Nat) (b : Nat) -\u003e Succ b) $x)\n    :\n    Nat;\n\n    TT-SC\u003e res2;\n    elim\n        Nat\n        (\\ (a : Nat) -\u003e Nat)\n        (elim Nat (\\ (a : Nat) -\u003e Nat) $z (\\ (a : Nat)  (b : Nat) -\u003e Succ b) $y)\n        (\\ (a : Nat) (b : Nat) -\u003e Succ b)\n        $x\n    :\n    Nat;\n\n    TT-SC\u003e proof2;\n    elim Nat\n    (\\ (a : Nat) -\u003e Id Nat\n            (elim Nat (\\ (b : Nat) -\u003e Nat) $z\n                (\\ (b : Nat) -\u003e \\ (c : Nat) -\u003e Succ c)\n                (elim Nat (\\ (b : Nat) -\u003e Nat) $y\n                    (\\ (b : Nat) -\u003e \\ (c : Nat) -\u003e Succ c)\n                    a))\n            (elim Nat (\\ (b : Nat) -\u003e Nat)\n                (elim Nat (\\ (b : Nat) -\u003e Nat) $z\n                    (\\ (b : Nat) -\u003e \\ (c : Nat) -\u003e Succ c)\n                    $y)\n                (\\ (b : Nat) -\u003e \\ (c : Nat) -\u003e Succ c)\n                a))\n    ...\n    :\n    Id Nat\n    (elim Nat (\\ (a : Nat) -\u003e Nat) $z (\\ (a : Nat) -\u003e \\ (b : Nat) -\u003e Succ b)\n        (elim Nat (\\ (a : Nat) -\u003e Nat) $y\n            (\\ (a : Nat) -\u003e \\ (b : Nat) -\u003e Succ b)\n            $x))\n    (elim Nat (\\ (a : Nat) -\u003e Nat)\n        (elim Nat (\\ (a : Nat) -\u003e Nat) $z\n            (\\ (a : Nat) -\u003e \\ (b : Nat) -\u003e Succ b)\n            $y)\n        (\\ (a : Nat) -\u003e \\ (b : Nat) -\u003e Succ b)\n        $x);\n\nThe whole proof term is quite long (it is long since TT Lite performs normalization of terms and terms are printed\nin normal form). An interested person is encouraged to launch the supercompiler to see it.\n\n### Interactive development\n\nThere is no editor or IDE plugin for TT Lite yet. So the only possibility to speedup development is to make a\nchange in a file and reload this file in REPL. For this purpose there is a special statement:\n\n    reload file;\n\nExamples:\n\n    reload examples/id;\n\nFor now, this statemenent reloads a specified file, but **do not** reload its dependencies.\n\n### Why `*.hs` ?\n\nIf you look into examples, you will notice that all of TT Lite examples are in files with extension `.hs`.\nThere is a very simple reason for this: syntax of TT Lite is quite close to Haskell and GitHub performs quite\ngood syntax coloring fot TT Lite files if they have extension `.hs`. That's it :)\n\n### Further reading\n\n* [Change notes](/tech-notes/changes.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filya-klyuchnikov%2Fttlite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Filya-klyuchnikov%2Fttlite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filya-klyuchnikov%2Fttlite/lists"}